Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .idea/checkstyle-idea.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@

<properties>
<java.version>25</java.version>
<errorprone.version>2.48.0</errorprone.version>
<jooq.version>3.20.11</jooq.version>
<nullaway.version>0.13.1</nullaway.version>
<errorprone.version>2.49.0</errorprone.version>
<jooq.version>3.21.2</jooq.version>
<nullaway.version>0.13.2</nullaway.version>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -100,7 +100,7 @@
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>3.0.2</version>
<version>3.0.3</version>
</dependency>

<!-- Testing -->
Expand Down Expand Up @@ -162,13 +162,13 @@
<dependency>
<groupId>com.tngtech.archunit</groupId>
<artifactId>archunit-junit5</artifactId>
<version>1.4.1</version>
<version>1.4.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.tngtech.archunit</groupId>
<artifactId>archunit-junit5-api</artifactId>
<version>1.4.1</version>
<version>1.4.2</version>
<scope>compile</scope>
</dependency>

Expand Down Expand Up @@ -255,7 +255,7 @@
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>13.3.0</version>
<version>13.4.0</version>
</dependency>
<dependency>
<groupId>it.aboutbits</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package it.aboutbits.springboot.toolbox.reflection.util;

import it.aboutbits.springboot.toolbox.type.ScaledBigDecimal;
import org.jspecify.annotations.NullMarked;

import java.lang.reflect.Constructor;
Expand Down Expand Up @@ -31,7 +32,7 @@ public static <T> Constructor<T> getConstructorForType(
Class<T> recordClass,
Class<?> type
) {
if (!recordClass.isRecord()) {
if (!recordClass.isRecord() && !ScaledBigDecimal.class.isAssignableFrom(recordClass)) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK for now, but I think we should create a ticket to clean this up. It seems strange to have a specific implementation inside this generic utility.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. We should have a ticket to clean up the ultility. And another ticket to look for other tools that use this to see if they can be improved. I am sure there are other places what will be happy about ScaledBigDecimal finally implementing Number.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done 💪🏼
AB-490 Spring Boot Toolbox: Clean up RecordReflectionUtil
AB-491 Spring Boot Toolbox: Check for ScaledBigDecimal extends Number refactoring possibilities in projects

throw new IllegalArgumentException("Class must be a record: " + recordClass.getName());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void customise(OpenAPI openApi) {
true
));
}
} catch (ClassNotFoundException ignored) {
} catch (ClassNotFoundException _) {
// do nothing
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package it.aboutbits.springboot.toolbox.type;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Getter;
import lombok.experimental.Accessors;
import org.jspecify.annotations.NullMarked;

import java.math.BigDecimal;
Expand All @@ -13,18 +15,20 @@
* This class provides various constructors for creating instances with different numerical types.
* It also provides a set of arithmetic operations that return new instances with the appropriate scale and rounding.
*/
@NullMarked
@Getter
@Accessors(fluent = true)
@SuppressWarnings("unused")
public record ScaledBigDecimal(
BigDecimal value
) implements CustomType<BigDecimal>, Comparable<ScaledBigDecimal> {
@NullMarked
public class ScaledBigDecimal extends Number implements CustomType<BigDecimal>, Comparable<ScaledBigDecimal> {
private static final MathContext MATH_CONTEXT = new MathContext(15, RoundingMode.HALF_UP);

public static final ScaledBigDecimal ZERO = new ScaledBigDecimal(0);
public static final ScaledBigDecimal ONE = new ScaledBigDecimal(1);
public static final ScaledBigDecimal TWO = new ScaledBigDecimal(2);
public static final ScaledBigDecimal TEN = new ScaledBigDecimal(10);

private final BigDecimal value;

@SuppressWarnings("unused")
ScaledBigDecimal(ScaledBigDecimal other) {
this(other.value);
Expand Down Expand Up @@ -217,8 +221,8 @@ public boolean equals(Object o) {
return true;
}

if (o instanceof ScaledBigDecimal(BigDecimal other)) {
return this.value().compareTo(other) == 0;
if (o instanceof ScaledBigDecimal other) {
return this.value().compareTo(other.value()) == 0;
}

return false;
Expand Down