Skip to content

Commit

Permalink
Remove unnecessary boxing (#3969)
Browse files Browse the repository at this point in the history
Using primitives makes the code faster and consume less memory.

Signed-off-by: Wouter Born <[email protected]>
  • Loading branch information
wborn authored Dec 27, 2023
1 parent ff6b33f commit ec05a63
Show file tree
Hide file tree
Showing 11 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ protected long getTimestampOfLastScan() {

private boolean getAutoDiscoveryEnabled(Object autoDiscoveryEnabled) {
if (autoDiscoveryEnabled instanceof String string) {
return Boolean.valueOf(string);
return Boolean.parseBoolean(string);
} else {
return Boolean.TRUE.equals(autoDiscoveryEnabled);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ private static ProxyParams prepareProxyParams() {
String proxyPortString = System.getProperty("http.proxyPort");
if (proxyPortString != null && !proxyPortString.isBlank()) {
try {
proxyParams.proxyPort = Integer.valueOf(proxyPortString);
proxyParams.proxyPort = Integer.parseInt(proxyPortString);
} catch (NumberFormatException e) {
LOGGER.warn("'{}' is not a valid proxy port - using default port ({}) instead", proxyPortString,
proxyParams.proxyPort);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ public Response setEnabled(
return getThingNotFoundResponse(thingUID);
}

thingManager.setEnabled(thingUIDObject, Boolean.valueOf(enabled));
thingManager.setEnabled(thingUIDObject, Boolean.parseBoolean(enabled));

// everything went well
return getThingResponse(Status.OK, thing, locale, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,14 @@ public class MqttWillAndTestament {
break;
case 2:
if (!"".equals(value)) {
int tmp = Integer.valueOf(value);
int tmp = Integer.parseInt(value);
if (tmp >= 0 && tmp <= 2) {
tmpQos = tmp;
}
}
break;
case 3:
tmpRetain = Boolean.valueOf(value);
tmpRetain = Boolean.parseBoolean(value);
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public SystemHysteresisStateProfile(ProfileCallback callback, ProfileContext con
this.upper = convertedUpperParam;

final Object paramValue = context.getConfiguration().get(INVERTED_PARAM);
final boolean inverted = paramValue == null ? false : Boolean.valueOf(paramValue.toString());
final boolean inverted = paramValue != null && Boolean.parseBoolean(paramValue.toString());
this.low = OnOffType.from(inverted);
this.high = OnOffType.from(!inverted);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public SystemRangeStateProfile(ProfileCallback callback, ProfileContext context)
this.upper = convertedUpperParam;

final Object paramValue = context.getConfiguration().get(INVERTED_PARAM);
final boolean inverted = paramValue == null ? false : Boolean.valueOf(paramValue.toString());
final boolean inverted = paramValue != null && Boolean.parseBoolean(paramValue.toString());
this.inRange = OnOffType.from(!inverted);
this.notInRange = OnOffType.from(inverted);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public TimestampOffsetProfile(ProfileCallback callback, ProfileContext context)
if (offsetParam instanceof Number bd) {
offset = Duration.ofSeconds(bd.longValue());
} else if (offsetParam instanceof String s) {
offset = Duration.ofSeconds(Long.valueOf(s));
offset = Duration.ofSeconds(Long.parseLong(s));
} else {
logger.error(
"Parameter '{}' is not of type String or Number. Please make sure it is one of both, e.g. 3 or \"-1\".",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public StateDescriptionConverter() {

private boolean toBoolean(Map<String, String> attributes, String attribute, boolean defaultValue) {
String attrValueText = attributes.get(attribute);
return attrValueText == null ? defaultValue : Boolean.valueOf(attrValueText);
return attrValueText == null ? defaultValue : Boolean.parseBoolean(attrValueText);
}

private List<StateOption> toListOfChannelState(NodeList nodeList) throws ConversionException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ public Set<IconSet> getIconSets() {
} else {
// let's treat all percentage-based categories
try {
Double stateAsDouble = Double.valueOf(iconState);
double stateAsDouble = Double.parseDouble(iconState);
if (stateAsDouble >= 0 && stateAsDouble <= 100) {
for (int i = stateAsDouble.intValue(); i >= 0; i--) {
for (int i = (int) stateAsDouble; i >= 0; i--) {
String resourceWithNumberState = category.toLowerCase() + "-" + i + "."
+ format.toString().toLowerCase();
if (hasResource(iconSetId, resourceWithNumberState)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ private void setWidgetPropertyFromComponentConfig(Widget widget, @Nullable UICom
Object normalizedValue = ConfigUtil.normalizeType(value);
if (widgetImpl.eGet(feature, false, false) instanceof Integer) {
normalizedValue = (normalizedValue instanceof BigDecimal bd) ? bd.intValue()
: Integer.valueOf(normalizedValue.toString());
: Integer.parseInt(normalizedValue.toString());
} else if (widgetImpl.eGet(feature, false, false) instanceof Boolean
&& !(normalizedValue instanceof Boolean)) {
normalizedValue = Boolean.valueOf(normalizedValue.toString());
Expand All @@ -337,7 +337,7 @@ private void setWidgetIconPropertyFromComponentConfig(Widget widget, @Nullable U
return;
}
Object staticIcon = component.getConfig().get("staticIcon");
if (staticIcon != null && Boolean.valueOf(ConfigUtil.normalizeType(staticIcon).toString())) {
if (staticIcon != null && Boolean.parseBoolean(ConfigUtil.normalizeType(staticIcon).toString())) {
setWidgetPropertyFromComponentConfig(widget, component, "icon", SitemapPackage.WIDGET__STATIC_ICON);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ private boolean getConfigParameter(Map<String, Object> parameters, String parame
return boolean1;
}
if (value instanceof String string) {
return Boolean.valueOf(string);
return Boolean.parseBoolean(string);
} else {
return defaultValue;
}
Expand Down

0 comments on commit ec05a63

Please sign in to comment.