[JAVA-2860] Decimal128 should extend Number and implement Comparable Created: 16/May/18  Updated: 28/Oct/23  Resolved: 06/Dec/18

Status: Closed
Project: Java Driver
Component/s: BSON
Affects Version/s: None
Fix Version/s: 3.10.0

Type: New Feature Priority: Major - P3
Reporter: Matej Tymes [X] Assignee: Jeffrey Yemin
Resolution: Fixed Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
is duplicated by JAVA-3056 should Decimal128 implement Number an... Closed
Backwards Compatibility: Minor Change

 Description   

It would be beneficial if Decimal128 would extend the standard Java interface Number (as all numbers and BigDecimal do). This would improve compatibility with many libraries that are Decimal128 unaware, but are able to process numbers.

Update: Also consider implementing Comparable



 Comments   
Comment by Githook User [ 14/Jan/19 ]

Author:

{'username': 'jyemin', 'email': 'jeff.yemin@10gen.com', 'name': 'Jeff Yemin'}

Message: Rewrite Decimal128 Groovy/Spock tests as Java

Groovy does surprising things with numbers under the hood, especially for
classes that extend Number and/or implement Comparable, which Decimal128
now does.

JAVA-2860
Branch: 3.10.x
https://github.com/mongodb/mongo-java-driver/commit/a88f98399c0a157d4a269a9bc01c49ebd1958434

Comment by Githook User [ 14/Jan/19 ]

Author:

{'username': 'jyemin', 'email': 'jeff.yemin@10gen.com', 'name': 'Jeff Yemin'}

Message: Decimal128 implements Comparable

JAVA-2860
Branch: 3.10.x
https://github.com/mongodb/mongo-java-driver/commit/62758dbd1555014e695775ffcf5af3ff23fd94bb

Comment by Githook User [ 14/Jan/19 ]

Author:

{'username': 'jyemin', 'email': 'jeff.yemin@10gen.com', 'name': 'Jeff Yemin'}

Message: Handle negative zero properly in Decimal128.doubleValue

JAVA-2860
Branch: 3.10.x
https://github.com/mongodb/mongo-java-driver/commit/d8765b8a9a4e96d61d74a1043b6d546d815eb19c

Comment by Githook User [ 14/Jan/19 ]

Author:

{'username': 'jyemin', 'email': 'jeff.yemin@10gen.com', 'name': 'Jeff Yemin'}

Message: Handle Decimal128 values when decoding integral and decimal types

JAVA-2860
Branch: 3.10.x
https://github.com/mongodb/mongo-java-driver/commit/79cd393ae39c1239eb279dc721add3f716c2e9b2

Comment by Githook User [ 14/Jan/19 ]

Author:

{'username': 'jyemin', 'email': 'jeff.yemin@10gen.com', 'name': 'Jeff Yemin'}

Message: Fix BasicBsonEncoder to still encode Decimal128 correctly

Since Decimal128 now extends Number, BasicBsonEncoder checks if value
is Decimal128 before it checks if it's a Number. Otherwise it won't be
encoded correctly

JAVA-2860
Branch: 3.10.x
https://github.com/mongodb/mongo-java-driver/commit/409df6fadb90a7e033711412481161219d3653af

Comment by Githook User [ 14/Jan/19 ]

Author:

{'username': 'jyemin', 'email': 'jeff.yemin@10gen.com', 'name': 'Jeff Yemin'}

Message: org.bson.Decimal128 implements java.lang.Number

JAVA-2860
Branch: 3.10.x
https://github.com/mongodb/mongo-java-driver/commit/c827ed29440a43b4d5f353fb0ec3c4626afc2d06

Comment by Githook User [ 06/Dec/18 ]

Author:

{'name': 'Jeff Yemin', 'email': 'jeff.yemin@10gen.com', 'username': 'jyemin'}

Message: Rewrite Decimal128 Groovy/Spock tests as Java

Groovy does surprising things with numbers under the hood, especially for
classes that extend Number and/or implement Comparable, which Decimal128
now does.

JAVA-2860
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/ddb26f4f8a47806d98f437593a1ed5b47d8b5b0e

Comment by Githook User [ 06/Dec/18 ]

Author:

{'name': 'Jeff Yemin', 'email': 'jeff.yemin@10gen.com', 'username': 'jyemin'}

Message: Decimal128 implements Comparable

JAVA-2860
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/6e75cf63e20c73b921a4de08bce87e0eec9b82c0

Comment by Githook User [ 06/Dec/18 ]

Author:

{'name': 'Jeff Yemin', 'email': 'jeff.yemin@10gen.com', 'username': 'jyemin'}

Message: Handle negative zero properly in Decimal128.doubleValue

JAVA-2860
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/45d65c9ee780f84a16a32321e32dd3cbad3cf3a4

Comment by Jeffrey Yemin [ 04/Dec/18 ]

Re-opening to implement Comparable as well.

Comment by Githook User [ 04/Dec/18 ]

Author:

{'name': 'Jeff Yemin', 'email': 'jeff.yemin@10gen.com', 'username': 'jyemin'}

Message: Handle Decimal128 values when decoding integral and decimal types

JAVA-2860
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/5908eb3adb3e6901d7e0e7cfe2b583fe80310aef

Comment by Githook User [ 04/Dec/18 ]

Author:

{'name': 'Jeff Yemin', 'email': 'jeff.yemin@10gen.com', 'username': 'jyemin'}

Message: Fix BasicBsonEncoder to still encode Decimal128 correctly

Since Decimal128 now extends Number, BasicBsonEncoder checks if value
is Decimal128 before it checks if it's a Number. Otherwise it won't be
encoded correctly

JAVA-2860
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/b8334aea33ae67070c672d592490e4bfd8cf39fc

Comment by Githook User [ 04/Dec/18 ]

Author:

{'name': 'Jeff Yemin', 'email': 'jeff.yemin@10gen.com', 'username': 'jyemin'}

Message: org.bson.Decimal128 implements java.lang.Number

JAVA-2860
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/17789f2f9dc1fc224737678aab262bce77072205

Comment by Jeffrey Yemin [ 16/May/18 ]

Thanks for the suggestion.  As a workaround for anyone looking at this ticket, you can already call Decimal128#bigDecimalValue to get the Decimal128 as a BigDecimal, which, as the reporter notes, already implements Number.

Generated at Thu Feb 08 08:58:14 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.