From 85056d9d7b41cca4f3e34d927adcbd0fb5af87fb Mon Sep 17 00:00:00 2001 From: Wouter Born Date: Sun, 4 Feb 2024 11:17:55 +0100 Subject: [PATCH] Some more code cleanup (#4021) This cleanup includes: * Use enhanced for loops * Use text blocks * Use Objects.equals * Fix some typos * Remove redundant variable initialization * Remove redundant null checks with instanceof * Remove redundant thrown Exceptions * Remove redundant empty String concatenation Signed-off-by: Wouter Born --- .../openhab/core/addon/AddonInfoRegistry.java | 6 +- .../AudioConsoleCommandExtension.java | 4 +- .../audio/internal/javasound/AudioPlayer.java | 9 +- .../javasound/JavaSoundAudioSink.java | 2 +- .../core/audio/utils/ToneSynthesizer.java | 3 +- .../internal/cipher/SymmetricKeyCipher.java | 2 +- .../handler/AbstractScriptModuleHandler.java | 2 +- .../internal/ConnectionValidator.java | 17 +- .../automation/internal/RuleEngineImpl.java | 8 +- .../automation/internal/RuleRegistryImpl.java | 5 +- .../commands/AutomationCommandList.java | 11 +- .../CommandlineModuleTypeProvider.java | 4 +- .../commands/CommandlineRuleImporter.java | 5 +- .../commands/CommandlineTemplateProvider.java | 2 +- .../automation/internal/commands/Utils.java | 6 +- .../composite/CompositeTriggerHandler.java | 2 +- .../handler/CompareConditionHandler.java | 7 +- .../AbstractResourceBundleProvider.java | 6 +- .../AutomationResourceBundlesEventQueue.java | 7 +- .../i18n/ModuleTypeI18nServiceImpl.java | 6 +- .../core/xml/ConfigDescriptionConverter.java | 2 +- .../ConfigDescriptionParameterConverter.java | 2 +- .../core/xml/util/ConverterValueMap.java | 2 +- .../xml/util/XmlDocumentReaderTest.java | 3 +- .../discovery/addon/ip/IpAddonFinder.java | 6 +- .../usbserial/UsbSerialDeviceInformation.java | 4 +- .../discovery/DiscoveryResultBuilderTest.java | 1 + .../dispatch/internal/ConfigDispatcher.java | 5 +- .../auth/internal/AuthorizePageServlet.java | 2 +- .../core/io/net/http/PEMTrustManager.java | 2 +- .../core/io/rest/auth/internal/JwtHelper.java | 5 +- .../internal/discovery/InboxResource.java | 2 +- .../io/rest/mdns/internal/MDNSAnnouncer.java | 2 +- .../sitemap/SitemapSubscriptionService.java | 2 +- .../io/rest/internal/filter/ProxyFilter.java | 2 +- ...UtilitiesExtractIndividualMethodsTest.java | 4 +- .../serial/internal/JavaCommPortProvider.java | 2 +- .../serial/internal/SerialPortUtil.java | 2 +- .../upnp/internal/UpnpIOServiceImpl.java | 2 +- .../core/internal/ModelRepositoryImpl.java | 2 +- .../core/model/script/actions/Voice.java | 4 +- .../model/script/lib/NumberExtensions.java | 12 +- .../GenericItemChannelLinkProvider.java | 2 +- .../core/thing/binding/ThingFactory.java | 2 +- .../thing/internal/CommunicationManager.java | 2 +- .../thing/internal/firmware/FirmwareImpl.java | 2 +- .../profiles/TimestampOffsetProfile.java | 2 +- .../xml/internal/ThingTypeConverter.java | 5 +- .../ui/icon/internal/IconServletTest.java | 2 +- .../internal/proxy/BlockingProxyServlet.java | 11 +- .../internal/proxy/ProxyServletService.java | 2 +- .../items/ItemUIRegistryImplTest.java | 162 +++++++++--------- .../text/AbstractRuleBasedInterpreter.java | 2 +- .../openhab/core/voice/text/TokenList.java | 6 +- .../core/internal/items/ItemUpdater.java | 2 +- .../types/StateDescriptionFragmentImpl.java | 10 +- .../core/items/ManagedItemProvider.java | 6 +- .../core/items/events/ItemEventFactory.java | 2 +- .../core/library/types/DateTimeType.java | 4 +- .../openhab/core/library/types/PointType.java | 6 +- .../org/openhab/core/net/HttpServiceUtil.java | 2 +- .../org/openhab/core/types/CommandOption.java | 4 +- .../openhab/core/types/StateDescription.java | 7 +- .../org/openhab/core/types/StateOption.java | 4 +- .../java/org/openhab/core/util/ColorUtil.java | 6 +- .../cache/lru/LRUMediaCacheEntryTest.java | 2 +- .../test/AutomationIntegrationTest.java | 4 +- .../defaultscope/ScriptRuleOSGiTest.java | 5 +- .../internal/ConfigDispatcherOSGiTest.java | 6 +- .../internal/GenericItemProviderTest.java | 30 ++-- .../test/hue/GenericThingProviderTest.java | 12 +- .../test/hue/GenericThingProviderTest2.java | 29 ++-- .../internal/JsonStorageServiceOSGiTest.java | 2 +- .../internal/ChannelLinkNotifierOSGiTest.java | 2 +- .../core/tools/i18n/plugin/Translations.java | 15 +- 75 files changed, 250 insertions(+), 294 deletions(-) diff --git a/bundles/org.openhab.core.addon/src/main/java/org/openhab/core/addon/AddonInfoRegistry.java b/bundles/org.openhab.core.addon/src/main/java/org/openhab/core/addon/AddonInfoRegistry.java index 9f09f1747..2815fe8a0 100644 --- a/bundles/org.openhab.core.addon/src/main/java/org/openhab/core/addon/AddonInfoRegistry.java +++ b/bundles/org.openhab.core.addon/src/main/java/org/openhab/core/addon/AddonInfoRegistry.java @@ -16,10 +16,10 @@ import java.util.Collection; import java.util.HashSet; import java.util.Locale; import java.util.Objects; -import java.util.Optional; import java.util.Set; import java.util.concurrent.CopyOnWriteArrayList; import java.util.function.BinaryOperator; +import java.util.function.Function; import java.util.stream.Collectors; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -79,9 +79,7 @@ public class AddonInfoRegistry { */ public @Nullable AddonInfo getAddonInfo(String uid, @Nullable Locale locale) { return addonInfoProviders.stream().map(p -> p.getAddonInfo(uid, locale)).filter(Objects::nonNull) - .collect(Collectors.groupingBy(a -> a == null ? "" : a.getUID(), - Collectors.collectingAndThen(Collectors.reducing(mergeAddonInfos), Optional::get))) - .get(uid); + .collect(Collectors.toMap(a -> a.getUID(), Function.identity(), mergeAddonInfos)).get(uid); } /** diff --git a/bundles/org.openhab.core.audio/src/main/java/org/openhab/core/audio/internal/AudioConsoleCommandExtension.java b/bundles/org.openhab.core.audio/src/main/java/org/openhab/core/audio/internal/AudioConsoleCommandExtension.java index c479be2cf..51e9142ca 100644 --- a/bundles/org.openhab.core.audio/src/main/java/org/openhab/core/audio/internal/AudioConsoleCommandExtension.java +++ b/bundles/org.openhab.core.audio/src/main/java/org/openhab/core/audio/internal/AudioConsoleCommandExtension.java @@ -161,7 +161,7 @@ public class AudioConsoleCommandExtension extends AbstractConsoleCommandExtensio playOnSinks(args[0], args[1], null, console); break; case 3: - PercentType volume = null; + PercentType volume; try { volume = PercentType.valueOf(args[2]); } catch (Exception e) { @@ -184,7 +184,7 @@ public class AudioConsoleCommandExtension extends AbstractConsoleCommandExtensio playMelodyOnSinks(args[0], args[1], null, console); break; case 3: - PercentType volume = null; + PercentType volume; try { volume = PercentType.valueOf(args[2]); } catch (Exception e) { diff --git a/bundles/org.openhab.core.audio/src/main/java/org/openhab/core/audio/internal/javasound/AudioPlayer.java b/bundles/org.openhab.core.audio/src/main/java/org/openhab/core/audio/internal/javasound/AudioPlayer.java index 01af04810..f6214a4df 100644 --- a/bundles/org.openhab.core.audio/src/main/java/org/openhab/core/audio/internal/javasound/AudioPlayer.java +++ b/bundles/org.openhab.core.audio/src/main/java/org/openhab/core/audio/internal/javasound/AudioPlayer.java @@ -17,7 +17,6 @@ import java.io.IOException; import javax.sound.sampled.AudioFormat; import javax.sound.sampled.AudioSystem; import javax.sound.sampled.DataLine; -import javax.sound.sampled.Line; import javax.sound.sampled.Line.Info; import javax.sound.sampled.Mixer; import javax.sound.sampled.SourceDataLine; @@ -77,10 +76,10 @@ public class AudioPlayer extends Thread { logger.warn("No line found: {}", e.getMessage()); logger.info("Available lines are:"); Mixer.Info[] mixerInfo = AudioSystem.getMixerInfo(); // get available mixers - Mixer mixer = null; - for (int cnt = 0; cnt < mixerInfo.length; cnt++) { - mixer = AudioSystem.getMixer(mixerInfo[cnt]); - Line.Info[] lineInfos = mixer.getSourceLineInfo(); + Mixer mixer; + for (Mixer.Info value : mixerInfo) { + mixer = AudioSystem.getMixer(value); + Info[] lineInfos = mixer.getSourceLineInfo(); for (Info lineInfo : lineInfos) { logger.info("{}", lineInfo); } diff --git a/bundles/org.openhab.core.audio/src/main/java/org/openhab/core/audio/internal/javasound/JavaSoundAudioSink.java b/bundles/org.openhab.core.audio/src/main/java/org/openhab/core/audio/internal/javasound/JavaSoundAudioSink.java index deae55c4c..ae173752e 100644 --- a/bundles/org.openhab.core.audio/src/main/java/org/openhab/core/audio/internal/javasound/JavaSoundAudioSink.java +++ b/bundles/org.openhab.core.audio/src/main/java/org/openhab/core/audio/internal/javasound/JavaSoundAudioSink.java @@ -201,7 +201,7 @@ public class JavaSoundAudioSink extends AudioSinkAsync { if (cachedVolume == null) { Process p = Runtime.getRuntime() .exec(new String[] { "osascript", "-e", "output volume of (get volume settings)" }); - String value = null; + String value; try (Scanner scanner = new Scanner(p.getInputStream(), StandardCharsets.UTF_8.name())) { value = scanner.useDelimiter("\\A").next().strip(); } diff --git a/bundles/org.openhab.core.audio/src/main/java/org/openhab/core/audio/utils/ToneSynthesizer.java b/bundles/org.openhab.core.audio/src/main/java/org/openhab/core/audio/utils/ToneSynthesizer.java index f037bc72a..39725db52 100644 --- a/bundles/org.openhab.core.audio/src/main/java/org/openhab/core/audio/utils/ToneSynthesizer.java +++ b/bundles/org.openhab.core.audio/src/main/java/org/openhab/core/audio/utils/ToneSynthesizer.java @@ -69,8 +69,7 @@ public class ToneSynthesizer { var melodySounds = new ArrayList(); var noteTextList = melody.split("\\s"); var melodyTextIndex = 0; - for (var i = 0; i < noteTextList.length; i++) { - var noteText = noteTextList[i]; + for (String noteText : noteTextList) { var noteTextParts = noteText.split(":"); var soundMillis = 200; switch (noteTextParts.length) { diff --git a/bundles/org.openhab.core.auth.oauth2client/src/main/java/org/openhab/core/auth/oauth2client/internal/cipher/SymmetricKeyCipher.java b/bundles/org.openhab.core.auth.oauth2client/src/main/java/org/openhab/core/auth/oauth2client/internal/cipher/SymmetricKeyCipher.java index dd0c0edd1..244e8cd55 100644 --- a/bundles/org.openhab.core.auth.oauth2client/src/main/java/org/openhab/core/auth/oauth2client/internal/cipher/SymmetricKeyCipher.java +++ b/bundles/org.openhab.core.auth.oauth2client/src/main/java/org/openhab/core/auth/oauth2client/internal/cipher/SymmetricKeyCipher.java @@ -132,7 +132,7 @@ public class SymmetricKeyCipher implements StorageCipher { private SecretKey getOrGenerateEncryptionKey() throws NoSuchAlgorithmException, IOException { Configuration configuration = configurationAdmin.getConfiguration(PID); - String encryptionKeyInBase64 = null; + String encryptionKeyInBase64; Dictionary properties = configuration.getProperties(); if (properties == null) { properties = new Hashtable<>(); diff --git a/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/internal/handler/AbstractScriptModuleHandler.java b/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/internal/handler/AbstractScriptModuleHandler.java index 034a543d9..af1cc293c 100644 --- a/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/internal/handler/AbstractScriptModuleHandler.java +++ b/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/internal/handler/AbstractScriptModuleHandler.java @@ -71,7 +71,7 @@ public abstract class AbstractScriptModuleHandler extends Base private static String getValidConfigParameter(String parameter, Configuration config, String moduleId) { Object value = config.get(parameter); - if (value != null && value instanceof String string && !string.trim().isEmpty()) { + if (value instanceof String string && !string.trim().isEmpty()) { return string; } else { throw new IllegalStateException(String.format( diff --git a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/ConnectionValidator.java b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/ConnectionValidator.java index 515429f3d..cecd45e19 100644 --- a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/ConnectionValidator.java +++ b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/ConnectionValidator.java @@ -14,7 +14,6 @@ package org.openhab.core.automation.internal; import java.util.HashMap; import java.util.HashSet; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -109,17 +108,15 @@ public class ConnectionValidator { List inputs = type.getInputs(); // get inputs of the condition according to module type definition // gets connected inputs from the condition module and put them into map - Set cons = getConnections(action.getInputs()); + Set connections = getConnections(action.getInputs()); Map connectionsMap = new HashMap<>(); - Iterator connectionsI = cons.iterator(); - while (connectionsI.hasNext()) { - Connection connection = connectionsI.next(); + for (Connection connection : connections) { String inputName = connection.getInputName(); connectionsMap.put(inputName, connection); } // checks is there unconnected required inputs - if (inputs != null && !inputs.isEmpty()) { + if (!inputs.isEmpty()) { for (Input input : inputs) { String name = input.getName(); Connection connection = connectionsMap.get(name); @@ -185,17 +182,15 @@ public class ConnectionValidator { List inputs = type.getInputs(); // get inputs of the condition according to module type definition // gets connected inputs from the condition module and put them into map - Set cons = getConnections(condition.getInputs()); + Set connections = getConnections(condition.getInputs()); Map connectionsMap = new HashMap<>(); - Iterator connectionsI = cons.iterator(); - while (connectionsI.hasNext()) { - Connection connection = connectionsI.next(); + for (Connection connection : connections) { String inputName = connection.getInputName(); connectionsMap.put(inputName, connection); } // checks is there unconnected required inputs - if (inputs != null && !inputs.isEmpty()) { + if (!inputs.isEmpty()) { for (Input input : inputs) { String name = input.getName(); Connection connection = connectionsMap.get(name); diff --git a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/RuleEngineImpl.java b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/RuleEngineImpl.java index 922bba270..1c636339e 100644 --- a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/RuleEngineImpl.java +++ b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/RuleEngineImpl.java @@ -708,7 +708,7 @@ public class RuleEngineImpl implements RuleManager, RegistryChangeListener moduleTypes) { Map> mapMissingHandlers = null; for (String moduleTypeName : moduleTypes) { - Set rules = null; + Set rules; synchronized (this) { rules = mapModuleTypeToRules.get(moduleTypeName); } @@ -1145,7 +1145,7 @@ public class RuleEngineImpl implements RuleManager, RegistryChangeListener configDescriptions) { if (configDescriptions != null && !configDescriptions.isEmpty()) { boolean required = false; - Iterator i = configDescriptions.iterator(); - while (i.hasNext()) { - ConfigDescriptionParameter param = i.next(); + for (ConfigDescriptionParameter param : configDescriptions) { required = required || param.isRequired(); } return !required; diff --git a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/commands/AutomationCommandList.java b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/commands/AutomationCommandList.java index 1bdcf5d54..85b454393 100644 --- a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/commands/AutomationCommandList.java +++ b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/commands/AutomationCommandList.java @@ -15,7 +15,6 @@ package org.openhab.core.automation.internal.commands; import java.util.ArrayList; import java.util.Collection; import java.util.Hashtable; -import java.util.Iterator; import java.util.Locale; import java.util.Map; @@ -278,7 +277,7 @@ public class AutomationCommandList extends AutomationCommand { private Collection getRuleByFilter(Map list) { Collection rules = new ArrayList<>(); if (!list.isEmpty()) { - Rule r = null; + Rule r; String uid = list.get(id); if (uid != null) { r = autoCommands.getRule(uid); @@ -313,7 +312,7 @@ public class AutomationCommandList extends AutomationCommand { */ private Collection getTemplateByFilter(Map list) { Collection templates = new ArrayList<>(); - RuleTemplate t = null; + RuleTemplate t; String uid = list.get(id); if (uid != null) { t = autoCommands.getTemplate(uid, locale); @@ -348,7 +347,7 @@ public class AutomationCommandList extends AutomationCommand { private Collection getModuleTypeByFilter(Map list) { Collection moduleTypes = new ArrayList<>(); if (!list.isEmpty()) { - ModuleType mt = null; + ModuleType mt; String uid = list.get(id); if (uid != null) { mt = autoCommands.getModuleType(uid, locale); @@ -385,9 +384,7 @@ public class AutomationCommandList extends AutomationCommand { @SuppressWarnings({ "rawtypes", "unchecked" }) private void addCollection(Collection collection, Map list) { if (collection != null && !collection.isEmpty()) { - Iterator i = collection.iterator(); - while (i.hasNext()) { - Object element = i.next(); + for (Object element : collection) { if (element instanceof ModuleType type) { list.put(type.getUID(), element); } diff --git a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/commands/CommandlineModuleTypeProvider.java b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/commands/CommandlineModuleTypeProvider.java index f519fe82d..56330d4ff 100644 --- a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/commands/CommandlineModuleTypeProvider.java +++ b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/commands/CommandlineModuleTypeProvider.java @@ -156,7 +156,7 @@ public class CommandlineModuleTypeProvider extends AbstractCommandProviderSUCCESS. */ public String remove(URL url) { - List portfolio = null; + List portfolio; synchronized (providerPortfolio) { portfolio = providerPortfolio.remove(url); } @@ -184,7 +184,7 @@ public class CommandlineModuleTypeProvider extends AbstractCommandProvider providedObjects = parser.parse(inputStreamReader); if (providedObjects != null && !providedObjects.isEmpty()) { - String uid = null; + String uid; List portfolio = new ArrayList<>(); synchronized (providerPortfolio) { providerPortfolio.put(url, portfolio); diff --git a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/commands/CommandlineRuleImporter.java b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/commands/CommandlineRuleImporter.java index 65b402ffa..2a32b01ad 100644 --- a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/commands/CommandlineRuleImporter.java +++ b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/commands/CommandlineRuleImporter.java @@ -17,7 +17,6 @@ import java.io.File; import java.io.IOException; import java.io.InputStreamReader; import java.net.URL; -import java.util.Iterator; import java.util.Set; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -119,9 +118,7 @@ public class CommandlineRuleImporter extends AbstractCommandProvider { throws ParsingException { Set providedRules = parser.parse(inputStreamReader); if (providedRules != null && !providedRules.isEmpty()) { - Iterator i = providedRules.iterator(); - while (i.hasNext()) { - Rule rule = i.next(); + for (Rule rule : providedRules) { if (rule != null) { if (ruleRegistry.get(rule.getUID()) != null) { ruleRegistry.update(rule); diff --git a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/commands/CommandlineTemplateProvider.java b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/commands/CommandlineTemplateProvider.java index e0160c070..230f50441 100644 --- a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/commands/CommandlineTemplateProvider.java +++ b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/commands/CommandlineTemplateProvider.java @@ -150,7 +150,7 @@ public class CommandlineTemplateProvider extends AbstractCommandProviderSUCCESS. */ public String remove(URL url) { - List portfolio = null; + List portfolio; synchronized (providerPortfolio) { portfolio = providerPortfolio.remove(url); } diff --git a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/commands/Utils.java b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/commands/Utils.java index 2eff00eea..c1273263c 100644 --- a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/commands/Utils.java +++ b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/commands/Utils.java @@ -179,11 +179,7 @@ public class Utils { if (count < 1) { return ""; } - StringBuilder sb = new StringBuilder(); - for (int i = 0; i < count; i++) { - sb.append(ch); - } - return sb.toString(); + return String.valueOf(ch).repeat(count); } /** diff --git a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/composite/CompositeTriggerHandler.java b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/composite/CompositeTriggerHandler.java index 77b3a37a1..fc8eee56f 100644 --- a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/composite/CompositeTriggerHandler.java +++ b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/composite/CompositeTriggerHandler.java @@ -88,7 +88,7 @@ public class CompositeTriggerHandler ref = ref.substring(i + 1); } } - Object value = null; + Object value; int idx = ReferenceResolver.getNextRefToken(ref, 1); if (idx < ref.length()) { String outputId = ref.substring(0, idx); diff --git a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/module/handler/CompareConditionHandler.java b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/module/handler/CompareConditionHandler.java index 70d52d700..288823d2f 100644 --- a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/module/handler/CompareConditionHandler.java +++ b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/module/handler/CompareConditionHandler.java @@ -51,12 +51,11 @@ public class CompareConditionHandler extends BaseConditionModuleHandler { @Override public boolean isSatisfied(Map context) { Object operatorObj = this.module.getConfiguration().get(OPERATOR); - String operator = (operatorObj != null && operatorObj instanceof String s) ? s : null; + String operator = operatorObj instanceof String s ? s : null; Object rightObj = this.module.getConfiguration().get(RIGHT_OP); - String rightOperandString = (rightObj != null && rightObj instanceof String s) ? s : null; + String rightOperandString = rightObj instanceof String s ? s : null; Object leftObjFieldNameObj = this.module.getConfiguration().get(INPUT_LEFT_FIELD); - String leftObjectFieldName = (leftObjFieldNameObj != null && leftObjFieldNameObj instanceof String s) ? s - : null; + String leftObjectFieldName = leftObjFieldNameObj instanceof String s ? s : null; if (rightOperandString == null || operator == null) { return false; } else { diff --git a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/provider/AbstractResourceBundleProvider.java b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/provider/AbstractResourceBundleProvider.java index 0aee0b6d8..e26e54dd6 100644 --- a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/provider/AbstractResourceBundleProvider.java +++ b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/provider/AbstractResourceBundleProvider.java @@ -266,7 +266,7 @@ public abstract class AbstractResourceBundleProvider<@NonNull E> { if (!newPortfolio.contains(uid)) { final @Nullable E removedObject = providedObjectsHolder.remove(uid); if (removedObject != null) { - List> snapshot = null; + List> snapshot; synchronized (listeners) { snapshot = new LinkedList<>(listeners); } @@ -333,7 +333,7 @@ public abstract class AbstractResourceBundleProvider<@NonNull E> { for (String uid : portfolio) { final @Nullable E removedObject = providedObjectsHolder.remove(uid); if (removedObject != null) { - List> snapshot = null; + List> snapshot; synchronized (listeners) { snapshot = new LinkedList<>(listeners); } @@ -431,7 +431,7 @@ public abstract class AbstractResourceBundleProvider<@NonNull E> { @SuppressWarnings("unchecked") protected void addNewProvidedObjects(List newPortfolio, List previousPortfolio, Set parsedObjects) { - List> snapshot = null; + List> snapshot; synchronized (listeners) { snapshot = new LinkedList<>(listeners); } diff --git a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/provider/AutomationResourceBundlesEventQueue.java b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/provider/AutomationResourceBundlesEventQueue.java index 0210d165b..690e38938 100644 --- a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/provider/AutomationResourceBundlesEventQueue.java +++ b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/provider/AutomationResourceBundlesEventQueue.java @@ -13,7 +13,6 @@ package org.openhab.core.automation.internal.provider; import java.util.ArrayList; -import java.util.Iterator; import java.util.LinkedList; import java.util.List; @@ -94,7 +93,7 @@ public class AutomationResourceBundlesEventQueue<@NonNull E> implements Runnable public void run() { boolean waitForEvents = true; while (true) { - List lQueue = null; + List lQueue; synchronized (this) { if (closed) { notifyAll(); @@ -117,9 +116,7 @@ public class AutomationResourceBundlesEventQueue<@NonNull E> implements Runnable lQueue = queue; shared = true; } - Iterator events = lQueue.iterator(); - while (events.hasNext()) { - BundleEvent event = events.next(); + for (BundleEvent event : lQueue) { try { processBundleChanged(event); synchronized (this) { diff --git a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/provider/i18n/ModuleTypeI18nServiceImpl.java b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/provider/i18n/ModuleTypeI18nServiceImpl.java index 67ef81b71..d9bc368dd 100644 --- a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/provider/i18n/ModuleTypeI18nServiceImpl.java +++ b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/provider/i18n/ModuleTypeI18nServiceImpl.java @@ -135,7 +135,7 @@ public class ModuleTypeI18nServiceImpl implements ModuleTypeI18nService { @Nullable String llabel, @Nullable String ldescription) { List inputs = moduleTypeI18nUtil.getLocalizedInputs(at.getInputs(), bundle, moduleTypeUID, locale); List outputs = moduleTypeI18nUtil.getLocalizedOutputs(at.getOutputs(), bundle, moduleTypeUID, locale); - ActionType lat = null; + ActionType lat; if (at instanceof CompositeActionType type) { List modules = moduleI18nUtil.getLocalizedModules(type.getChildren(), bundle, moduleTypeUID, ModuleTypeI18nUtil.MODULE_TYPE, locale); @@ -164,7 +164,7 @@ public class ModuleTypeI18nServiceImpl implements ModuleTypeI18nService { @Nullable Locale locale, @Nullable List lconfigDescriptions, @Nullable String llabel, @Nullable String ldescription) { List inputs = moduleTypeI18nUtil.getLocalizedInputs(ct.getInputs(), bundle, moduleTypeUID, locale); - ConditionType lct = null; + ConditionType lct; if (ct instanceof CompositeConditionType type) { List modules = moduleI18nUtil.getLocalizedModules(type.getChildren(), bundle, moduleTypeUID, ModuleTypeI18nUtil.MODULE_TYPE, locale); @@ -193,7 +193,7 @@ public class ModuleTypeI18nServiceImpl implements ModuleTypeI18nService { @Nullable Locale locale, @Nullable List lconfigDescriptions, @Nullable String llabel, @Nullable String ldescription) { List outputs = moduleTypeI18nUtil.getLocalizedOutputs(tt.getOutputs(), bundle, moduleTypeUID, locale); - TriggerType ltt = null; + TriggerType ltt; if (tt instanceof CompositeTriggerType type) { List modules = moduleI18nUtil.getLocalizedModules(type.getChildren(), bundle, moduleTypeUID, ModuleTypeI18nUtil.MODULE_TYPE, locale); diff --git a/bundles/org.openhab.core.config.core/src/main/java/org/openhab/core/config/core/xml/ConfigDescriptionConverter.java b/bundles/org.openhab.core.config.core/src/main/java/org/openhab/core/config/core/xml/ConfigDescriptionConverter.java index 2a726f5aa..ad206c854 100644 --- a/bundles/org.openhab.core.config.core/src/main/java/org/openhab/core/config/core/xml/ConfigDescriptionConverter.java +++ b/bundles/org.openhab.core.config.core/src/main/java/org/openhab/core/config/core/xml/ConfigDescriptionConverter.java @@ -65,7 +65,7 @@ public class ConfigDescriptionConverter extends GenericUnmarshaller attributes = this.attributeMapValidator.readValidatedAttributes(reader); diff --git a/bundles/org.openhab.core.config.core/src/main/java/org/openhab/core/config/core/xml/util/ConverterValueMap.java b/bundles/org.openhab.core.config.core/src/main/java/org/openhab/core/config/core/xml/util/ConverterValueMap.java index d7ced91e2..fa0c69478 100644 --- a/bundles/org.openhab.core.config.core/src/main/java/org/openhab/core/config/core/xml/util/ConverterValueMap.java +++ b/bundles/org.openhab.core.config.core/src/main/java/org/openhab/core/config/core/xml/util/ConverterValueMap.java @@ -62,7 +62,7 @@ public class ConverterValueMap { throws ConversionException { this.reader = reader; this.context = context; - this.valueMap = readValueMap(this.reader, numberOfValues >= -1 ? numberOfValues : -1, this.context); + this.valueMap = readValueMap(this.reader, Math.max(numberOfValues, -1), this.context); } /** diff --git a/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/xml/util/XmlDocumentReaderTest.java b/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/xml/util/XmlDocumentReaderTest.java index 2a84a8eb4..bf15cc4f2 100644 --- a/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/xml/util/XmlDocumentReaderTest.java +++ b/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/xml/util/XmlDocumentReaderTest.java @@ -19,7 +19,6 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import java.io.IOException; import java.net.URI; -import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; @@ -57,7 +56,7 @@ public class XmlDocumentReaderTest { private @Nullable ConfigDescription readXML(String xml) throws IOException { Path tempFile = Files.createTempFile(null, null); tempFile.toFile().deleteOnExit(); - Files.write(tempFile, xml.getBytes(StandardCharsets.UTF_8)); + Files.writeString(tempFile, xml); return new ConfigDescriptionReader().readFromXML(tempFile.toUri().toURL()); } diff --git a/bundles/org.openhab.core.config.discovery.addon.ip/src/main/java/org/openhab/core/config/discovery/addon/ip/IpAddonFinder.java b/bundles/org.openhab.core.config.discovery.addon.ip/src/main/java/org/openhab/core/config/discovery/addon/ip/IpAddonFinder.java index 0719158f1..6cbeca545 100644 --- a/bundles/org.openhab.core.config.discovery.addon.ip/src/main/java/org/openhab/core/config/discovery/addon/ip/IpAddonFinder.java +++ b/bundles/org.openhab.core.config.discovery.addon.ip/src/main/java/org/openhab/core/config/discovery/addon/ip/IpAddonFinder.java @@ -228,7 +228,7 @@ public class IpAddonFinder extends BaseAddonFinder { String type = Objects.toString(parameters.get("type"), ""); String request = Objects.toString(parameters.get(PARAMETER_REQUEST), ""); String response = Objects.toString(matchProperties.get(MATCH_PROPERTY_RESPONSE), ""); - int timeoutMs = 0; + int timeoutMs; try { timeoutMs = Integer.parseInt(Objects.toString(parameters.get(PARAMETER_TIMEOUT_MS))); } catch (NumberFormatException e) { @@ -237,14 +237,14 @@ public class IpAddonFinder extends BaseAddonFinder { continue; } @Nullable - InetAddress destIp = null; + InetAddress destIp; try { destIp = InetAddress.getByName(parameters.get(PARAMETER_DEST_IP)); } catch (UnknownHostException e) { logger.warn("{}: discovery-parameter '{}' cannot be parsed", candidate.getUID(), PARAMETER_DEST_IP); continue; } - int destPort = 0; + int destPort; try { destPort = Integer.parseInt(Objects.toString(parameters.get(PARAMETER_DEST_PORT))); } catch (NumberFormatException e) { diff --git a/bundles/org.openhab.core.config.discovery.usbserial/src/main/java/org/openhab/core/config/discovery/usbserial/UsbSerialDeviceInformation.java b/bundles/org.openhab.core.config.discovery.usbserial/src/main/java/org/openhab/core/config/discovery/usbserial/UsbSerialDeviceInformation.java index 2e596afbc..ba42bd5f0 100644 --- a/bundles/org.openhab.core.config.discovery.usbserial/src/main/java/org/openhab/core/config/discovery/usbserial/UsbSerialDeviceInformation.java +++ b/bundles/org.openhab.core.config.discovery.usbserial/src/main/java/org/openhab/core/config/discovery/usbserial/UsbSerialDeviceInformation.java @@ -50,8 +50,8 @@ public class UsbSerialDeviceInformation { public UsbSerialDeviceInformation(int vendorId, int productId, @Nullable String serialNumber, @Nullable String manufacturer, @Nullable String product, int interfaceNumber, @Nullable String interfaceDescription, String serialPort) { - this.vendorId = requireNonNull(vendorId); - this.productId = requireNonNull(productId); + this.vendorId = vendorId; + this.productId = productId; this.serialNumber = serialNumber; this.manufacturer = manufacturer; diff --git a/bundles/org.openhab.core.config.discovery/src/test/java/org/openhab/core/config/discovery/DiscoveryResultBuilderTest.java b/bundles/org.openhab.core.config.discovery/src/test/java/org/openhab/core/config/discovery/DiscoveryResultBuilderTest.java index 09e9688cd..d76cd230c 100644 --- a/bundles/org.openhab.core.config.discovery/src/test/java/org/openhab/core/config/discovery/DiscoveryResultBuilderTest.java +++ b/bundles/org.openhab.core.config.discovery/src/test/java/org/openhab/core/config/discovery/DiscoveryResultBuilderTest.java @@ -56,6 +56,7 @@ public class DiscoveryResultBuilderTest { discoveryResult = builder.build(); } + @Test public void testInstance() { assertThat(builder, is(instanceOf(DiscoveryResultBuilder.class))); assertThat(builder.withLabel("TEST"), is(instanceOf(DiscoveryResultBuilder.class))); diff --git a/bundles/org.openhab.core.config.dispatch/src/main/java/org/openhab/core/config/dispatch/internal/ConfigDispatcher.java b/bundles/org.openhab.core.config.dispatch/src/main/java/org/openhab/core/config/dispatch/internal/ConfigDispatcher.java index ecc5253fc..6630db57e 100644 --- a/bundles/org.openhab.core.config.dispatch/src/main/java/org/openhab/core/config/dispatch/internal/ConfigDispatcher.java +++ b/bundles/org.openhab.core.config.dispatch/src/main/java/org/openhab/core/config/dispatch/internal/ConfigDispatcher.java @@ -13,7 +13,6 @@ package org.openhab.core.config.dispatch.internal; import java.io.File; -import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; @@ -190,7 +189,7 @@ public class ConfigDispatcher { private void processOrphanExclusivePIDs() { for (String orphanPID : exclusivePIDMap.getOrphanPIDs()) { try { - Configuration configuration = null; + Configuration configuration; if (orphanPID.contains(OpenHAB.SERVICE_CONTEXT_MARKER)) { configuration = getConfigurationWithContext(orphanPID); } else { @@ -276,7 +275,7 @@ public class ConfigDispatcher { } @SuppressWarnings({ "unchecked", "rawtypes" }) - private void internalProcessConfigFile(File configFile) throws IOException, FileNotFoundException { + private void internalProcessConfigFile(File configFile) throws IOException { if (configFile.isDirectory() || !configFile.getName().endsWith(".cfg")) { logger.debug("Ignoring file '{}'", configFile.getName()); return; diff --git a/bundles/org.openhab.core.io.http.auth/src/main/java/org/openhab/core/io/http/auth/internal/AuthorizePageServlet.java b/bundles/org.openhab.core.io.http.auth/src/main/java/org/openhab/core/io/http/auth/internal/AuthorizePageServlet.java index 029a43af6..2aed01a69 100644 --- a/bundles/org.openhab.core.io.http.auth/src/main/java/org/openhab/core/io/http/auth/internal/AuthorizePageServlet.java +++ b/bundles/org.openhab.core.io.http.auth/src/main/java/org/openhab/core/io/http/auth/internal/AuthorizePageServlet.java @@ -77,7 +77,7 @@ public class AuthorizePageServlet extends AbstractAuthPageServlet { Map params = req.getParameterMap(); try { - String message = ""; + String message; String scope = params.containsKey("scope") ? params.get("scope")[0] : ""; String clientId = params.containsKey("client_id") ? params.get("client_id")[0] : ""; diff --git a/bundles/org.openhab.core.io.net/src/main/java/org/openhab/core/io/net/http/PEMTrustManager.java b/bundles/org.openhab.core.io.net/src/main/java/org/openhab/core/io/net/http/PEMTrustManager.java index 2ed77354b..530f682b1 100644 --- a/bundles/org.openhab.core.io.net/src/main/java/org/openhab/core/io/net/http/PEMTrustManager.java +++ b/bundles/org.openhab.core.io.net/src/main/java/org/openhab/core/io/net/http/PEMTrustManager.java @@ -232,7 +232,7 @@ public final class PEMTrustManager extends X509ExtendedTrustManager { File certFile = new File(path); if (certFile.exists()) { try { - return new String(Files.readAllBytes(certFile.toPath()), StandardCharsets.UTF_8); + return Files.readString(certFile.toPath()); } catch (IOException e) { LoggerFactory.getLogger(PEMTrustManager.class).error("An unexpected IOException occurred: ", e); } diff --git a/bundles/org.openhab.core.io.rest.auth/src/main/java/org/openhab/core/io/rest/auth/internal/JwtHelper.java b/bundles/org.openhab.core.io.rest.auth/src/main/java/org/openhab/core/io/rest/auth/internal/JwtHelper.java index 2822ed074..59adec3c3 100644 --- a/bundles/org.openhab.core.io.rest.auth/src/main/java/org/openhab/core/io/rest/auth/internal/JwtHelper.java +++ b/bundles/org.openhab.core.io.rest.auth/src/main/java/org/openhab/core/io/rest/auth/internal/JwtHelper.java @@ -14,7 +14,6 @@ package org.openhab.core.io.rest.auth.internal; import java.io.BufferedReader; import java.io.File; -import java.io.FileNotFoundException; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.nio.file.Files; @@ -72,7 +71,7 @@ public class JwtHelper { } } - private RsaJsonWebKey generateNewKey() throws JoseException, FileNotFoundException, IOException { + private RsaJsonWebKey generateNewKey() throws JoseException, IOException { RsaJsonWebKey newKey = RsaJwkGenerator.generateJwk(2048); File file = new File(KEY_FILE_PATH); @@ -84,7 +83,7 @@ public class JwtHelper { return newKey; } - private RsaJsonWebKey loadOrGenerateKey() throws FileNotFoundException, JoseException, IOException { + private RsaJsonWebKey loadOrGenerateKey() throws JoseException, IOException { try (final BufferedReader reader = Files.newBufferedReader(Paths.get(KEY_FILE_PATH))) { return (RsaJsonWebKey) JsonWebKey.Factory.newJwk(reader.readLine()); } catch (IOException | JoseException e) { diff --git a/bundles/org.openhab.core.io.rest.core/src/main/java/org/openhab/core/io/rest/core/internal/discovery/InboxResource.java b/bundles/org.openhab.core.io.rest.core/src/main/java/org/openhab/core/io/rest/core/internal/discovery/InboxResource.java index e31e61a5c..6c1ef8e52 100644 --- a/bundles/org.openhab.core.io.rest.core/src/main/java/org/openhab/core/io/rest/core/internal/discovery/InboxResource.java +++ b/bundles/org.openhab.core.io.rest.core/src/main/java/org/openhab/core/io/rest/core/internal/discovery/InboxResource.java @@ -116,7 +116,7 @@ public class InboxResource implements RESTResource { ThingUID thingUIDObject = new ThingUID(thingUID); String notEmptyLabel = label != null && !label.isEmpty() ? label : null; String notEmptyNewThingId = newThingId != null && !newThingId.isEmpty() ? newThingId : null; - Thing thing = null; + Thing thing; try { thing = inbox.approve(thingUIDObject, notEmptyLabel, notEmptyNewThingId); } catch (IllegalArgumentException e) { diff --git a/bundles/org.openhab.core.io.rest.mdns/src/main/java/org/openhab/core/io/rest/mdns/internal/MDNSAnnouncer.java b/bundles/org.openhab.core.io.rest.mdns/src/main/java/org/openhab/core/io/rest/mdns/internal/MDNSAnnouncer.java index b3fa731be..47bbfc3d5 100644 --- a/bundles/org.openhab.core.io.rest.mdns/src/main/java/org/openhab/core/io/rest/mdns/internal/MDNSAnnouncer.java +++ b/bundles/org.openhab.core.io.rest.mdns/src/main/java/org/openhab/core/io/rest/mdns/internal/MDNSAnnouncer.java @@ -99,7 +99,7 @@ public class MDNSAnnouncer { private ServiceDescription getSSLServiceDescription() { ServiceDescription description = getDefaultServiceDescription(); description.serviceType = "_" + mdnsName + "-server-ssl._tcp.local."; - description.serviceName = "" + mdnsName + "-ssl"; + description.serviceName = mdnsName + "-ssl"; description.servicePort = httpSSLPort; return description; } diff --git a/bundles/org.openhab.core.io.rest.sitemap/src/main/java/org/openhab/core/io/rest/sitemap/SitemapSubscriptionService.java b/bundles/org.openhab.core.io.rest.sitemap/src/main/java/org/openhab/core/io/rest/sitemap/SitemapSubscriptionService.java index 1e650c1fb..736cd05b6 100644 --- a/bundles/org.openhab.core.io.rest.sitemap/src/main/java/org/openhab/core/io/rest/sitemap/SitemapSubscriptionService.java +++ b/bundles/org.openhab.core.io.rest.sitemap/src/main/java/org/openhab/core/io/rest/sitemap/SitemapSubscriptionService.java @@ -177,7 +177,7 @@ public class SitemapSubscriptionService implements ModelRepositoryChangeListener creationInstants.remove(subscriptionId); callbacks.remove(subscriptionId); String sitemapPage = pageOfSubscription.remove(subscriptionId); - if (sitemapPage != null && !pageOfSubscription.values().contains(sitemapPage)) { + if (sitemapPage != null && !pageOfSubscription.containsValue(sitemapPage)) { // this was the only subscription listening on this page, so we can dispose the listener ListenerRecord listener = pageChangeListeners.remove(sitemapPage); if (listener != null) { diff --git a/bundles/org.openhab.core.io.rest/src/main/java/org/openhab/core/io/rest/internal/filter/ProxyFilter.java b/bundles/org.openhab.core.io.rest/src/main/java/org/openhab/core/io/rest/internal/filter/ProxyFilter.java index 955987619..2284d8407 100644 --- a/bundles/org.openhab.core.io.rest/src/main/java/org/openhab/core/io/rest/internal/filter/ProxyFilter.java +++ b/bundles/org.openhab.core.io.rest/src/main/java/org/openhab/core/io/rest/internal/filter/ProxyFilter.java @@ -94,7 +94,7 @@ public class ProxyFilter implements ContainerRequestFilter { // it String uriString = scheme + "://" + host.trim(); - URI newBaseUri = null; + URI newBaseUri; try { newBaseUri = new URI(uriString); } catch (URISyntaxException e) { diff --git a/bundles/org.openhab.core.io.transport.modbus/src/test/java/org/openhab/core/io/transport/modbus/test/BitUtilitiesExtractIndividualMethodsTest.java b/bundles/org.openhab.core.io.transport.modbus/src/test/java/org/openhab/core/io/transport/modbus/test/BitUtilitiesExtractIndividualMethodsTest.java index 48287b728..d530cf723 100644 --- a/bundles/org.openhab.core.io.transport.modbus/src/test/java/org/openhab/core/io/transport/modbus/test/BitUtilitiesExtractIndividualMethodsTest.java +++ b/bundles/org.openhab.core.io.transport.modbus/src/test/java/org/openhab/core/io/transport/modbus/test/BitUtilitiesExtractIndividualMethodsTest.java @@ -73,9 +73,7 @@ public class BitUtilitiesExtractIndividualMethodsTest { for (int offset = 0; offset < 5; offset++) { int byteIndex = origByteIndex + offset; byte[] bytesOffsetted = new byte[origBytes.length + offset]; - for (int i = 0; i < bytesOffsetted.length; i++) { - bytesOffsetted[i] = 99; - } + Arrays.fill(bytesOffsetted, (byte) 99); System.arraycopy(origBytes, 0, bytesOffsetted, offset, origBytes.length); // offsetted: streamBuilder.add(new Object[] { expectedResult, type, bytesOffsetted, byteIndex }); diff --git a/bundles/org.openhab.core.io.transport.serial.javacomm/src/main/java/org/openhab/core/io/transport/serial/internal/JavaCommPortProvider.java b/bundles/org.openhab.core.io.transport.serial.javacomm/src/main/java/org/openhab/core/io/transport/serial/internal/JavaCommPortProvider.java index cb0b732fd..55b3f393c 100644 --- a/bundles/org.openhab.core.io.transport.serial.javacomm/src/main/java/org/openhab/core/io/transport/serial/internal/JavaCommPortProvider.java +++ b/bundles/org.openhab.core.io.transport.serial.javacomm/src/main/java/org/openhab/core/io/transport/serial/internal/JavaCommPortProvider.java @@ -44,7 +44,7 @@ public class JavaCommPortProvider implements SerialPortProvider { @Override public @Nullable SerialPortIdentifier getPortIdentifier(URI port) { - CommPortIdentifier ident = null; + CommPortIdentifier ident; try { ident = CommPortIdentifier.getPortIdentifier(port.getPath()); } catch (javax.comm.NoSuchPortException e) { diff --git a/bundles/org.openhab.core.io.transport.serial.rxtx/src/main/java/org/openhab/core/io/transport/serial/internal/SerialPortUtil.java b/bundles/org.openhab.core.io.transport.serial.rxtx/src/main/java/org/openhab/core/io/transport/serial/internal/SerialPortUtil.java index f0efdca25..c0d31d8ce 100644 --- a/bundles/org.openhab.core.io.transport.serial.rxtx/src/main/java/org/openhab/core/io/transport/serial/internal/SerialPortUtil.java +++ b/bundles/org.openhab.core.io.transport.serial.rxtx/src/main/java/org/openhab/core/io/transport/serial/internal/SerialPortUtil.java @@ -107,7 +107,7 @@ public class SerialPortUtil { static @Nullable String initSerialPort(String port, @Nullable String serialPortsProperty) { String pathSeparator = File.pathSeparator; - Set serialPorts = null; + Set serialPorts; if (serialPortsProperty != null) { serialPorts = Stream.of(serialPortsProperty.split(pathSeparator)).collect(Collectors.toSet()); } else { diff --git a/bundles/org.openhab.core.io.transport.upnp/src/main/java/org/openhab/core/io/transport/upnp/internal/UpnpIOServiceImpl.java b/bundles/org.openhab.core.io.transport.upnp/src/main/java/org/openhab/core/io/transport/upnp/internal/UpnpIOServiceImpl.java index 54ec9e155..b41771400 100644 --- a/bundles/org.openhab.core.io.transport.upnp/src/main/java/org/openhab/core/io/transport/upnp/internal/UpnpIOServiceImpl.java +++ b/bundles/org.openhab.core.io.transport.upnp/src/main/java/org/openhab/core/io/transport/upnp/internal/UpnpIOServiceImpl.java @@ -385,7 +385,7 @@ public class UpnpIOServiceImpl implements UpnpIOService, RegistryListener { } private Service findService(Device device, String serviceID) { - Service service = null; + Service service; String namespace = device.getType().getNamespace(); if (UDAServiceId.DEFAULT_NAMESPACE.equals(namespace) || UDAServiceId.BROKEN_DEFAULT_NAMESPACE.equals(namespace)) { diff --git a/bundles/org.openhab.core.model.core/src/main/java/org/openhab/core/model/core/internal/ModelRepositoryImpl.java b/bundles/org.openhab.core.model.core/src/main/java/org/openhab/core/model/core/internal/ModelRepositoryImpl.java index d3e420fd5..8c635a10c 100644 --- a/bundles/org.openhab.core.model.core/src/main/java/org/openhab/core/model/core/internal/ModelRepositoryImpl.java +++ b/bundles/org.openhab.core.model.core/src/main/java/org/openhab/core/model/core/internal/ModelRepositoryImpl.java @@ -98,7 +98,7 @@ public class ModelRepositoryImpl implements ModelRepository { public boolean addOrRefreshModel(String name, final InputStream originalInputStream) { logger.info("Loading model '{}'", name); Resource resource = null; - byte[] bytes = null; + byte[] bytes; try (InputStream inputStream = originalInputStream) { bytes = inputStream.readAllBytes(); String validationResult = validateModel(name, new ByteArrayInputStream(bytes)); diff --git a/bundles/org.openhab.core.model.script/src/org/openhab/core/model/script/actions/Voice.java b/bundles/org.openhab.core.model.script/src/org/openhab/core/model/script/actions/Voice.java index c164e8712..30df09855 100644 --- a/bundles/org.openhab.core.model.script/src/org/openhab/core/model/script/actions/Voice.java +++ b/bundles/org.openhab.core.model.script/src/org/openhab/core/model/script/actions/Voice.java @@ -323,7 +323,7 @@ public class Voice { } if (locale != null) { String[] split = locale.split("-"); - Locale loc = null; + Locale loc; if (split.length == 2) { loc = new Locale(split[0], split[1]); } else { @@ -450,7 +450,7 @@ public class Voice { dialogContextBuilder.withListeningItem(listeningItem); } if (locale != null) { - Locale loc = null; + Locale loc; String[] split = locale.split("-"); if (split.length == 2) { loc = new Locale(split[0], split[1]); 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 b9a4cee66..e8619c540 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 @@ -178,7 +178,7 @@ public class NumberExtensions { if (type instanceof QuantityType qtype && x instanceof QuantityType qx) { return operator_equals(qtype, qx); } - if (type != null && type instanceof DecimalType decimalType && x != null) { + if (type instanceof DecimalType decimalType && x != null) { return decimalType.toBigDecimal().compareTo(numberToBigDecimal(x)) == 0; } else { return type == x; // both might be null, then we should return true @@ -189,7 +189,7 @@ public class NumberExtensions { if (type instanceof QuantityType qtype && x instanceof QuantityType qx) { return operator_notEquals(qtype, qx); } - if (type != null && type instanceof DecimalType decimalType && x != null) { + if (type instanceof DecimalType decimalType && x != null) { return decimalType.toBigDecimal().compareTo(numberToBigDecimal(x)) != 0; } else { return type != x; // both might be null, then we should return @@ -201,7 +201,7 @@ public class NumberExtensions { if (type instanceof QuantityType qtype && x instanceof QuantityType qx) { return operator_greaterThan(qtype, qx); } - if (type != null && type instanceof DecimalType decimalType && x != null) { + if (type instanceof DecimalType decimalType && x != null) { return decimalType.toBigDecimal().compareTo(numberToBigDecimal(x)) > 0; } else { return false; @@ -212,7 +212,7 @@ public class NumberExtensions { if (type instanceof QuantityType qtype && x instanceof QuantityType qx) { return operator_greaterEqualsThan(qtype, qx); } - if (type != null && type instanceof DecimalType decimalType && x != null) { + if (type instanceof DecimalType decimalType && x != null) { return decimalType.toBigDecimal().compareTo(numberToBigDecimal(x)) >= 0; } else { return false; @@ -223,7 +223,7 @@ public class NumberExtensions { if (type instanceof QuantityType qtype && x instanceof QuantityType qx) { return operator_lessThan(qtype, qx); } - if (type != null && type instanceof DecimalType decimalType && x != null) { + if (type instanceof DecimalType decimalType && x != null) { return decimalType.toBigDecimal().compareTo(numberToBigDecimal(x)) < 0; } else { return false; @@ -234,7 +234,7 @@ public class NumberExtensions { if (type instanceof QuantityType qtype && x instanceof QuantityType qx) { return operator_lessEqualsThan(qtype, qx); } - if (type != null && type instanceof DecimalType decimalType && x != null) { + if (type instanceof DecimalType decimalType && x != null) { return decimalType.toBigDecimal().compareTo(numberToBigDecimal(x)) <= 0; } else { return false; diff --git a/bundles/org.openhab.core.model.thing/src/org/openhab/core/model/thing/internal/GenericItemChannelLinkProvider.java b/bundles/org.openhab.core.model.thing/src/org/openhab/core/model/thing/internal/GenericItemChannelLinkProvider.java index 80517a38e..66cea3a5f 100644 --- a/bundles/org.openhab.core.model.thing/src/org/openhab/core/model/thing/internal/GenericItemChannelLinkProvider.java +++ b/bundles/org.openhab.core.model.thing/src/org/openhab/core/model/thing/internal/GenericItemChannelLinkProvider.java @@ -80,7 +80,7 @@ public class GenericItemChannelLinkProvider extends AbstractProvider[] getChannelTypeReferenceObjects(NodeIterator nodeIterator) throws ConversionException { - List channelTypeReferences = null; List channelGroupTypeReferences = null; - - channelTypeReferences = (List) nodeIterator.nextList("channels", false); + List channelTypeReferences = (List) nodeIterator.nextList("channels", + false); if (channelTypeReferences == null) { channelGroupTypeReferences = (List) nodeIterator.nextList("channel-groups", false); } diff --git a/bundles/org.openhab.core.ui.icon/src/test/java/org/openhab/core/ui/icon/internal/IconServletTest.java b/bundles/org.openhab.core.ui.icon/src/test/java/org/openhab/core/ui/icon/internal/IconServletTest.java index a110925fd..ff623ec02 100644 --- a/bundles/org.openhab.core.ui.icon/src/test/java/org/openhab/core/ui/icon/internal/IconServletTest.java +++ b/bundles/org.openhab.core.ui.icon/src/test/java/org/openhab/core/ui/icon/internal/IconServletTest.java @@ -66,7 +66,7 @@ public class IconServletTest { } public String getOutput() { - return new String(outputStream.toByteArray()); + return outputStream.toString(); } public void reset() { diff --git a/bundles/org.openhab.core.ui/src/main/java/org/openhab/core/ui/internal/proxy/BlockingProxyServlet.java b/bundles/org.openhab.core.ui/src/main/java/org/openhab/core/ui/internal/proxy/BlockingProxyServlet.java index 726ec99af..32504e035 100644 --- a/bundles/org.openhab.core.ui/src/main/java/org/openhab/core/ui/internal/proxy/BlockingProxyServlet.java +++ b/bundles/org.openhab.core.ui/src/main/java/org/openhab/core/ui/internal/proxy/BlockingProxyServlet.java @@ -15,7 +15,6 @@ package org.openhab.core.ui.internal.proxy; import java.io.IOException; import java.io.InputStream; import java.net.URI; -import java.util.Iterator; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; @@ -29,7 +28,6 @@ import org.eclipse.jetty.client.api.Request; import org.eclipse.jetty.client.api.Response; import org.eclipse.jetty.client.util.InputStreamResponseListener; import org.eclipse.jetty.http.HttpField; -import org.eclipse.jetty.http.HttpFields; import org.eclipse.jetty.util.ssl.SslContextFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -91,13 +89,8 @@ public class BlockingProxyServlet extends HttpServlet { // wait for the response headers to arrive or the timeout to expire Response httpResponse = listener.get(TIMEOUT, TimeUnit.MILLISECONDS); - // get response headers - HttpFields headers = httpResponse.getHeaders(); - Iterator iterator = headers.iterator(); - - // copy all headers - while (iterator.hasNext()) { - HttpField header = iterator.next(); + // copy all response headers + for (HttpField header : httpResponse.getHeaders()) { response.setHeader(header.getName(), header.getValue()); } } catch (TimeoutException e) { diff --git a/bundles/org.openhab.core.ui/src/main/java/org/openhab/core/ui/internal/proxy/ProxyServletService.java b/bundles/org.openhab.core.ui/src/main/java/org/openhab/core/ui/internal/proxy/ProxyServletService.java index cbe0469e3..af1ca4ff0 100644 --- a/bundles/org.openhab.core.ui/src/main/java/org/openhab/core/ui/internal/proxy/ProxyServletService.java +++ b/bundles/org.openhab.core.ui/src/main/java/org/openhab/core/ui/internal/proxy/ProxyServletService.java @@ -243,7 +243,7 @@ public class ProxyServletService extends HttpServlet { String.format("Widget '%s' could not be found!", widgetId)); } - String uriString = null; + String uriString; if (widget instanceof Image image) { uriString = image.getUrl(); } else if (widget instanceof Video video) { diff --git a/bundles/org.openhab.core.ui/src/test/java/org/openhab/core/ui/internal/items/ItemUIRegistryImplTest.java b/bundles/org.openhab.core.ui/src/test/java/org/openhab/core/ui/internal/items/ItemUIRegistryImplTest.java index 7a916ed8f..15336254a 100644 --- a/bundles/org.openhab.core.ui/src/test/java/org/openhab/core/ui/internal/items/ItemUIRegistryImplTest.java +++ b/bundles/org.openhab.core.ui/src/test/java/org/openhab/core/ui/internal/items/ItemUIRegistryImplTest.java @@ -241,7 +241,7 @@ public class ItemUIRegistryImplTest { String testLabel = "Label [%.3f " + UnitUtils.UNIT_PLACEHOLDER + "]"; when(widgetMock.getLabel()).thenReturn(testLabel); - when(itemMock.getState()).thenReturn(new QuantityType<>("" + 10f / 3f + " °C")); + when(itemMock.getState()).thenReturn(new QuantityType<>(10f / 3f + " °C")); String label = uiRegistry.getLabel(widgetMock); assertEquals("Label [3" + SEP + "333 °C]", label); } @@ -261,7 +261,7 @@ public class ItemUIRegistryImplTest { String testLabel = "Label [%.0f " + UnitUtils.UNIT_PLACEHOLDER + "]"; when(widgetMock.getLabel()).thenReturn(testLabel); - when(itemMock.getState()).thenReturn(new QuantityType<>("" + 10f / 3f + " °C")); + when(itemMock.getState()).thenReturn(new QuantityType<>(10f / 3f + " °C")); String label = uiRegistry.getLabel(widgetMock); assertEquals("Label [3 °C]", label); } @@ -271,7 +271,7 @@ public class ItemUIRegistryImplTest { String testLabel = "Label [%d %%]"; when(widgetMock.getLabel()).thenReturn(testLabel); - when(itemMock.getState()).thenReturn(new QuantityType<>("" + 10f / 3f + " %")); + when(itemMock.getState()).thenReturn(new QuantityType<>(10f / 3f + " %")); String label = uiRegistry.getLabel(widgetMock); assertEquals("Label [3 %]", label); } @@ -281,7 +281,7 @@ public class ItemUIRegistryImplTest { String testLabel = "Label [%.0f %%]"; when(widgetMock.getLabel()).thenReturn(testLabel); - when(itemMock.getState()).thenReturn(new QuantityType<>("" + 10f / 3f + " %")); + when(itemMock.getState()).thenReturn(new QuantityType<>(10f / 3f + " %")); String label = uiRegistry.getLabel(widgetMock); assertEquals("Label [3 %]", label); } @@ -301,7 +301,7 @@ public class ItemUIRegistryImplTest { String testLabel = "Label [%d " + UnitUtils.UNIT_PLACEHOLDER + "]"; when(widgetMock.getLabel()).thenReturn(testLabel); - when(itemMock.getState()).thenReturn(new QuantityType<>("" + 10f / 3f + " %")); + when(itemMock.getState()).thenReturn(new QuantityType<>(10f / 3f + " %")); String label = uiRegistry.getLabel(widgetMock); assertEquals("Label [3 %]", label); } @@ -311,7 +311,7 @@ public class ItemUIRegistryImplTest { String testLabel = "Label [%.0f " + UnitUtils.UNIT_PLACEHOLDER + "]"; when(widgetMock.getLabel()).thenReturn(testLabel); - when(itemMock.getState()).thenReturn(new QuantityType<>("" + 10f / 3f + " %")); + when(itemMock.getState()).thenReturn(new QuantityType<>(10f / 3f + " %")); String label = uiRegistry.getLabel(widgetMock); assertEquals("Label [3 %]", label); } @@ -743,11 +743,11 @@ public class ItemUIRegistryImplTest { when(widgetMock.getLabel()).thenReturn(testLabel); - Condition conditon = mock(Condition.class); - when(conditon.getState()).thenReturn("21"); - when(conditon.getCondition()).thenReturn("<"); + Condition condition = mock(Condition.class); + when(condition.getState()).thenReturn("21"); + when(condition.getCondition()).thenReturn("<"); BasicEList conditions = new BasicEList<>(); - conditions.add(conditon); + conditions.add(condition); ColorArray rule = mock(ColorArray.class); when(rule.getConditions()).thenReturn(conditions); when(rule.getArg()).thenReturn("yellow"); @@ -772,11 +772,11 @@ public class ItemUIRegistryImplTest { when(widgetMock.getLabel()).thenReturn(testLabel); - Condition conditon = mock(Condition.class); - when(conditon.getState()).thenReturn("20"); - when(conditon.getCondition()).thenReturn("=="); + Condition condition = mock(Condition.class); + when(condition.getState()).thenReturn("20"); + when(condition.getCondition()).thenReturn("=="); BasicEList conditions = new BasicEList<>(); - conditions.add(conditon); + conditions.add(condition); ColorArray rule = mock(ColorArray.class); when(rule.getConditions()).thenReturn(conditions); when(rule.getArg()).thenReturn("yellow"); @@ -950,29 +950,29 @@ public class ItemUIRegistryImplTest { when(widgetMock.getLabel()).thenReturn(testLabel); - Condition conditon = mock(Condition.class); - when(conditon.getState()).thenReturn("18"); - when(conditon.getCondition()).thenReturn(">="); - Condition conditon2 = mock(Condition.class); - when(conditon2.getState()).thenReturn("21"); - when(conditon2.getCondition()).thenReturn("<"); + Condition condition = mock(Condition.class); + when(condition.getState()).thenReturn("18"); + when(condition.getCondition()).thenReturn(">="); + Condition condition2 = mock(Condition.class); + when(condition2.getState()).thenReturn("21"); + when(condition2.getCondition()).thenReturn("<"); BasicEList conditions = new BasicEList<>(); - conditions.add(conditon); - conditions.add(conditon2); + conditions.add(condition); + conditions.add(condition2); ColorArray rule = mock(ColorArray.class); when(rule.getConditions()).thenReturn(conditions); when(rule.getArg()).thenReturn("yellow"); BasicEList rules = new BasicEList<>(); rules.add(rule); - Condition conditon3 = mock(Condition.class); - when(conditon3.getState()).thenReturn("21"); - when(conditon3.getCondition()).thenReturn(">="); - Condition conditon4 = mock(Condition.class); - when(conditon4.getState()).thenReturn("24"); - when(conditon4.getCondition()).thenReturn("<"); + Condition condition3 = mock(Condition.class); + when(condition3.getState()).thenReturn("21"); + when(condition3.getCondition()).thenReturn(">="); + Condition condition4 = mock(Condition.class); + when(condition4.getState()).thenReturn("24"); + when(condition4.getCondition()).thenReturn("<"); BasicEList conditions2 = new BasicEList<>(); - conditions2.add(conditon3); - conditions2.add(conditon4); + conditions2.add(condition3); + conditions2.add(condition4); ColorArray rule2 = mock(ColorArray.class); when(rule2.getConditions()).thenReturn(conditions2); when(rule2.getArg()).thenReturn("red"); @@ -1004,8 +1004,6 @@ public class ItemUIRegistryImplTest { color = uiRegistry.getLabelColor(widgetMock); assertEquals("blue", color); - conditions5 = null; - when(itemMock.getState()).thenReturn(new DecimalType(24.0)); color = uiRegistry.getLabelColor(widgetMock); @@ -1019,29 +1017,29 @@ public class ItemUIRegistryImplTest { @Test public void getValueColor() { - Condition conditon = mock(Condition.class); - when(conditon.getState()).thenReturn("18"); - when(conditon.getCondition()).thenReturn(">="); - Condition conditon2 = mock(Condition.class); - when(conditon2.getState()).thenReturn("21"); - when(conditon2.getCondition()).thenReturn("<"); + Condition condition = mock(Condition.class); + when(condition.getState()).thenReturn("18"); + when(condition.getCondition()).thenReturn(">="); + Condition condition2 = mock(Condition.class); + when(condition2.getState()).thenReturn("21"); + when(condition2.getCondition()).thenReturn("<"); BasicEList conditions = new BasicEList<>(); - conditions.add(conditon); - conditions.add(conditon2); + conditions.add(condition); + conditions.add(condition2); ColorArray rule = mock(ColorArray.class); when(rule.getConditions()).thenReturn(conditions); when(rule.getArg()).thenReturn("yellow"); BasicEList rules = new BasicEList<>(); rules.add(rule); - Condition conditon3 = mock(Condition.class); - when(conditon3.getState()).thenReturn("21"); - when(conditon3.getCondition()).thenReturn(">="); - Condition conditon4 = mock(Condition.class); - when(conditon4.getState()).thenReturn("24"); - when(conditon4.getCondition()).thenReturn("<"); + Condition condition3 = mock(Condition.class); + when(condition3.getState()).thenReturn("21"); + when(condition3.getCondition()).thenReturn(">="); + Condition condition4 = mock(Condition.class); + when(condition4.getState()).thenReturn("24"); + when(condition4.getCondition()).thenReturn("<"); BasicEList conditions2 = new BasicEList<>(); - conditions2.add(conditon3); - conditions2.add(conditon4); + conditions2.add(condition3); + conditions2.add(condition4); ColorArray rule2 = mock(ColorArray.class); when(rule2.getConditions()).thenReturn(conditions2); when(rule2.getArg()).thenReturn("red"); @@ -1073,8 +1071,6 @@ public class ItemUIRegistryImplTest { color = uiRegistry.getValueColor(widgetMock); assertEquals("blue", color); - conditions5 = null; - when(itemMock.getState()).thenReturn(new DecimalType(24.0)); color = uiRegistry.getValueColor(widgetMock); @@ -1088,29 +1084,29 @@ public class ItemUIRegistryImplTest { @Test public void getIconColor() { - Condition conditon = mock(Condition.class); - when(conditon.getState()).thenReturn("18"); - when(conditon.getCondition()).thenReturn(">="); - Condition conditon2 = mock(Condition.class); - when(conditon2.getState()).thenReturn("21"); - when(conditon2.getCondition()).thenReturn("<"); + Condition condition = mock(Condition.class); + when(condition.getState()).thenReturn("18"); + when(condition.getCondition()).thenReturn(">="); + Condition condition2 = mock(Condition.class); + when(condition2.getState()).thenReturn("21"); + when(condition2.getCondition()).thenReturn("<"); BasicEList conditions = new BasicEList<>(); - conditions.add(conditon); - conditions.add(conditon2); + conditions.add(condition); + conditions.add(condition2); ColorArray rule = mock(ColorArray.class); when(rule.getConditions()).thenReturn(conditions); when(rule.getArg()).thenReturn("yellow"); BasicEList rules = new BasicEList<>(); rules.add(rule); - Condition conditon3 = mock(Condition.class); - when(conditon3.getState()).thenReturn("21"); - when(conditon3.getCondition()).thenReturn(">="); - Condition conditon4 = mock(Condition.class); - when(conditon4.getState()).thenReturn("24"); - when(conditon4.getCondition()).thenReturn("<"); + Condition condition3 = mock(Condition.class); + when(condition3.getState()).thenReturn("21"); + when(condition3.getCondition()).thenReturn(">="); + Condition condition4 = mock(Condition.class); + when(condition4.getState()).thenReturn("24"); + when(condition4.getCondition()).thenReturn("<"); BasicEList conditions2 = new BasicEList<>(); - conditions2.add(conditon3); - conditions2.add(conditon4); + conditions2.add(condition3); + conditions2.add(condition4); ColorArray rule2 = mock(ColorArray.class); when(rule2.getConditions()).thenReturn(conditions2); when(rule2.getArg()).thenReturn("red"); @@ -1142,8 +1138,6 @@ public class ItemUIRegistryImplTest { color = uiRegistry.getIconColor(widgetMock); assertEquals("blue", color); - conditions5 = null; - when(itemMock.getState()).thenReturn(new DecimalType(24.0)); color = uiRegistry.getIconColor(widgetMock); @@ -1157,15 +1151,15 @@ public class ItemUIRegistryImplTest { @Test public void getVisibility() { - Condition conditon = mock(Condition.class); - when(conditon.getState()).thenReturn("21"); - when(conditon.getCondition()).thenReturn(">="); - Condition conditon2 = mock(Condition.class); - when(conditon2.getState()).thenReturn("24"); - when(conditon2.getCondition()).thenReturn("<"); + Condition condition = mock(Condition.class); + when(condition.getState()).thenReturn("21"); + when(condition.getCondition()).thenReturn(">="); + Condition condition2 = mock(Condition.class); + when(condition2.getState()).thenReturn("24"); + when(condition2.getCondition()).thenReturn("<"); BasicEList conditions = new BasicEList<>(); - conditions.add(conditon); - conditions.add(conditon2); + conditions.add(condition); + conditions.add(condition2); VisibilityRule rule = mock(VisibilityRule.class); when(rule.getConditions()).thenReturn(conditions); BasicEList rules = new BasicEList<>(); @@ -1211,15 +1205,15 @@ public class ItemUIRegistryImplTest { when(widgetMock.eClass()).thenReturn(textEClass); when(widgetMock.getIcon()).thenReturn(null); when(widgetMock.getStaticIcon()).thenReturn(null); - Condition conditon = mock(Condition.class); - when(conditon.getState()).thenReturn("21"); - when(conditon.getCondition()).thenReturn(">="); - Condition conditon2 = mock(Condition.class); - when(conditon2.getState()).thenReturn("24"); - when(conditon2.getCondition()).thenReturn("<"); + Condition condition = mock(Condition.class); + when(condition.getState()).thenReturn("21"); + when(condition.getCondition()).thenReturn(">="); + Condition condition2 = mock(Condition.class); + when(condition2.getState()).thenReturn("24"); + when(condition2.getCondition()).thenReturn("<"); BasicEList conditions = new BasicEList<>(); - conditions.add(conditon); - conditions.add(conditon2); + conditions.add(condition); + conditions.add(condition2); IconRule rule = mock(IconRule.class); when(rule.getConditions()).thenReturn(conditions); when(rule.getArg()).thenReturn("temperature"); diff --git a/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/text/AbstractRuleBasedInterpreter.java b/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/text/AbstractRuleBasedInterpreter.java index bac8331c3..f70ce53c7 100644 --- a/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/text/AbstractRuleBasedInterpreter.java +++ b/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/text/AbstractRuleBasedInterpreter.java @@ -856,7 +856,7 @@ public abstract class AbstractRuleBasedInterpreter implements HumanLanguageInter if (!isForced && newState.equals(oldState)) { String template = language.getString(STATE_ALREADY_SINGULAR); String cmdName = "state_" + command.toString().toLowerCase(); - String stateText = null; + String stateText; try { stateText = language.getString(cmdName); } catch (Exception e) { diff --git a/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/text/TokenList.java b/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/text/TokenList.java index ba71132be..c7eb98c84 100644 --- a/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/text/TokenList.java +++ b/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/text/TokenList.java @@ -21,10 +21,10 @@ import java.util.List; */ public class TokenList { - private List list = null; + private List list; - private int head = 0; - private int tail = 0; + private int head; + private int tail; /** * Constructs a new instance. diff --git a/bundles/org.openhab.core/src/main/java/org/openhab/core/internal/items/ItemUpdater.java b/bundles/org.openhab.core/src/main/java/org/openhab/core/internal/items/ItemUpdater.java index c14719711..f31bd9a32 100644 --- a/bundles/org.openhab.core/src/main/java/org/openhab/core/internal/items/ItemUpdater.java +++ b/bundles/org.openhab.core/src/main/java/org/openhab/core/internal/items/ItemUpdater.java @@ -71,7 +71,7 @@ public class ItemUpdater extends AbstractItemEventSubscriber { } catch (ReflectiveOperationException e) { // Should never happen logger.warn("{} while creating {} instance: {}", e.getClass().getSimpleName(), - state.getClass().getSimpleName(), e.getMessage()); + state.getSimpleName(), e.getMessage()); } } } diff --git a/bundles/org.openhab.core/src/main/java/org/openhab/core/internal/types/StateDescriptionFragmentImpl.java b/bundles/org.openhab.core/src/main/java/org/openhab/core/internal/types/StateDescriptionFragmentImpl.java index f713b7a7f..e719f799e 100644 --- a/bundles/org.openhab.core/src/main/java/org/openhab/core/internal/types/StateDescriptionFragmentImpl.java +++ b/bundles/org.openhab.core/src/main/java/org/openhab/core/internal/types/StateDescriptionFragmentImpl.java @@ -15,6 +15,7 @@ package org.openhab.core.internal.types; import java.math.BigDecimal; import java.util.Collections; import java.util.List; +import java.util.Objects; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; @@ -226,12 +227,9 @@ public class StateDescriptionFragmentImpl implements StateDescriptionFragment { return false; } StateDescriptionFragmentImpl other = (StateDescriptionFragmentImpl) obj; - return (minimum != null ? minimum.equals(other.minimum) : other.minimum == null) - && (maximum != null ? maximum.equals(other.maximum) : other.maximum == null) - && (step != null ? step.equals(other.step) : other.step == null) - && (pattern != null ? pattern.equals(other.pattern) : other.pattern == null) - && (readOnly != null ? readOnly.equals(other.readOnly) : other.readOnly == null) - && (options != null ? options.equals(other.options) : other.options == null); + return Objects.equals(minimum, other.minimum) && Objects.equals(maximum, other.maximum) + && Objects.equals(step, other.step) && Objects.equals(pattern, other.pattern) + && Objects.equals(readOnly, other.readOnly) && Objects.equals(options, other.options); } @Override diff --git a/bundles/org.openhab.core/src/main/java/org/openhab/core/items/ManagedItemProvider.java b/bundles/org.openhab.core/src/main/java/org/openhab/core/items/ManagedItemProvider.java index df38a4148..f1f6685b3 100644 --- a/bundles/org.openhab.core/src/main/java/org/openhab/core/items/ManagedItemProvider.java +++ b/bundles/org.openhab.core/src/main/java/org/openhab/core/items/ManagedItemProvider.java @@ -186,7 +186,7 @@ public class ManagedItemProvider extends AbstractManagedProvider T parseType(String typeName, String valueToParse, Class desiredClass) { - Object parsedObject = null; + Object parsedObject; String simpleClassName = typeName + TYPE_POSTFIX; parsedObject = parseSimpleClassName(simpleClassName, valueToParse); diff --git a/bundles/org.openhab.core/src/main/java/org/openhab/core/library/types/DateTimeType.java b/bundles/org.openhab.core/src/main/java/org/openhab/core/library/types/DateTimeType.java index 932d8faf5..848a28478 100644 --- a/bundles/org.openhab.core/src/main/java/org/openhab/core/library/types/DateTimeType.java +++ b/bundles/org.openhab.core/src/main/java/org/openhab/core/library/types/DateTimeType.java @@ -77,7 +77,7 @@ public class DateTimeType implements PrimitiveType, State, Command { } public DateTimeType(String zonedValue) { - ZonedDateTime date = null; + ZonedDateTime date; try { // direct parsing (date and time) try { @@ -228,7 +228,7 @@ public class DateTimeType implements PrimitiveType, State, Command { } private ZonedDateTime parse(String value) throws DateTimeParseException { - ZonedDateTime date = null; + ZonedDateTime date; try { date = ZonedDateTime.parse(value, PARSER_TZ_RFC); } catch (DateTimeParseException tzMsRfcException) { diff --git a/bundles/org.openhab.core/src/main/java/org/openhab/core/library/types/PointType.java b/bundles/org.openhab.core/src/main/java/org/openhab/core/library/types/PointType.java index b34cafc29..4a7c0d3c8 100644 --- a/bundles/org.openhab.core/src/main/java/org/openhab/core/library/types/PointType.java +++ b/bundles/org.openhab.core/src/main/java/org/openhab/core/library/types/PointType.java @@ -223,15 +223,15 @@ public class PointType implements ComplexType, Command, State { private void canonicalize(DecimalType aLat, DecimalType aLon) { latitude = FLAT.add(aLat.toBigDecimal()).remainder(CIRCLE); longitude = aLon.toBigDecimal(); - if (latitude.compareTo(BigDecimal.ZERO) == -1) { + if (latitude.compareTo(BigDecimal.ZERO) < 0) { latitude = latitude.add(CIRCLE); } latitude = latitude.subtract(FLAT); - if (latitude.compareTo(RIGHT) == 1) { + if (latitude.compareTo(RIGHT) > 0) { latitude = FLAT.subtract(latitude); longitude = longitude.add(FLAT); - } else if (latitude.compareTo(RIGHT.negate()) == -1) { + } else if (latitude.compareTo(RIGHT.negate()) < 0) { latitude = FLAT.negate().subtract(latitude); longitude = longitude.add(FLAT); } diff --git a/bundles/org.openhab.core/src/main/java/org/openhab/core/net/HttpServiceUtil.java b/bundles/org.openhab.core/src/main/java/org/openhab/core/net/HttpServiceUtil.java index 743c21fa2..e656f54c6 100644 --- a/bundles/org.openhab.core/src/main/java/org/openhab/core/net/HttpServiceUtil.java +++ b/bundles/org.openhab.core/src/main/java/org/openhab/core/net/HttpServiceUtil.java @@ -76,7 +76,7 @@ public class HttpServiceUtil { } value = ref.getProperty(Constants.SERVICE_RANKING); final int serviceRanking; - if (value == null || !(value instanceof Integer)) { + if (!(value instanceof Integer)) { serviceRanking = 0; } else { serviceRanking = (Integer) value; diff --git a/bundles/org.openhab.core/src/main/java/org/openhab/core/types/CommandOption.java b/bundles/org.openhab.core/src/main/java/org/openhab/core/types/CommandOption.java index 642f9e404..6df1f29d8 100644 --- a/bundles/org.openhab.core/src/main/java/org/openhab/core/types/CommandOption.java +++ b/bundles/org.openhab.core/src/main/java/org/openhab/core/types/CommandOption.java @@ -12,6 +12,8 @@ */ package org.openhab.core.types; +import java.util.Objects; + import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; @@ -84,7 +86,7 @@ public class CommandOption { return false; } CommandOption other = (CommandOption) obj; - return command.equals(other.command) && (label != null ? label.equals(other.label) : other.label == null); + return command.equals(other.command) && Objects.equals(label, other.label); } @Override diff --git a/bundles/org.openhab.core/src/main/java/org/openhab/core/types/StateDescription.java b/bundles/org.openhab.core/src/main/java/org/openhab/core/types/StateDescription.java index f532f7e65..e946abde7 100644 --- a/bundles/org.openhab.core/src/main/java/org/openhab/core/types/StateDescription.java +++ b/bundles/org.openhab.core/src/main/java/org/openhab/core/types/StateDescription.java @@ -15,6 +15,7 @@ package org.openhab.core.types; import java.math.BigDecimal; import java.util.Collections; import java.util.List; +import java.util.Objects; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; @@ -136,10 +137,8 @@ public class StateDescription { return false; } StateDescription other = (StateDescription) obj; - return (minimum != null ? minimum.equals(other.minimum) : other.minimum == null) - && (maximum != null ? maximum.equals(other.maximum) : other.maximum == null) - && (step != null ? step.equals(other.step) : other.step == null) - && (pattern != null ? pattern.equals(other.pattern) : other.pattern == null) + return Objects.equals(minimum, other.minimum) && Objects.equals(maximum, other.maximum) + && Objects.equals(step, other.step) && Objects.equals(pattern, other.pattern) && readOnly == other.readOnly // && options.equals(other.options); } diff --git a/bundles/org.openhab.core/src/main/java/org/openhab/core/types/StateOption.java b/bundles/org.openhab.core/src/main/java/org/openhab/core/types/StateOption.java index ea2422fd5..a79dd769a 100644 --- a/bundles/org.openhab.core/src/main/java/org/openhab/core/types/StateOption.java +++ b/bundles/org.openhab.core/src/main/java/org/openhab/core/types/StateOption.java @@ -12,6 +12,8 @@ */ package org.openhab.core.types; +import java.util.Objects; + import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; @@ -76,7 +78,7 @@ public final class StateOption { return false; } StateOption other = (StateOption) obj; - return value.equals(other.value) && (label != null ? label.equals(other.label) : other.label == null); + return value.equals(other.value) && Objects.equals(label, other.label); } @Override diff --git a/bundles/org.openhab.core/src/main/java/org/openhab/core/util/ColorUtil.java b/bundles/org.openhab.core/src/main/java/org/openhab/core/util/ColorUtil.java index c28d96314..aad1e57cb 100644 --- a/bundles/org.openhab.core/src/main/java/org/openhab/core/util/ColorUtil.java +++ b/bundles/org.openhab.core/src/main/java/org/openhab/core/util/ColorUtil.java @@ -105,9 +105,9 @@ public class ColorUtil { * @return array of three {@link PercentType} with the RGB values in the range 0 to 100 percent. */ public static PercentType[] hsbToRgbPercent(HSBType hsb) { - PercentType red = null; - PercentType green = null; - PercentType blue = null; + PercentType red; + PercentType green; + PercentType blue; final BigDecimal h = hsb.getHue().toBigDecimal().divide(BIG_DECIMAL_100, 10, RoundingMode.HALF_UP); final BigDecimal s = hsb.getSaturation().toBigDecimal().divide(BIG_DECIMAL_100); diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/cache/lru/LRUMediaCacheEntryTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/cache/lru/LRUMediaCacheEntryTest.java index aade45cec..793b8fad3 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/cache/lru/LRUMediaCacheEntryTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/cache/lru/LRUMediaCacheEntryTest.java @@ -164,7 +164,7 @@ public class LRUMediaCacheEntryTest { assertTrue(fakeStream.isClosed()); // all client closed, the main stream should also be closed assertArrayEquals(new byte[] { 5, 6, 7, 8 }, byteReadFromStream1); - assertArrayEquals(new byte[] { 5, 6, 7, 8 }, byteReadFromStream1); + assertArrayEquals(new byte[] { 5, 6, 7, 8 }, byteReadFromStream2); // we call the TTS service only once verify(supplier, times(1)).get(); diff --git a/itests/org.openhab.core.automation.integration.tests/src/main/java/org/openhab/core/automation/integration/test/AutomationIntegrationTest.java b/itests/org.openhab.core.automation.integration.tests/src/main/java/org/openhab/core/automation/integration/test/AutomationIntegrationTest.java index 46b3cf27f..aa8a8d595 100644 --- a/itests/org.openhab.core.automation.integration.tests/src/main/java/org/openhab/core/automation/integration/test/AutomationIntegrationTest.java +++ b/itests/org.openhab.core.automation.integration.tests/src/main/java/org/openhab/core/automation/integration/test/AutomationIntegrationTest.java @@ -665,7 +665,7 @@ public class AutomationIntegrationTest extends JavaOSGiTest { TemplateRegistry templateRegistry = getService(TemplateRegistry.class); assertThat(templateRegistry, is(notNullValue())); waitForAssert(() -> { - Template template = null; + Template template; template = templateRegistry.get("SimpleTestTemplate"); assertThat(template, is(notNullValue())); assertThat(template.getTags(), is(notNullValue())); @@ -713,7 +713,7 @@ public class AutomationIntegrationTest extends JavaOSGiTest { TemplateRegistry templateRegistry = getService(TemplateRegistry.class); assertThat(templateRegistry, is(notNullValue())); waitForAssert(() -> { - Template template = null; + Template template; template = templateRegistry.get("TestTemplateWithCompositeModules"); assertThat(template, is(notNullValue())); assertThat(template.getTags(), is(notNullValue())); diff --git a/itests/org.openhab.core.automation.module.script.tests/src/main/java/org/openhab/core/automation/module/script/internal/defaultscope/ScriptRuleOSGiTest.java b/itests/org.openhab.core.automation.module.script.tests/src/main/java/org/openhab/core/automation/module/script/internal/defaultscope/ScriptRuleOSGiTest.java index 4c5629f7d..41dd3cc73 100644 --- a/itests/org.openhab.core.automation.module.script.tests/src/main/java/org/openhab/core/automation/module/script/internal/defaultscope/ScriptRuleOSGiTest.java +++ b/itests/org.openhab.core.automation.module.script.tests/src/main/java/org/openhab/core/automation/module/script/internal/defaultscope/ScriptRuleOSGiTest.java @@ -22,6 +22,8 @@ import java.util.Set; import org.eclipse.jdt.annotation.NonNullByDefault; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.openhab.core.automation.Action; import org.openhab.core.automation.Condition; import org.openhab.core.automation.Rule; @@ -95,7 +97,8 @@ public class ScriptRuleOSGiTest extends JavaOSGiTest { registerService(eventSubscriber); } - // ignore - wip @Test + @Test + @Disabled("WIP") public void testPredefinedRule() throws ItemNotFoundException { EventPublisher eventPublisher = getService(EventPublisher.class); ItemRegistry itemRegistry = getService(ItemRegistry.class); diff --git a/itests/org.openhab.core.config.dispatch.tests/src/main/java/org/openhab/core/config/dispatch/internal/ConfigDispatcherOSGiTest.java b/itests/org.openhab.core.config.dispatch.tests/src/main/java/org/openhab/core/config/dispatch/internal/ConfigDispatcherOSGiTest.java index b4751b188..2278b399d 100644 --- a/itests/org.openhab.core.config.dispatch.tests/src/main/java/org/openhab/core/config/dispatch/internal/ConfigDispatcherOSGiTest.java +++ b/itests/org.openhab.core.config.dispatch.tests/src/main/java/org/openhab/core/config/dispatch/internal/ConfigDispatcherOSGiTest.java @@ -926,15 +926,15 @@ public class ConfigDispatcherOSGiTest extends JavaOSGiTest { } private @Nullable Configuration getConfigurationWithContext(String pidWithContext) { - String pid = null; - String configContext = null; + String pid; + String configContext; if (pidWithContext.contains(OpenHAB.SERVICE_CONTEXT_MARKER)) { pid = pidWithContext.split(OpenHAB.SERVICE_CONTEXT_MARKER)[0]; configContext = pidWithContext.split(OpenHAB.SERVICE_CONTEXT_MARKER)[1]; } else { throw new IllegalArgumentException("PID does not have a context"); } - Configuration[] configs = null; + Configuration[] configs; try { configs = configAdmin.listConfigurations( "(&(service.factoryPid=" + pid + ")(" + OpenHAB.SERVICE_CONTEXT + "=" + configContext + "))"); diff --git a/itests/org.openhab.core.model.item.tests/src/main/java/org/openhab/core/model/item/internal/GenericItemProviderTest.java b/itests/org.openhab.core.model.item.tests/src/main/java/org/openhab/core/model/item/internal/GenericItemProviderTest.java index 5c19baeef..9f8043d7d 100644 --- a/itests/org.openhab.core.model.item.tests/src/main/java/org/openhab/core/model/item/internal/GenericItemProviderTest.java +++ b/itests/org.openhab.core.model.item.tests/src/main/java/org/openhab/core/model/item/internal/GenericItemProviderTest.java @@ -23,7 +23,6 @@ import java.math.BigDecimal; import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; -import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Set; @@ -158,12 +157,14 @@ public class GenericItemProviderTest extends JavaOSGiTest { Collection items = itemRegistry.getAll(); assertThat(items, hasSize(0)); - String model = "Group Weather [TAG1]\n" + "Group Weather_Chart (Weather)\n" - + "Number Weather_Temperature \"Outside Temperature [%.1f °C]\" (Weather_Chart) [TAG1, TAG2] { channel=\"acmeweather:weather:berlin:temperature\" }\n" - + "Number Weather_Temp_Max \"Todays Maximum [%.1f °C]\" (Weather_Chart)\n" - + "Number Weather_Temp_Min \"Todays Minimum [%.1f °C]\" (Weather_Chart)\n" - + "Number Weather_Chart_Period \"Chart Period\"\n" - + "DateTime Weather_LastUpdate \"Last Update [%1$ta %1$tR]\" [TAG1, TAG2, TAG3]"; + String model = """ + Group Weather [TAG1] + Group Weather_Chart (Weather) + Number Weather_Temperature "Outside Temperature [%.1f °C]" (Weather_Chart) [TAG1, TAG2] { channel="acmeweather:weather:berlin:temperature" } + Number Weather_Temp_Max "Todays Maximum [%.1f °C]" (Weather_Chart) + Number Weather_Temp_Min "Todays Minimum [%.1f °C]" (Weather_Chart) + Number Weather_Chart_Period "Chart Period" + DateTime Weather_LastUpdate "Last Update [%1$ta %1$tR]" [TAG1, TAG2, TAG3]"""; modelRepository.addOrRefreshModel(TESTMODEL_NAME, new ByteArrayInputStream(model.getBytes())); Collection actualItems = itemRegistry.getAll(); @@ -368,9 +369,10 @@ public class GenericItemProviderTest extends JavaOSGiTest { public void assertThatTheItemRegistryGetsTheSameInstanceOnItemUpdatesWithoutChanges() throws Exception { assertThat(itemRegistry.getAll(), hasSize(0)); - String model = "String test1 \"Test Item [%s]\" { channel=\"test:test:test:test\" }\n" - + "String test2 \"Test Item [%s]\" { channel=\"test:test:test:test\" }\n" - + "String test3 \"Test Item [%s]\" { channel=\"test:test:test:test\" }"; + String model = """ + String test1 "Test Item [%s]" { channel="test:test:test:test" } + String test2 "Test Item [%s]" { channel="test:test:test:test" } + String test3 "Test Item [%s]" { channel="test:test:test:test" }"""; modelRepository.addOrRefreshModel(TESTMODEL_NAME, new ByteArrayInputStream(model.getBytes())); waitForAssert(() -> assertThat(itemRegistry.getAll(), hasSize(3))); @@ -420,9 +422,7 @@ public class GenericItemProviderTest extends JavaOSGiTest { assertThat(groupItem, is(notNullValue())); int number = 0; - Iterator it = groupItem.getMembers().iterator(); - while (it.hasNext()) { - Item item = it.next(); + for (Item item : groupItem.getMembers()) { assertThat(item.getName(), is("number" + (++number))); } } @@ -459,9 +459,7 @@ public class GenericItemProviderTest extends JavaOSGiTest { assertThat(groupItem, is(notNullValue())); int number = 0; - Iterator it = groupItem.getMembers().iterator(); - while (it.hasNext()) { - Item item = it.next(); + for (Item item : groupItem.getMembers()) { assertThat(item.getName(), is("number" + (++number))); if (number == 7) { assertThat(item.getLabel(), is("Number Seven")); diff --git a/itests/org.openhab.core.model.thing.tests/src/main/java/org/openhab/core/model/thing/test/hue/GenericThingProviderTest.java b/itests/org.openhab.core.model.thing.tests/src/main/java/org/openhab/core/model/thing/test/hue/GenericThingProviderTest.java index 84398e24b..64af52414 100644 --- a/itests/org.openhab.core.model.thing.tests/src/main/java/org/openhab/core/model/thing/test/hue/GenericThingProviderTest.java +++ b/itests/org.openhab.core.model.thing.tests/src/main/java/org/openhab/core/model/thing/test/hue/GenericThingProviderTest.java @@ -419,8 +419,10 @@ public class GenericThingProviderTest extends JavaOSGiTest { public void assertThatStandaloneThingsCanHaveBridgesInLongNotation() { assertThat(thingRegistry.getAll().size(), is(0)); - String model = "Bridge hue:bridge:myBridge @ \"basement\" [ ip = \"1.2.3.4\", username = \"123\" ]\n" - + "hue:LCT001:bulb1 (hue:bridge:myBridge) [ lightId = \"1\" ] { Switch : notification }\n"; + String model = """ + Bridge hue:bridge:myBridge @ "basement" [ ip = "1.2.3.4", username = "123" ] + hue:LCT001:bulb1 (hue:bridge:myBridge) [ lightId = "1" ] { Switch : notification } + """; modelRepository.addOrRefreshModel(TESTMODEL_NAME, new ByteArrayInputStream(model.getBytes())); Collection actualThings = thingRegistry.getAll(); @@ -462,8 +464,10 @@ public class GenericThingProviderTest extends JavaOSGiTest { public void assertThatStandaloneThingWithoutAbridgeDoesNotWorkInShortNotation() { assertThat(thingRegistry.getAll().size(), is(0)); - String model = "LCT001 bulb1 [ lightId = \"1\" ] { Switch : notification }\n" - + "hue:LCT001:bulb2 (hue:bridge:myBridge) [ lightId = \"2\" ] { Switch : notification }\n"; + String model = """ + LCT001 bulb1 [ lightId = "1" ] { Switch : notification } + hue:LCT001:bulb2 (hue:bridge:myBridge) [ lightId = "2" ] { Switch : notification } + """; modelRepository.addOrRefreshModel(TESTMODEL_NAME, new ByteArrayInputStream(model.getBytes())); Collection actualThings = thingRegistry.getAll(); diff --git a/itests/org.openhab.core.model.thing.tests/src/main/java/org/openhab/core/model/thing/test/hue/GenericThingProviderTest2.java b/itests/org.openhab.core.model.thing.tests/src/main/java/org/openhab/core/model/thing/test/hue/GenericThingProviderTest2.java index 0cd9b1caf..a356a8e50 100644 --- a/itests/org.openhab.core.model.thing.tests/src/main/java/org/openhab/core/model/thing/test/hue/GenericThingProviderTest2.java +++ b/itests/org.openhab.core.model.thing.tests/src/main/java/org/openhab/core/model/thing/test/hue/GenericThingProviderTest2.java @@ -66,19 +66,21 @@ public class GenericThingProviderTest2 extends JavaOSGiTest { Collection things = thingRegistry.getAll(); assertThat(things.size(), is(0)); - String model = "Bridge Xhue:Xbridge:myBridge [ XipAddress = \"1.2.3.4\", XuserName = \"123\" ] {" + // - " XLCT001 bulb1 [ XlightId = \"1\" ] { Switch : notification }" + // - " Bridge Xbridge myBridge2 [ ] {" + // - " XLCT001 bulb2 [ ]" + // - " }" + // - "}" + // - "Xhue:XTEST:bulb4 [ XlightId = \"5\"]{" + // - " Switch : notification [ duration = \"5\" ]" + // - "}" + // - "" + // - "Xhue:XLCT001:bulb3 [ XlightId = \"4\" ] {" + // - " Switch : notification [ duration = \"5\" ]" + // - "}"; + String model = """ + Bridge Xhue:Xbridge:myBridge [ XipAddress = "1.2.3.4", XuserName = "123" ] { + XLCT001 bulb1 [ XlightId = "1" ] { Switch : notification } + Bridge Xbridge myBridge2 [ ] { + XLCT001 bulb2 [ ] + } + } + Xhue:XTEST:bulb4 [ XlightId = "5"] { + Switch : notification [ duration = "5" ] + } + + Xhue:XLCT001:bulb3 [ XlightId = "4" ] { + Switch : notification [ duration = "5" ] + } + """; modelRepository.addOrRefreshModel(TESTMODEL_NAME, new ByteArrayInputStream(model.getBytes())); Collection actualThings = thingRegistry.getAll(); @@ -87,7 +89,6 @@ public class GenericThingProviderTest2 extends JavaOSGiTest { registerService(hueThingHandlerFactory, ThingHandlerFactory.class.getName()); - actualThings = thingRegistry.getAll(); assertThat(thingRegistry.getAll().size(), is(6)); unregisterService(hueThingHandlerFactory); diff --git a/itests/org.openhab.core.storage.json.tests/src/main/java/org/openhab/core/storage/json/internal/JsonStorageServiceOSGiTest.java b/itests/org.openhab.core.storage.json.tests/src/main/java/org/openhab/core/storage/json/internal/JsonStorageServiceOSGiTest.java index 09c4efffa..c66dbd25b 100644 --- a/itests/org.openhab.core.storage.json.tests/src/main/java/org/openhab/core/storage/json/internal/JsonStorageServiceOSGiTest.java +++ b/itests/org.openhab.core.storage.json.tests/src/main/java/org/openhab/core/storage/json/internal/JsonStorageServiceOSGiTest.java @@ -114,7 +114,7 @@ public class JsonStorageServiceOSGiTest extends JavaOSGiTest { @Test public void testOverride() { - PersistedItem pItem = null; + PersistedItem pItem; assertThat(storage.getKeys().size(), is(0)); diff --git a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/ChannelLinkNotifierOSGiTest.java b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/ChannelLinkNotifierOSGiTest.java index 9bdb13571..f4ac2254a 100644 --- a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/ChannelLinkNotifierOSGiTest.java +++ b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/ChannelLinkNotifierOSGiTest.java @@ -295,7 +295,7 @@ public class ChannelLinkNotifierOSGiTest extends JavaOSGiTest { } private void forEachThingChannelUID(Thing thing, Consumer consumer) { - thing.getChannels().stream().map(Channel::getUID).forEach(consumer::accept); + thing.getChannels().stream().map(Channel::getUID).forEach(consumer); } private void addItemsAndLinks(Thing thing, String itemSuffix) { diff --git a/tools/i18n-plugin/src/main/java/org/openhab/core/tools/i18n/plugin/Translations.java b/tools/i18n-plugin/src/main/java/org/openhab/core/tools/i18n/plugin/Translations.java index 26185f8cf..f8064d671 100644 --- a/tools/i18n-plugin/src/main/java/org/openhab/core/tools/i18n/plugin/Translations.java +++ b/tools/i18n-plugin/src/main/java/org/openhab/core/tools/i18n/plugin/Translations.java @@ -14,7 +14,6 @@ package org.openhab.core.tools.i18n.plugin; import java.util.Arrays; import java.util.List; -import java.util.function.Function; import java.util.function.Predicate; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -123,9 +122,7 @@ public class Translations { } public Stream keysStream() { - return groups.stream() // - .map(TranslationsGroup::keysStream) // - .flatMap(Function.identity()); + return groups.stream().flatMap(TranslationsGroup::keysStream); } public Stream linesStream() { @@ -138,8 +135,7 @@ public class Translations { } groups.stream() // .filter(TranslationsGroup::hasTranslations) // - .map(TranslationsGroup::linesStream) // - .flatMap(Function.identity()) // + .flatMap(TranslationsGroup::linesStream) // .forEach(builder::add); builder.add(""); return builder.build(); @@ -181,16 +177,13 @@ public class Translations { } public Stream keysStream() { - return sections.stream() // - .map(TranslationsSection::keysStream) // - .flatMap(Function.identity()); + return sections.stream().flatMap(TranslationsSection::keysStream); } public Stream linesStream() { return sections.stream() // .filter(TranslationsSection::hasTranslations) // - .map(TranslationsSection::linesStream) // - .flatMap(Function.identity()); + .flatMap(TranslationsSection::linesStream); } public void removeEntries(Predicate filter) {