Skip to content

Commit 9cdbd02

Browse files
committed
OverflowHandling parameter ignored
+ reduce code duplication
1 parent 161fbf3 commit 9cdbd02

File tree

1 file changed

+4
-14
lines changed

1 file changed

+4
-14
lines changed

src/main/java/org/firebirdsql/decimal/Decimal.java

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -129,17 +129,7 @@ public final byte[] toBytes() {
129129
* If conversion to {@code decimalType} is not supported
130130
*/
131131
public final <D extends Decimal<D>> D toDecimal(Class<D> decimalType) {
132-
if (decimalType == getClass()) {
133-
return decimalType.cast(this);
134-
} else if (decimalType == Decimal128.class) {
135-
return decimalType.cast(Decimal128.valueOf(this));
136-
} else if (decimalType == Decimal64.class) {
137-
return decimalType.cast(Decimal64.valueOf(this));
138-
} else if (decimalType == Decimal32.class) {
139-
return decimalType.cast(Decimal32.valueOf(this));
140-
} else {
141-
throw new IllegalArgumentException("Unsupported conversion to " + decimalType.getName());
142-
}
132+
return toDecimal(decimalType, OverflowHandling.ROUND_TO_INFINITY);
143133
}
144134

145135
/**
@@ -161,11 +151,11 @@ public final <D extends Decimal<D>> D toDecimal(Class<D> decimalType, OverflowHa
161151
if (decimalType == getClass()) {
162152
return decimalType.cast(this);
163153
} else if (decimalType == Decimal128.class) {
164-
return decimalType.cast(Decimal128.valueOf(this, OverflowHandling.THROW_EXCEPTION));
154+
return decimalType.cast(Decimal128.valueOf(this, overflowHandling));
165155
} else if (decimalType == Decimal64.class) {
166-
return decimalType.cast(Decimal64.valueOf(this, OverflowHandling.THROW_EXCEPTION));
156+
return decimalType.cast(Decimal64.valueOf(this, overflowHandling));
167157
} else if (decimalType == Decimal32.class) {
168-
return decimalType.cast(Decimal32.valueOf(this, OverflowHandling.THROW_EXCEPTION));
158+
return decimalType.cast(Decimal32.valueOf(this, overflowHandling));
169159
} else {
170160
throw new IllegalArgumentException("Unsupported conversion to " + decimalType.getName());
171161
}

0 commit comments

Comments
 (0)