diff --git a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/RuleRegistryImpl.java b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/RuleRegistryImpl.java index bd849baf129..dc41b1c0e48 100644 --- a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/RuleRegistryImpl.java +++ b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/RuleRegistryImpl.java @@ -589,7 +589,7 @@ private boolean checkType(Type type, Object configValue) { return configValue instanceof Boolean; case INTEGER: return configValue instanceof BigDecimal || configValue instanceof Integer - || configValue instanceof Double && ((Double) configValue).intValue() == (Double) configValue; + || configValue instanceof Double doubleValue && doubleValue.intValue() == doubleValue; case DECIMAL: return configValue instanceof BigDecimal || configValue instanceof Double; } diff --git a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/module/handler/AnnotationActionHandler.java b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/module/handler/AnnotationActionHandler.java index 5bfad2d86e7..9d1715dcf9a 100644 --- a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/module/handler/AnnotationActionHandler.java +++ b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/module/handler/AnnotationActionHandler.java @@ -105,16 +105,16 @@ public AnnotationActionHandler(Action module, ActionType mt, Method method, Obje method, moduleType.getUID(), ex.getMessage()); } // we allow simple data types as return values and put them under the context key "result". - } else if (result instanceof Boolean boolean1) { - output.put(MODULE_RESULT, boolean1); + } else if (result instanceof Boolean booleanValue) { + output.put(MODULE_RESULT, booleanValue); } else if (result instanceof String) { output.put(MODULE_RESULT, result); } else if (result instanceof Integer) { output.put(MODULE_RESULT, result); - } else if (result instanceof Double) { - output.put(MODULE_RESULT, (double) result); - } else if (result instanceof Float) { - output.put(MODULE_RESULT, (float) result); + } else if (result instanceof Double doubleValue) { + output.put(MODULE_RESULT, doubleValue); + } else if (result instanceof Float floatValue) { + output.put(MODULE_RESULT, floatValue); } else { logger.warn("Non compatible return type '{}' on action method.", result.getClass()); } diff --git a/bundles/org.openhab.core.config.core/src/main/java/org/openhab/core/config/core/internal/normalization/BooleanNormalizer.java b/bundles/org.openhab.core.config.core/src/main/java/org/openhab/core/config/core/internal/normalization/BooleanNormalizer.java index 118479c6a23..7d0b6f49c9a 100644 --- a/bundles/org.openhab.core.config.core/src/main/java/org/openhab/core/config/core/internal/normalization/BooleanNormalizer.java +++ b/bundles/org.openhab.core.config.core/src/main/java/org/openhab/core/config/core/internal/normalization/BooleanNormalizer.java @@ -31,14 +31,14 @@ public Object doNormalize(Object value) { if (value instanceof Boolean) { return value; } - if (value instanceof Byte) { - return handleNumeric(((Byte) value).longValue()); + if (value instanceof Byte byteValue) { + return handleNumeric(byteValue.longValue()); } - if (value instanceof Integer) { - return handleNumeric(((Integer) value).longValue()); + if (value instanceof Integer integerValue) { + return handleNumeric(integerValue.longValue()); } - if (value instanceof Long) { - return handleNumeric((Long) value); + if (value instanceof Long longValue) { + return handleNumeric(longValue); } String s = value.toString(); if ("true".equalsIgnoreCase(s) || "yes".equalsIgnoreCase(s) || "on".equalsIgnoreCase(s) diff --git a/bundles/org.openhab.core.config.core/src/main/java/org/openhab/core/config/core/internal/normalization/DecimalNormalizer.java b/bundles/org.openhab.core.config.core/src/main/java/org/openhab/core/config/core/internal/normalization/DecimalNormalizer.java index 8c3498f1374..f77bad6825d 100644 --- a/bundles/org.openhab.core.config.core/src/main/java/org/openhab/core/config/core/internal/normalization/DecimalNormalizer.java +++ b/bundles/org.openhab.core.config.core/src/main/java/org/openhab/core/config/core/internal/normalization/DecimalNormalizer.java @@ -28,26 +28,26 @@ final class DecimalNormalizer extends AbstractNormalizer { @Override public Object doNormalize(Object value) { try { - if (value instanceof BigDecimal) { - return stripTrailingZeros((BigDecimal) value); + if (value instanceof BigDecimal bigDecimalValue) { + return stripTrailingZeros(bigDecimalValue); } - if (value instanceof String) { - return stripTrailingZeros(new BigDecimal((String) value)); + if (value instanceof String stringValue) { + return stripTrailingZeros(new BigDecimal(stringValue)); } - if (value instanceof Byte) { - return new BigDecimal((Byte) value).setScale(1); + if (value instanceof Byte byteValue) { + return new BigDecimal(byteValue).setScale(1); } - if (value instanceof Integer) { - return new BigDecimal((Integer) value).setScale(1); + if (value instanceof Integer integerValue) { + return new BigDecimal(integerValue).setScale(1); } - if (value instanceof Long) { - return new BigDecimal((Long) value).setScale(1); + if (value instanceof Long longValue) { + return new BigDecimal(longValue).setScale(1); } - if (value instanceof Float) { - return new BigDecimal(((Float) value).toString()); + if (value instanceof Float floatValue) { + return new BigDecimal(floatValue.toString()); } - if (value instanceof Double) { - return BigDecimal.valueOf((Double) value); + if (value instanceof Double doubleValue) { + return BigDecimal.valueOf(doubleValue); } } catch (ArithmeticException | NumberFormatException e) { logger.trace("\"{}\" is not a valid decimal number.", value, e); diff --git a/bundles/org.openhab.core.config.core/src/main/java/org/openhab/core/config/core/internal/normalization/IntNormalizer.java b/bundles/org.openhab.core.config.core/src/main/java/org/openhab/core/config/core/internal/normalization/IntNormalizer.java index aafa36b609b..0563924977a 100644 --- a/bundles/org.openhab.core.config.core/src/main/java/org/openhab/core/config/core/internal/normalization/IntNormalizer.java +++ b/bundles/org.openhab.core.config.core/src/main/java/org/openhab/core/config/core/internal/normalization/IntNormalizer.java @@ -29,26 +29,26 @@ final class IntNormalizer extends AbstractNormalizer { @Override public Object doNormalize(Object value) { try { - if (value instanceof BigDecimal) { - return ((BigDecimal) value).setScale(0, RoundingMode.UNNECESSARY); + if (value instanceof BigDecimal bigDecimalValue) { + return bigDecimalValue.setScale(0, RoundingMode.UNNECESSARY); } - if (value instanceof Byte) { - return new BigDecimal((Byte) value); + if (value instanceof Byte byteValue) { + return new BigDecimal(byteValue); } - if (value instanceof Integer) { - return new BigDecimal((Integer) value); + if (value instanceof Integer integerValue) { + return new BigDecimal(integerValue); } - if (value instanceof Long) { - return BigDecimal.valueOf((Long) value); + if (value instanceof Long longValue) { + return BigDecimal.valueOf(longValue); } - if (value instanceof String) { - return new BigDecimal((String) value).setScale(0, RoundingMode.UNNECESSARY); + if (value instanceof String stringValue) { + return new BigDecimal(stringValue).setScale(0, RoundingMode.UNNECESSARY); } - if (value instanceof Float) { - return new BigDecimal(((Float) value).toString()).setScale(0, RoundingMode.UNNECESSARY); + if (value instanceof Float floatValue) { + return new BigDecimal(floatValue.toString()).setScale(0, RoundingMode.UNNECESSARY); } - if (value instanceof Double) { - return BigDecimal.valueOf((Double) value).setScale(0, RoundingMode.UNNECESSARY); + if (value instanceof Double doubleValue) { + return BigDecimal.valueOf(doubleValue).setScale(0, RoundingMode.UNNECESSARY); } } catch (ArithmeticException | NumberFormatException e) { logger.trace("\"{}\" is not a valid integer number.", value, e); diff --git a/bundles/org.openhab.core.io.net/src/main/java/org/openhab/core/io/net/http/internal/WebClientFactoryImpl.java b/bundles/org.openhab.core.io.net/src/main/java/org/openhab/core/io/net/http/internal/WebClientFactoryImpl.java index 43b3efa87b7..2380c82fa0e 100644 --- a/bundles/org.openhab.core.io.net/src/main/java/org/openhab/core/io/net/http/internal/WebClientFactoryImpl.java +++ b/bundles/org.openhab.core.io.net/src/main/java/org/openhab/core/io/net/http/internal/WebClientFactoryImpl.java @@ -195,8 +195,8 @@ private int getConfigParameter(Map parameters, String parameter, if (value == null) { return defaultValue; } - if (value instanceof Integer) { - return (Integer) value; + if (value instanceof Integer integerValue) { + return integerValue; } if (value instanceof String string) { try { diff --git a/bundles/org.openhab.core.io.rest.core/src/main/java/org/openhab/core/io/rest/core/internal/item/ItemResource.java b/bundles/org.openhab.core.io.rest.core/src/main/java/org/openhab/core/io/rest/core/internal/item/ItemResource.java index 803df0a41ed..ebe4a1b05e2 100644 --- a/bundles/org.openhab.core.io.rest.core/src/main/java/org/openhab/core/io/rest/core/internal/item/ItemResource.java +++ b/bundles/org.openhab.core.io.rest.core/src/main/java/org/openhab/core/io/rest/core/internal/item/ItemResource.java @@ -271,8 +271,8 @@ public Response getItems(final @Context UriInfo uriInfo, final @Context HttpHead .peek(dto -> addMetadata(dto, namespaces, null)) // .peek(dto -> dto.editable = isEditable(dto.name)) // .peek(dto -> { - if (dto instanceof EnrichedGroupItemDTO) { - for (EnrichedItemDTO member : ((EnrichedGroupItemDTO) dto).members) { + if (dto instanceof EnrichedGroupItemDTO enrichedGroupItemDTO) { + for (EnrichedItemDTO member : enrichedGroupItemDTO.members) { member.editable = isEditable(member.name); } } @@ -329,8 +329,8 @@ public Response getItemByName(final @Context UriInfo uriInfo, final @Context Htt locale); addMetadata(dto, namespaces, null); dto.editable = isEditable(dto.name); - if (dto instanceof EnrichedGroupItemDTO) { - for (EnrichedItemDTO member : ((EnrichedGroupItemDTO) dto).members) { + if (dto instanceof EnrichedGroupItemDTO enrichedGroupItemDTO) { + for (EnrichedItemDTO member : enrichedGroupItemDTO.members) { member.editable = isEditable(member.name); } } diff --git a/bundles/org.openhab.core.model.item/src/org/openhab/core/model/item/internal/GenericItemProvider.java b/bundles/org.openhab.core.model.item/src/org/openhab/core/model/item/internal/GenericItemProvider.java index 55383cf359f..e8d9c83ca7f 100644 --- a/bundles/org.openhab.core.model.item/src/org/openhab/core/model/item/internal/GenericItemProvider.java +++ b/bundles/org.openhab.core.model.item/src/org/openhab/core/model/item/internal/GenericItemProvider.java @@ -97,8 +97,8 @@ public GenericItemProvider(final @Reference ModelRepository modelRepository, this.genericMetaDataProvider = genericMetadataProvider; Object serviceRanking = properties.get(Constants.SERVICE_RANKING); - if (serviceRanking instanceof Integer) { - rank = (Integer) serviceRanking; + if (serviceRanking instanceof Integer integerValue) { + rank = integerValue; } else { rank = 0; } diff --git a/bundles/org.openhab.core.model.script/src/org/openhab/core/model/script/lib/NumberExtensions.java b/bundles/org.openhab.core.model.script/src/org/openhab/core/model/script/lib/NumberExtensions.java index e8619c54039..84720eec0f4 100644 --- a/bundles/org.openhab.core.model.script/src/org/openhab/core/model/script/lib/NumberExtensions.java +++ b/bundles/org.openhab.core.model.script/src/org/openhab/core/model/script/lib/NumberExtensions.java @@ -372,9 +372,8 @@ public static boolean operator_greaterEqualsThan(QuantityType x, Number y) { * @return the given number as BigDecimal or null if number is null */ public static BigDecimal numberToBigDecimal(Number number) { - if (number instanceof QuantityType) { - QuantityType state = ((QuantityType) number) - .toInvertibleUnit(((QuantityType) number).getUnit().getSystemUnit()); + if (number instanceof QuantityType quantity) { + QuantityType state = quantity.toInvertibleUnit(quantity.getUnit().getSystemUnit()); if (state != null) { return state.toBigDecimal(); } @@ -388,8 +387,8 @@ public static BigDecimal numberToBigDecimal(Number number) { } private static boolean oneIsQuantity(Number left, Number right) { - return (left instanceof QuantityType && !isAbstractUnitOne((QuantityType) left)) - || (right instanceof QuantityType && !isAbstractUnitOne((QuantityType) right)); + return (left instanceof QuantityType leftQuantity && !isAbstractUnitOne(leftQuantity)) + || (right instanceof QuantityType rightQuantity && !isAbstractUnitOne(rightQuantity)); } private static boolean isAbstractUnitOne(QuantityType left) { diff --git a/bundles/org.openhab.core.persistence/src/main/java/org/openhab/core/persistence/filter/PersistenceThresholdFilter.java b/bundles/org.openhab.core.persistence/src/main/java/org/openhab/core/persistence/filter/PersistenceThresholdFilter.java index 8e33b993ee2..c337e80049b 100644 --- a/bundles/org.openhab.core.persistence/src/main/java/org/openhab/core/persistence/filter/PersistenceThresholdFilter.java +++ b/bundles/org.openhab.core.persistence/src/main/java/org/openhab/core/persistence/filter/PersistenceThresholdFilter.java @@ -83,9 +83,9 @@ public boolean apply(Item item) { return true; } - if (state instanceof DecimalType) { + if (state instanceof DecimalType decimalState) { BigDecimal oldState = ((DecimalType) cachedState).toBigDecimal(); - BigDecimal delta = oldState.subtract(((DecimalType) state).toBigDecimal()); + BigDecimal delta = oldState.subtract(decimalState.toBigDecimal()); if (relative && !BigDecimal.ZERO.equals(oldState)) { delta = delta.multiply(HUNDRED).divide(oldState, 2, RoundingMode.HALF_UP); } diff --git a/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/internal/ChannelStateDescriptionProvider.java b/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/internal/ChannelStateDescriptionProvider.java index d2a7abe51e3..abe9ec7545d 100644 --- a/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/internal/ChannelStateDescriptionProvider.java +++ b/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/internal/ChannelStateDescriptionProvider.java @@ -71,8 +71,8 @@ public ChannelStateDescriptionProvider(final @Reference ItemChannelLinkRegistry @Activate protected void activate(Map properties) { Object serviceRanking = properties.get(Constants.SERVICE_RANKING); - if (serviceRanking instanceof Integer) { - rank = (Integer) serviceRanking; + if (serviceRanking instanceof Integer integerValue) { + rank = integerValue; } } diff --git a/bundles/org.openhab.core.ui/src/main/java/org/openhab/core/ui/internal/components/UIComponentSitemapProvider.java b/bundles/org.openhab.core.ui/src/main/java/org/openhab/core/ui/internal/components/UIComponentSitemapProvider.java index f07ef8cdedf..f83166dfb1a 100644 --- a/bundles/org.openhab.core.ui/src/main/java/org/openhab/core/ui/internal/components/UIComponentSitemapProvider.java +++ b/bundles/org.openhab.core.ui/src/main/java/org/openhab/core/ui/internal/components/UIComponentSitemapProvider.java @@ -355,8 +355,8 @@ private void setWidgetIconPropertyFromComponentConfig(Widget widget, @Nullable U private void addWidgetMappings(EList mappings, UIComponent component) { if (component.getConfig() != null && component.getConfig().containsKey("mappings")) { Object sourceMappings = component.getConfig().get("mappings"); - if (sourceMappings instanceof Collection) { - for (Object sourceMapping : (Collection) sourceMappings) { + if (sourceMappings instanceof Collection sourceMappingsCollection) { + for (Object sourceMapping : sourceMappingsCollection) { if (sourceMapping instanceof String) { String[] splitMapping = sourceMapping.toString().split("="); String cmd = splitMapping[0].trim(); @@ -376,8 +376,8 @@ private void addWidgetMappings(EList mappings, UIComponent component) { private void addWidgetButtons(EList