Skip to content

Commit 66928e1

Browse files
ptzieglerazoitl
authored andcommitted
Avoid usage of deprecated rounding mode in BigDecimal
The setScale(...) method accepting the mode as integer has been deprecated with Java 9. Given that Draw2D requires at least Java 17, we can simply use the drop-in replacement via the RoundingMode enum. Contributes to eclipse-gef#778
1 parent 47b2b5c commit 66928e1

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

org.eclipse.draw2d/src/org/eclipse/draw2d/geometry/PrecisionGeometry.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2010 itemis AG and others.
2+
* Copyright (c) 2010, 2025 itemis AG and others.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License 2.0 which is available at
@@ -14,6 +14,7 @@
1414
package org.eclipse.draw2d.geometry;
1515

1616
import java.math.BigDecimal;
17+
import java.math.RoundingMode;
1718

1819
/**
1920
* A Utilities class for precise geometry calculations.
@@ -27,7 +28,7 @@ public class PrecisionGeometry {
2728
* Precise calculations on doubles are performed based on BigDecimals,
2829
* converting to 16 digits scale, so there are no undesired rounding effects.
2930
*/
30-
private static final int ROUNDING = BigDecimal.ROUND_HALF_EVEN;
31+
private static final RoundingMode ROUNDING = RoundingMode.HALF_EVEN;
3132
private static final int SCALE = 16;
3233

3334
protected static final double preciseAdd(double d1, double d2) {
@@ -55,9 +56,7 @@ protected static final double preciseAbs(double d) {
5556
}
5657

5758
protected static final BigDecimal doubleToBigDecimal(double d) {
58-
// may not use BigDecimal.valueOf due to J2SE-1.4 backwards
59-
// compatibility
60-
return new BigDecimal(Double.toString(d));
59+
return BigDecimal.valueOf(d);
6160
}
6261

6362
/**

0 commit comments

Comments
 (0)