Skip to content

Commit e74b11b

Browse files
authored
Replace floating-point constructors with valueOf (#4389)
1 parent e43dadb commit e74b11b

File tree

17 files changed

+49
-48
lines changed

17 files changed

+49
-48
lines changed

.github/scripts/generate-quality-report.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,7 @@ def main() -> None:
797797
"BC_UNCONFIRMED_CAST_OF_RETURN_VALUE",
798798
"CN_IDIOM_NO_SUPER_CALL",
799799
"DM_BOOLEAN_CTOR",
800+
"DM_FP_NUMBER_CTOR",
800801
"DM_EXIT",
801802
"EI_EXPOSE_REP",
802803
"EI_EXPOSE_REP2",

CodenameOne/src/com/codename1/io/JSONParser.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -838,10 +838,10 @@ public void stringToken(String tok) {
838838
*/
839839
public void numericToken(double tok) {
840840
if (isStackHash()) {
841-
getStackHash().put(currentKey, new Double(tok));
841+
getStackHash().put(currentKey, Double.valueOf(tok));
842842
currentKey = null;
843843
} else {
844-
getStackVec().add(new Double(tok));
844+
getStackVec().add(Double.valueOf(tok));
845845
}
846846
}
847847

CodenameOne/src/com/codename1/io/Preferences.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ public static void set(String pref, long l) {
173173
* @param d a number
174174
*/
175175
public static void set(String pref, double d) {
176-
set(pref, new Double(d));
176+
set(pref, Double.valueOf(d));
177177
}
178178

179179
/**
@@ -183,7 +183,7 @@ public static void set(String pref, double d) {
183183
* @param f a number
184184
*/
185185
public static void set(String pref, float f) {
186-
set(pref, new Float(f));
186+
set(pref, Float.valueOf(f));
187187
}
188188

189189
/**

CodenameOne/src/com/codename1/javascript/JSObject.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ public void set(String key, Object js) {
531531
* @param async True if you want this call to be asynchronous.
532532
*/
533533
public void setInt(String key, int value, boolean async) {
534-
set(key, new Double(value), async);
534+
set(key, Double.valueOf(value), async);
535535
}
536536

537537
/**
@@ -552,7 +552,7 @@ public void setInt(String key, int value) {
552552
* @param async True if you want this call to be asynchronous.
553553
*/
554554
public void setDouble(String key, double value, boolean async) {
555-
set(key, new Double(value), async);
555+
set(key, Double.valueOf(value), async);
556556
}
557557

558558
/**
@@ -615,7 +615,7 @@ public void set(int index, Object js) {
615615
* @param async True to make this call asynchronous.
616616
*/
617617
public void setInt(int index, int value, boolean async) {
618-
set(index, new Double(value), async);
618+
set(index, Double.valueOf(value), async);
619619
}
620620

621621
/**
@@ -636,7 +636,7 @@ public void setInt(int index, int value) {
636636
* @param async True to make this call asynchronous.
637637
*/
638638
public void setDouble(int index, double value, boolean async) {
639-
set(index, new Double(value), async);
639+
set(index, Double.valueOf(value), async);
640640
}
641641

642642
/**

CodenameOne/src/com/codename1/maps/MapComponent.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,11 +1107,11 @@ public Class[] getPropertyTypes() {
11071107
public Object getPropertyValue(String name) {
11081108
if (name.equals("latitude")) {
11091109
Coord c = _map.projection().toWGS84(_center);
1110-
return new Double(c.getLatitude());
1110+
return Double.valueOf(c.getLatitude());
11111111
}
11121112
if (name.equals("longitude")) {
11131113
Coord c = _map.projection().toWGS84(_center);
1114-
return new Double(c.getLongitude());
1114+
return Double.valueOf(c.getLongitude());
11151115
}
11161116
if (name.equals("zoom")) {
11171117
return Integer.valueOf(getZoomLevel());

CodenameOne/src/com/codename1/ui/layouts/mig/AC.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ public AC grow(float w) {
450450
* @return <code>this</code> so it is possible to chain calls. E.g. <code>new AxisConstraint().noGrid().gap().fill()</code>.
451451
*/
452452
public AC grow(float w, int... indexes) {
453-
Float gw = new Float(w);
453+
Float gw = Float.valueOf(w);
454454
for (int i = indexes.length - 1; i >= 0; i--) {
455455
int ix = indexes[i];
456456
makeSize(ix);
@@ -527,7 +527,7 @@ public AC shrink(float w) {
527527
* @since 3.7.2
528528
*/
529529
public AC shrink(float w, int... indexes) {
530-
Float sw = new Float(w);
530+
Float sw = Float.valueOf(w);
531531
for (int i = indexes.length - 1; i >= 0; i--) {
532532
int ix = indexes[i];
533533
makeSize(ix);

CodenameOne/src/com/codename1/ui/layouts/mig/CC.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ public CC shrinkPrio(int... widthHeight) {
333333
* @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
334334
*/
335335
public CC shrinkX(float w) {
336-
hor.setShrink(new Float(w));
336+
hor.setShrink(Float.valueOf(w));
337337
return this;
338338
}
339339

@@ -560,7 +560,7 @@ public CC shrinkPrioY(int p) {
560560
* @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
561561
*/
562562
public CC shrinkY(float w) {
563-
ver.setShrink(new Float(w));
563+
ver.setShrink(Float.valueOf(w));
564564
return this;
565565
}
566566

CodenameOne/src/com/codename1/ui/layouts/mig/CodenameOneMiGComponentWrapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public final float getPixelUnitFactor(boolean isHor) {
133133

134134
Float s = isHor ? PlatformDefaults.getHorizontalScaleFactor() : PlatformDefaults.getVerticalScaleFactor();
135135
if (s == null)
136-
s = new Float(1.0f);
136+
s = Float.valueOf(1.0f);
137137
return s * (isHor ? getHorizontalScreenDPI() : getVerticalScreenDPI()) / (float) PlatformDefaults.getDefaultDPI();
138138

139139
default:

CodenameOne/src/com/codename1/ui/layouts/mig/ConstraintParser.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -898,10 +898,10 @@ public static CC parseComponentConstraint(String s) {
898898
}
899899

900900
if (part.equals("dock center")) {
901-
cc.getHorizontal().setGrow(new Float(100f));
902-
cc.getVertical().setGrow(new Float(100f));
903-
cc.setPushX(new Float(100f));
904-
cc.setPushY(new Float(100f));
901+
cc.getHorizontal().setGrow(Float.valueOf(100f));
902+
cc.getVertical().setGrow(Float.valueOf(100f));
903+
cc.setPushX(Float.valueOf(100f));
904+
cc.setPushY(Float.valueOf(100f));
905905
continue;
906906
}
907907
}
@@ -1067,7 +1067,7 @@ private static int parseSpan(String s) {
10671067
}
10681068

10691069
private static Float parseFloat(String s, Float nullVal) {
1070-
return s.length() > 0 ? new Float(Float.parseFloat(s)) : nullVal;
1070+
return s.length() > 0 ? Float.valueOf(Float.parseFloat(s)) : nullVal;
10711071
}
10721072

10731073
/**

CodenameOne/src/com/codename1/ui/layouts/mig/ResizeConstraint.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
* grow compared to other entities.
4040
*/
4141
final class ResizeConstraint {
42-
static final Float WEIGHT_100 = new Float(100);
42+
static final Float WEIGHT_100 = Float.valueOf(100);
4343

4444
/**
4545
* How flexilble the entity should be, relative to other entities, when it comes to growing. <code>null</code> or

0 commit comments

Comments
 (0)