From 7cb746ece1829fcec285f023f88295f1750bfe81 Mon Sep 17 00:00:00 2001 From: Christoph Weitkamp Date: Sat, 14 Nov 2020 13:46:03 +0100 Subject: [PATCH] Changed comparison from equals() to reference (#1817) Signed-off-by: Christoph Weitkamp --- .../ChannelCommandDescriptionProvider.java | 2 +- .../ChannelStateDescriptionProvider.java | 17 +++++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/internal/ChannelCommandDescriptionProvider.java b/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/internal/ChannelCommandDescriptionProvider.java index ef8e4394b..980f39b3d 100644 --- a/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/internal/ChannelCommandDescriptionProvider.java +++ b/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/internal/ChannelCommandDescriptionProvider.java @@ -90,7 +90,7 @@ public class ChannelCommandDescriptionProvider implements CommandDescriptionProv CommandDescription dynamicCommandDescription = dynamicCommandDescriptionProvider .getCommandDescription(channel, originalCommandDescription, locale); if (dynamicCommandDescription != null) { - if (dynamicCommandDescription.equals(originalCommandDescription)) { + if (dynamicCommandDescription == originalCommandDescription) { logger.error( "Dynamic command description matches original command description. DynamicCommandDescriptionProvider implementations must never return the original command description. {} has to be fixed.", dynamicCommandDescription.getClass()); 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 5aa55b4a1..02ddc4b68 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 @@ -100,12 +100,12 @@ public class ChannelStateDescriptionProvider implements StateDescriptionFragment ChannelType channelType = thingTypeRegistry.getChannelType(channel, locale); if (channelType != null) { stateDescription = channelType.getState(); - if ((channelType.getItemType() != null) - && ((stateDescription == null) || (stateDescription.getPattern() == null))) { + String itemType = channelType.getItemType(); + if (itemType != null && (stateDescription == null || stateDescription.getPattern() == null)) { String pattern = null; - if (CoreItemFactory.STRING.equalsIgnoreCase(channelType.getItemType())) { + if (CoreItemFactory.STRING.equalsIgnoreCase(itemType)) { pattern = "%s"; - } else if (channelType.getItemType().startsWith(CoreItemFactory.NUMBER)) { + } else if (itemType.startsWith(CoreItemFactory.NUMBER)) { pattern = "%.0f"; } if (pattern != null) { @@ -131,14 +131,15 @@ public class ChannelStateDescriptionProvider implements StateDescriptionFragment private @Nullable StateDescription getDynamicStateDescription(Channel channel, @Nullable StateDescription originalStateDescription, @Nullable Locale locale) { for (DynamicStateDescriptionProvider provider : dynamicStateDescriptionProviders) { - StateDescription stateDescription = provider.getStateDescription(channel, originalStateDescription, locale); - if (stateDescription != null) { - if (stateDescription.equals(originalStateDescription)) { + StateDescription dynamicStateDescription = provider.getStateDescription(channel, originalStateDescription, + locale); + if (dynamicStateDescription != null) { + if (dynamicStateDescription == originalStateDescription) { logger.error( "Dynamic state description matches original state description. DynamicStateDescriptionProvider implementations must never return the original state description. {} has to be fixed.", provider.getClass()); } else { - return stateDescription; + return dynamicStateDescription; } } }