|
1 | 1 | package it.aboutbits.springboot.toolbox.type; |
2 | 2 |
|
3 | 3 | import com.fasterxml.jackson.annotation.JsonIgnore; |
| 4 | +import lombok.Getter; |
| 5 | +import lombok.experimental.Accessors; |
4 | 6 | import org.jspecify.annotations.NullMarked; |
5 | 7 |
|
6 | 8 | import java.math.BigDecimal; |
|
13 | 15 | * This class provides various constructors for creating instances with different numerical types. |
14 | 16 | * It also provides a set of arithmetic operations that return new instances with the appropriate scale and rounding. |
15 | 17 | */ |
16 | | -@NullMarked |
| 18 | +@Getter |
| 19 | +@Accessors(fluent = true) |
17 | 20 | @SuppressWarnings("unused") |
18 | | -public record ScaledBigDecimal( |
19 | | - BigDecimal value |
20 | | -) implements CustomType<BigDecimal>, Comparable<ScaledBigDecimal> { |
| 21 | +@NullMarked |
| 22 | +public class ScaledBigDecimal extends Number implements CustomType<BigDecimal>, Comparable<ScaledBigDecimal> { |
21 | 23 | private static final MathContext MATH_CONTEXT = new MathContext(15, RoundingMode.HALF_UP); |
22 | 24 |
|
23 | 25 | public static final ScaledBigDecimal ZERO = new ScaledBigDecimal(0); |
24 | 26 | public static final ScaledBigDecimal ONE = new ScaledBigDecimal(1); |
25 | 27 | public static final ScaledBigDecimal TWO = new ScaledBigDecimal(2); |
26 | 28 | public static final ScaledBigDecimal TEN = new ScaledBigDecimal(10); |
27 | 29 |
|
| 30 | + private final BigDecimal value; |
| 31 | + |
28 | 32 | @SuppressWarnings("unused") |
29 | 33 | ScaledBigDecimal(ScaledBigDecimal other) { |
30 | 34 | this(other.value); |
@@ -217,8 +221,8 @@ public boolean equals(Object o) { |
217 | 221 | return true; |
218 | 222 | } |
219 | 223 |
|
220 | | - if (o instanceof ScaledBigDecimal(BigDecimal other)) { |
221 | | - return this.value().compareTo(other) == 0; |
| 224 | + if (o instanceof ScaledBigDecimal other) { |
| 225 | + return this.value().compareTo(other.value()) == 0; |
222 | 226 | } |
223 | 227 |
|
224 | 228 | return false; |
|
0 commit comments