Skip to content

Commit 3ae3cbe

Browse files
committed
extend ScaledBigDecimal class with Number
1 parent 7b4ba8d commit 3ae3cbe

2 files changed

Lines changed: 12 additions & 7 deletions

File tree

src/main/java/it/aboutbits/springboot/toolbox/reflection/util/RecordReflectionUtil.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package it.aboutbits.springboot.toolbox.reflection.util;
22

3+
import it.aboutbits.springboot.toolbox.type.ScaledBigDecimal;
34
import org.jspecify.annotations.NullMarked;
45

56
import java.lang.reflect.Constructor;
@@ -31,7 +32,7 @@ public static <T> Constructor<T> getConstructorForType(
3132
Class<T> recordClass,
3233
Class<?> type
3334
) {
34-
if (!recordClass.isRecord()) {
35+
if (!recordClass.isRecord() && !ScaledBigDecimal.class.isAssignableFrom(recordClass)) {
3536
throw new IllegalArgumentException("Class must be a record: " + recordClass.getName());
3637
}
3738

src/main/java/it/aboutbits/springboot/toolbox/type/ScaledBigDecimal.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package it.aboutbits.springboot.toolbox.type;
22

33
import com.fasterxml.jackson.annotation.JsonIgnore;
4+
import lombok.Getter;
5+
import lombok.experimental.Accessors;
46
import org.jspecify.annotations.NullMarked;
57

68
import java.math.BigDecimal;
@@ -13,18 +15,20 @@
1315
* This class provides various constructors for creating instances with different numerical types.
1416
* It also provides a set of arithmetic operations that return new instances with the appropriate scale and rounding.
1517
*/
16-
@NullMarked
18+
@Getter
19+
@Accessors(fluent = true)
1720
@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> {
2123
private static final MathContext MATH_CONTEXT = new MathContext(15, RoundingMode.HALF_UP);
2224

2325
public static final ScaledBigDecimal ZERO = new ScaledBigDecimal(0);
2426
public static final ScaledBigDecimal ONE = new ScaledBigDecimal(1);
2527
public static final ScaledBigDecimal TWO = new ScaledBigDecimal(2);
2628
public static final ScaledBigDecimal TEN = new ScaledBigDecimal(10);
2729

30+
private final BigDecimal value;
31+
2832
@SuppressWarnings("unused")
2933
ScaledBigDecimal(ScaledBigDecimal other) {
3034
this(other.value);
@@ -217,8 +221,8 @@ public boolean equals(Object o) {
217221
return true;
218222
}
219223

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;
222226
}
223227

224228
return false;

0 commit comments

Comments
 (0)