diff --git a/bundles/org.openhab.core.audio/src/test/java/org/openhab/core/audio/internal/AudioManagerTest.java b/bundles/org.openhab.core.audio/src/test/java/org/openhab/core/audio/internal/AudioManagerTest.java index e7b12b7c86..aae2bfef5d 100644 --- a/bundles/org.openhab.core.audio/src/test/java/org/openhab/core/audio/internal/AudioManagerTest.java +++ b/bundles/org.openhab.core.audio/src/test/java/org/openhab/core/audio/internal/AudioManagerTest.java @@ -24,6 +24,7 @@ import java.net.URI; import java.util.Collection; import java.util.Collections; import java.util.Locale; +import java.util.Map; import java.util.function.BiFunction; import org.junit.jupiter.api.AfterEach; @@ -231,8 +232,7 @@ public class AudioManagerTest { audioManager.addAudioSource(audioSource); if (isSourceDefault) { - audioManager - .modified(Collections.singletonMap(AudioManagerImpl.CONFIG_DEFAULT_SOURCE, audioSource.getId())); + audioManager.modified(Map.of(AudioManagerImpl.CONFIG_DEFAULT_SOURCE, audioSource.getId())); } else { // just to make sure there is no default source audioManager.modified(Collections.emptyMap()); @@ -250,10 +250,10 @@ public class AudioManagerTest { audioManager.addAudioSink(audioSink); if (isSinkDefault) { - audioManager.modified(Collections.singletonMap(AudioManagerImpl.CONFIG_DEFAULT_SINK, audioSink.getId())); + audioManager.modified(Map.of(AudioManagerImpl.CONFIG_DEFAULT_SINK, audioSink.getId())); } else { // just to make sure there is no default sink - audioManager.modified(Collections.emptyMap()); + audioManager.modified(Map.of()); } assertThat(String.format("The sink %s was not registered", audioSink.getId()), audioManager.getSink(), diff --git a/bundles/org.openhab.core.audio/src/test/java/org/openhab/core/audio/internal/fake/AudioSinkFake.java b/bundles/org.openhab.core.audio/src/test/java/org/openhab/core/audio/internal/fake/AudioSinkFake.java index ee46b20784..7b52e2705d 100644 --- a/bundles/org.openhab.core.audio/src/test/java/org/openhab/core/audio/internal/fake/AudioSinkFake.java +++ b/bundles/org.openhab.core.audio/src/test/java/org/openhab/core/audio/internal/fake/AudioSinkFake.java @@ -13,11 +13,8 @@ package org.openhab.core.audio.internal.fake; import java.io.IOException; -import java.util.Collections; import java.util.Locale; import java.util.Set; -import java.util.stream.Collectors; -import java.util.stream.Stream; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; @@ -51,10 +48,9 @@ public class AudioSinkFake implements AudioSink { public boolean isUnsupportedAudioFormatExceptionExpected; public boolean isUnsupportedAudioStreamExceptionExpected; - private static final Set SUPPORTED_AUDIO_FORMATS = Collections - .unmodifiableSet(Stream.of(AudioFormat.MP3, AudioFormat.WAV).collect(Collectors.toSet())); - private static final Set> SUPPORTED_AUDIO_STREAMS = Collections - .unmodifiableSet(Stream.of(FixedLengthAudioStream.class, URLAudioStream.class).collect(Collectors.toSet())); + private static final Set SUPPORTED_AUDIO_FORMATS = Set.of(AudioFormat.MP3, AudioFormat.WAV); + private static final Set> SUPPORTED_AUDIO_STREAMS = Set + .of(FixedLengthAudioStream.class, URLAudioStream.class); @Override public String getId() { diff --git a/bundles/org.openhab.core.automation.module.media/src/main/java/org/openhab/core/automation/module/media/internal/MediaModuleHandlerFactory.java b/bundles/org.openhab.core.automation.module.media/src/main/java/org/openhab/core/automation/module/media/internal/MediaModuleHandlerFactory.java index 7a10695965..eb863c09c8 100644 --- a/bundles/org.openhab.core.automation.module.media/src/main/java/org/openhab/core/automation/module/media/internal/MediaModuleHandlerFactory.java +++ b/bundles/org.openhab.core.automation.module.media/src/main/java/org/openhab/core/automation/module/media/internal/MediaModuleHandlerFactory.java @@ -12,10 +12,8 @@ */ package org.openhab.core.automation.module.media.internal; -import static java.util.Arrays.asList; -import static java.util.Collections.unmodifiableList; - import java.util.Collection; +import java.util.List; import org.openhab.core.audio.AudioManager; import org.openhab.core.automation.Action; @@ -35,8 +33,7 @@ import org.osgi.service.component.annotations.Reference; @Component(service = ModuleHandlerFactory.class) public class MediaModuleHandlerFactory extends BaseModuleHandlerFactory { - private static final Collection TYPES = unmodifiableList( - asList(SayActionHandler.TYPE_ID, PlayActionHandler.TYPE_ID)); + private static final Collection TYPES = List.of(SayActionHandler.TYPE_ID, PlayActionHandler.TYPE_ID); private VoiceManager voiceManager; private AudioManager audioManager; diff --git a/bundles/org.openhab.core.automation.module.media/src/main/java/org/openhab/core/automation/module/media/internal/MediaScriptScopeProvider.java b/bundles/org.openhab.core.automation.module.media/src/main/java/org/openhab/core/automation/module/media/internal/MediaScriptScopeProvider.java index 74b05baf72..78ac127c05 100644 --- a/bundles/org.openhab.core.automation.module.media/src/main/java/org/openhab/core/automation/module/media/internal/MediaScriptScopeProvider.java +++ b/bundles/org.openhab.core.automation.module.media/src/main/java/org/openhab/core/automation/module/media/internal/MediaScriptScopeProvider.java @@ -13,9 +13,9 @@ package org.openhab.core.automation.module.media.internal; import java.util.Collection; -import java.util.Collections; import java.util.HashMap; import java.util.Map; +import java.util.Set; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; @@ -56,12 +56,12 @@ public class MediaScriptScopeProvider implements ScriptExtensionProvider { @Override public Collection getDefaultPresets() { - return Collections.singleton("media"); + return Set.of("media"); } @Override public Collection getPresets() { - return Collections.singleton("media"); + return Set.of("media"); } @Override diff --git a/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/internal/defaultscope/DefaultScriptScopeProvider.java b/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/internal/defaultscope/DefaultScriptScopeProvider.java index efde9cc83d..0c465a1df0 100644 --- a/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/internal/defaultscope/DefaultScriptScopeProvider.java +++ b/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/internal/defaultscope/DefaultScriptScopeProvider.java @@ -20,6 +20,7 @@ import java.nio.file.Paths; import java.util.Collection; import java.util.Collections; import java.util.Map; +import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -182,12 +183,12 @@ public class DefaultScriptScopeProvider implements ScriptExtensionProvider { @Override public Collection getDefaultPresets() { - return Collections.singleton(PRESET_DEFAULT); + return Set.of(PRESET_DEFAULT); } @Override public Collection getPresets() { - return Collections.singleton(PRESET_DEFAULT); + return Set.of(PRESET_DEFAULT); } @Override diff --git a/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/internal/defaultscope/ItemRegistryDelegate.java b/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/internal/defaultscope/ItemRegistryDelegate.java index c604aeb37b..d906dae2f3 100644 --- a/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/internal/defaultscope/ItemRegistryDelegate.java +++ b/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/internal/defaultscope/ItemRegistryDelegate.java @@ -12,7 +12,6 @@ */ package org.openhab.core.automation.module.script.internal.defaultscope; -import java.util.AbstractMap; import java.util.Collection; import java.util.HashSet; import java.util.Map; @@ -115,7 +114,7 @@ public class ItemRegistryDelegate implements Map { public Set> entrySet() { Set> entries = new HashSet<>(); for (Item item : itemRegistry.getAll()) { - entries.add(new AbstractMap.SimpleEntry<>(item.getName(), item.getState())); + entries.add(Map.entry(item.getName(), item.getState())); } return entries; } diff --git a/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/internal/defaultscope/LifecycleScriptExtensionProvider.java b/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/internal/defaultscope/LifecycleScriptExtensionProvider.java index cb9b79e2b8..c9097e0ac6 100644 --- a/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/internal/defaultscope/LifecycleScriptExtensionProvider.java +++ b/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/internal/defaultscope/LifecycleScriptExtensionProvider.java @@ -17,6 +17,7 @@ import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -40,17 +41,17 @@ public class LifecycleScriptExtensionProvider implements ScriptExtensionProvider @Override public Collection getDefaultPresets() { - return Collections.singleton(LIFECYCLE_PRESET_NAME); + return Set.of(LIFECYCLE_PRESET_NAME); } @Override public Collection getPresets() { - return Collections.singleton(LIFECYCLE_PRESET_NAME); + return Set.of(LIFECYCLE_PRESET_NAME); } @Override public Collection getTypes() { - return Collections.singleton(LIFECYCLE_TRACKER_NAME); + return Set.of(LIFECYCLE_TRACKER_NAME); } @Override @@ -67,7 +68,7 @@ public class LifecycleScriptExtensionProvider implements ScriptExtensionProvider if (LIFECYCLE_PRESET_NAME.equals(preset)) { final Object requestedType = get(scriptIdentifier, LIFECYCLE_TRACKER_NAME); if (requestedType != null) { - return Collections.singletonMap(LIFECYCLE_TRACKER_NAME, requestedType); + return Map.of(LIFECYCLE_TRACKER_NAME, requestedType); } } diff --git a/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/internal/factory/ScriptModuleHandlerFactory.java b/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/internal/factory/ScriptModuleHandlerFactory.java index ba979a4771..8e219e805a 100644 --- a/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/internal/factory/ScriptModuleHandlerFactory.java +++ b/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/internal/factory/ScriptModuleHandlerFactory.java @@ -12,10 +12,8 @@ */ package org.openhab.core.automation.module.script.internal.factory; -import static java.util.Arrays.asList; -import static java.util.Collections.unmodifiableList; - import java.util.Collection; +import java.util.List; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; @@ -46,8 +44,8 @@ public class ScriptModuleHandlerFactory extends BaseModuleHandlerFactory { private final Logger logger = LoggerFactory.getLogger(ScriptModuleHandlerFactory.class); - private static final Collection TYPES = unmodifiableList( - asList(ScriptActionHandler.TYPE_ID, ScriptConditionHandler.TYPE_ID)); + private static final Collection TYPES = List.of(ScriptActionHandler.TYPE_ID, + ScriptConditionHandler.TYPE_ID); private @NonNullByDefault({}) ScriptEngineManager scriptEngineManager; @Override diff --git a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/RuleImpl.java b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/RuleImpl.java index 4bb37d90aa..8e3b26e1c3 100644 --- a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/RuleImpl.java +++ b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/RuleImpl.java @@ -14,7 +14,6 @@ package org.openhab.core.automation.internal; import java.util.ArrayList; import java.util.Collections; -import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.UUID; @@ -95,15 +94,11 @@ public class RuleImpl implements Rule { this.uid = uid == null ? UUID.randomUUID().toString() : uid; this.name = name; this.description = description; - this.tags = tags == null ? Collections.emptySet() : Collections.unmodifiableSet(new HashSet<>(tags)); - this.triggers = triggers == null ? Collections.emptyList() - : Collections.unmodifiableList(new ArrayList<>(triggers)); - this.conditions = conditions == null ? Collections.emptyList() - : Collections.unmodifiableList(new ArrayList<>(conditions)); - this.actions = actions == null ? Collections.emptyList() - : Collections.unmodifiableList(new ArrayList<>(actions)); - this.configDescriptions = configDescriptions == null ? Collections.emptyList() - : Collections.unmodifiableList(new ArrayList<>(configDescriptions)); + this.tags = tags == null ? Set.of() : Set.copyOf(tags); + this.triggers = triggers == null ? List.of() : List.copyOf(triggers); + this.conditions = conditions == null ? List.of() : List.copyOf(conditions); + this.actions = actions == null ? List.of() : List.copyOf(actions); + this.configDescriptions = configDescriptions == null ? List.of() : List.copyOf(configDescriptions); this.configuration = configuration == null ? new Configuration() : new Configuration(configuration.getProperties()); this.templateUID = templateUID; diff --git a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/module/factory/EphemerisModuleHandlerFactory.java b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/module/factory/EphemerisModuleHandlerFactory.java index 4c1f20de2b..4bd3e2a9e1 100644 --- a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/module/factory/EphemerisModuleHandlerFactory.java +++ b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/module/factory/EphemerisModuleHandlerFactory.java @@ -13,9 +13,7 @@ package org.openhab.core.automation.internal.module.factory; import java.util.Collection; -import java.util.Collections; -import java.util.stream.Collectors; -import java.util.stream.Stream; +import java.util.List; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; @@ -45,10 +43,9 @@ public class EphemerisModuleHandlerFactory extends BaseModuleHandlerFactory impl private final Logger logger = LoggerFactory.getLogger(EphemerisModuleHandlerFactory.class); - private static final Collection TYPES = Collections.unmodifiableList(Stream - .of(EphemerisConditionHandler.HOLIDAY_MODULE_TYPE_ID, EphemerisConditionHandler.WEEKEND_MODULE_TYPE_ID, - EphemerisConditionHandler.WEEKDAY_MODULE_TYPE_ID, EphemerisConditionHandler.DAYSET_MODULE_TYPE_ID) - .collect(Collectors.toList())); + private static final Collection TYPES = List.of(EphemerisConditionHandler.HOLIDAY_MODULE_TYPE_ID, + EphemerisConditionHandler.WEEKEND_MODULE_TYPE_ID, EphemerisConditionHandler.WEEKDAY_MODULE_TYPE_ID, + EphemerisConditionHandler.DAYSET_MODULE_TYPE_ID); private final EphemerisManager ephemerisManager; diff --git a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/module/handler/GenericEventTriggerHandler.java b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/module/handler/GenericEventTriggerHandler.java index ba06cbfbfd..6ef80f6336 100644 --- a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/module/handler/GenericEventTriggerHandler.java +++ b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/module/handler/GenericEventTriggerHandler.java @@ -12,11 +12,8 @@ */ package org.openhab.core.automation.internal.module.handler; -import java.util.Arrays; -import java.util.Collections; import java.util.Dictionary; import java.util.HashMap; -import java.util.HashSet; import java.util.Hashtable; import java.util.Map; import java.util.Set; @@ -66,10 +63,9 @@ public class GenericEventTriggerHandler extends BaseTriggerModuleHandler impleme this.source = (String) module.getConfiguration().get(CFG_EVENT_SOURCE); this.topic = (String) module.getConfiguration().get(CFG_EVENT_TOPIC); if (module.getConfiguration().get(CFG_EVENT_TYPES) != null) { - this.types = Collections.unmodifiableSet( - new HashSet<>(Arrays.asList(((String) module.getConfiguration().get(CFG_EVENT_TYPES)).split(",")))); + this.types = Set.of(((String) module.getConfiguration().get(CFG_EVENT_TYPES)).split(",")); } else { - this.types = Collections.emptySet(); + this.types = Set.of(); } this.bundleContext = bundleContext; Dictionary properties = new Hashtable<>(); diff --git a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/module/handler/GroupCommandTriggerHandler.java b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/module/handler/GroupCommandTriggerHandler.java index 4afab1998a..b55d71646a 100644 --- a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/module/handler/GroupCommandTriggerHandler.java +++ b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/module/handler/GroupCommandTriggerHandler.java @@ -12,7 +12,6 @@ */ package org.openhab.core.automation.internal.module.handler; -import java.util.Collections; import java.util.Dictionary; import java.util.HashMap; import java.util.Hashtable; @@ -67,7 +66,7 @@ public class GroupCommandTriggerHandler extends BaseTriggerModuleHandler impleme super(module); this.groupName = (String) module.getConfiguration().get(CFG_GROUPNAME); this.command = (String) module.getConfiguration().get(CFG_COMMAND); - this.types = Collections.singleton(ItemCommandEvent.TYPE); + this.types = Set.of(ItemCommandEvent.TYPE); this.bundleContext = bundleContext; Dictionary properties = new Hashtable<>(); this.topic = "openhab/items/"; diff --git a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/module/handler/GroupStateTriggerHandler.java b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/module/handler/GroupStateTriggerHandler.java index 69b4bcd885..39fc32cfdd 100644 --- a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/module/handler/GroupStateTriggerHandler.java +++ b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/module/handler/GroupStateTriggerHandler.java @@ -12,10 +12,8 @@ */ package org.openhab.core.automation.internal.module.handler; -import java.util.Collections; import java.util.Dictionary; import java.util.HashMap; -import java.util.HashSet; import java.util.Hashtable; import java.util.Map; import java.util.Set; @@ -73,12 +71,9 @@ public class GroupStateTriggerHandler extends BaseTriggerModuleHandler implement this.state = (String) module.getConfiguration().get(CFG_STATE); this.previousState = (String) module.getConfiguration().get(CFG_PREVIOUS_STATE); if (UPDATE_MODULE_TYPE_ID.equals(module.getTypeUID())) { - this.types = Collections.singleton(ItemStateEvent.TYPE); + this.types = Set.of(ItemStateEvent.TYPE); } else { - Set set = new HashSet<>(); - set.add(ItemStateChangedEvent.TYPE); - set.add(GroupItemStateChangedEvent.TYPE); - this.types = Collections.unmodifiableSet(set); + this.types = Set.of(ItemStateChangedEvent.TYPE, GroupItemStateChangedEvent.TYPE); } this.bundleContext = bundleContext; Dictionary properties = new Hashtable<>(); diff --git a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/module/handler/ItemCommandTriggerHandler.java b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/module/handler/ItemCommandTriggerHandler.java index 718b121c45..bcd808706b 100644 --- a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/module/handler/ItemCommandTriggerHandler.java +++ b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/module/handler/ItemCommandTriggerHandler.java @@ -12,7 +12,6 @@ */ package org.openhab.core.automation.internal.module.handler; -import java.util.Collections; import java.util.Dictionary; import java.util.HashMap; import java.util.Hashtable; @@ -61,7 +60,7 @@ public class ItemCommandTriggerHandler extends BaseTriggerModuleHandler implemen super(module); this.itemName = (String) module.getConfiguration().get(CFG_ITEMNAME); this.command = (String) module.getConfiguration().get(CFG_COMMAND); - this.types = Collections.singleton(ItemCommandEvent.TYPE); + this.types = Set.of(ItemCommandEvent.TYPE); this.bundleContext = bundleContext; Dictionary properties = new Hashtable<>(); this.topic = "openhab/items/" + itemName + "/command"; diff --git a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/module/handler/ItemStateTriggerHandler.java b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/module/handler/ItemStateTriggerHandler.java index 9839cf0dd7..eb15e131da 100644 --- a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/module/handler/ItemStateTriggerHandler.java +++ b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/module/handler/ItemStateTriggerHandler.java @@ -12,10 +12,8 @@ */ package org.openhab.core.automation.internal.module.handler; -import java.util.Collections; import java.util.Dictionary; import java.util.HashMap; -import java.util.HashSet; import java.util.Hashtable; import java.util.Map; import java.util.Set; @@ -68,12 +66,9 @@ public class ItemStateTriggerHandler extends BaseTriggerModuleHandler implements this.state = (String) module.getConfiguration().get(CFG_STATE); this.previousState = (String) module.getConfiguration().get(CFG_PREVIOUS_STATE); if (UPDATE_MODULE_TYPE_ID.equals(module.getTypeUID())) { - this.types = Collections.singleton(ItemStateEvent.TYPE); + this.types = Set.of(ItemStateEvent.TYPE); } else { - Set set = new HashSet<>(); - set.add(ItemStateChangedEvent.TYPE); - set.add(GroupItemStateChangedEvent.TYPE); - this.types = Collections.unmodifiableSet(set); + this.types = Set.of(ItemStateChangedEvent.TYPE, GroupItemStateChangedEvent.TYPE); } this.bundleContext = bundleContext; Dictionary properties = new Hashtable<>(); diff --git a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/module/handler/SystemTriggerHandler.java b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/module/handler/SystemTriggerHandler.java index 6fbe7508b1..63e70c44be 100644 --- a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/module/handler/SystemTriggerHandler.java +++ b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/module/handler/SystemTriggerHandler.java @@ -13,7 +13,6 @@ package org.openhab.core.automation.internal.module.handler; import java.math.BigDecimal; -import java.util.Collections; import java.util.Dictionary; import java.util.HashMap; import java.util.Hashtable; @@ -59,7 +58,7 @@ public class SystemTriggerHandler extends BaseTriggerModuleHandler implements Ev super(module); this.startlevel = ((BigDecimal) module.getConfiguration().get(CFG_STARTLEVEL)).intValue(); if (STARTLEVEL_MODULE_TYPE_ID.equals(module.getTypeUID())) { - this.types = Collections.singleton(StartlevelEvent.TYPE); + this.types = Set.of(StartlevelEvent.TYPE); } else { logger.warn("Module type '{}' is not (yet) handled by this class.", module.getTypeUID()); throw new IllegalArgumentException(module.getTypeUID() + " is no valid module type."); diff --git a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/module/handler/ThingStatusTriggerHandler.java b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/module/handler/ThingStatusTriggerHandler.java index 9c2072d778..fb050890af 100644 --- a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/module/handler/ThingStatusTriggerHandler.java +++ b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/module/handler/ThingStatusTriggerHandler.java @@ -12,7 +12,6 @@ */ package org.openhab.core.automation.internal.module.handler; -import java.util.Collections; import java.util.Dictionary; import java.util.HashMap; import java.util.Hashtable; @@ -73,9 +72,9 @@ public class ThingStatusTriggerHandler extends BaseTriggerModuleHandler implemen this.status = (String) module.getConfiguration().get(CFG_STATUS); this.previousStatus = (String) module.getConfiguration().get(CFG_PREVIOUS_STATUS); if (UPDATE_MODULE_TYPE_ID.equals(module.getTypeUID())) { - this.types = Collections.singleton(ThingStatusInfoEvent.TYPE); + this.types = Set.of(ThingStatusInfoEvent.TYPE); } else { - this.types = Collections.singleton(ThingStatusInfoChangedEvent.TYPE); + this.types = Set.of(ThingStatusInfoChangedEvent.TYPE); } this.bundleContext = bundleContext; Dictionary properties = new Hashtable<>(); diff --git a/bundles/org.openhab.core.automation/src/test/java/org/openhab/core/automation/internal/module/factory/EphemerisModuleHandlerFactoryTest.java b/bundles/org.openhab.core.automation/src/test/java/org/openhab/core/automation/internal/module/factory/EphemerisModuleHandlerFactoryTest.java index 35d8839e60..83cc6d4be8 100644 --- a/bundles/org.openhab.core.automation/src/test/java/org/openhab/core/automation/internal/module/factory/EphemerisModuleHandlerFactoryTest.java +++ b/bundles/org.openhab.core.automation/src/test/java/org/openhab/core/automation/internal/module/factory/EphemerisModuleHandlerFactoryTest.java @@ -17,7 +17,7 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.*; -import java.util.Collections; +import java.util.Map; import org.eclipse.jdt.annotation.NonNullByDefault; import org.junit.jupiter.api.BeforeEach; @@ -60,7 +60,7 @@ public class EphemerisModuleHandlerFactoryTest { public void testFactoryCreatesModuleHandlerForDaysetCondition() { when(moduleMock.getTypeUID()).thenReturn(EphemerisConditionHandler.DAYSET_MODULE_TYPE_ID); - when(moduleMock.getConfiguration()).thenReturn(new Configuration(Collections.singletonMap("dayset", "school"))); + when(moduleMock.getConfiguration()).thenReturn(new Configuration(Map.of("dayset", "school"))); ModuleHandler handler = factory.internalCreate(moduleMock, "My second rule"); assertThat(handler, is(notNullValue())); assertThat(handler, instanceOf(EphemerisConditionHandler.class)); @@ -75,7 +75,7 @@ public class EphemerisModuleHandlerFactoryTest { assertThat(handler, is(notNullValue())); assertThat(handler, instanceOf(EphemerisConditionHandler.class)); - when(moduleMock.getConfiguration()).thenReturn(new Configuration(Collections.singletonMap("offset", 5))); + when(moduleMock.getConfiguration()).thenReturn(new Configuration(Map.of("offset", 5))); handler = factory.internalCreate(moduleMock, "My second rule"); assertThat(handler, is(notNullValue())); assertThat(handler, instanceOf(EphemerisConditionHandler.class)); diff --git a/bundles/org.openhab.core.automation/src/test/java/org/openhab/core/automation/util/ReferenceResolverUtilTest.java b/bundles/org.openhab.core.automation/src/test/java/org/openhab/core/automation/util/ReferenceResolverUtilTest.java index fc4787aecc..0c37699e34 100644 --- a/bundles/org.openhab.core.automation/src/test/java/org/openhab/core/automation/util/ReferenceResolverUtilTest.java +++ b/bundles/org.openhab.core.automation/src/test/java/org/openhab/core/automation/util/ReferenceResolverUtilTest.java @@ -15,7 +15,6 @@ package org.openhab.core.automation.util; import static org.junit.jupiter.api.Assertions.*; import java.math.BigDecimal; -import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -154,14 +153,14 @@ public class ReferenceResolverUtilTest { @Test public void testGetFromList() { String ken = "Ken"; - List names = Arrays.asList("John", ken, "Sue"); + List names = List.of("John", ken, "Sue"); assertEquals(ken, ReferenceResolver.resolveComplexDataReference(names, ReferenceResolver.splitReferenceToTokens("[1]"))); } @Test public void testGetFromListInvalidIndexFormat() { - List names = Arrays.asList("John", "Ken", "Sue"); + List names = List.of("John", "Ken", "Sue"); assertThrows(NumberFormatException.class, () -> ReferenceResolver.resolveComplexDataReference(names, ReferenceResolver.splitReferenceToTokens("[Ten]"))); } @@ -169,10 +168,7 @@ public class ReferenceResolverUtilTest { @Test public void getFromMap() { String phone = "0331 1387 121"; - Map phones = new HashMap<>(); - phones.put("John", phone); - phones.put("Sue", "0222 2184 121"); - phones.put("Mark", "0222 5641 121"); + Map phones = Map.of("John", phone, "Sue", "0222 2184 121", "Mark", "0222 5641 121"); assertEquals(phone, ReferenceResolver.resolveComplexDataReference(phones, ReferenceResolver.splitReferenceToTokens("[\"John\"]"))); } @@ -180,19 +176,14 @@ public class ReferenceResolverUtilTest { @Test public void getFromMapWithKeyThatContainsSpecialCharacters() { String phone = "0331 1387 121"; - Map phones = new HashMap<>(); - phones.put("John[].Smi\"th].", phone); - phones.put("Sue", "0222 2184 121"); - phones.put("Mark", "0222 5641 121"); + Map phones = Map.of("John[].Smi\"th].", phone, "Sue", "0222 2184 121", "Mark", "0222 5641 121"); assertEquals(phone, ReferenceResolver.resolveComplexDataReference(phones, ReferenceResolver.splitReferenceToTokens("[\"John[].Smi\"th].\"]"))); } @Test public void getFromMapUnExistingKey() { - Map phones = new HashMap<>(); - phones.put("Sue", "0222 2184 121"); - phones.put("Mark", "0222 5641 121"); + Map phones = Map.of("Sue", "0222 2184 121", "Mark", "0222 5641 121"); assertNull(ReferenceResolver.resolveComplexDataReference(phones, ReferenceResolver.splitReferenceToTokens("[\"John\"]"))); } @@ -200,21 +191,21 @@ public class ReferenceResolverUtilTest { @Test public void getFromList() { String ken = "Ken"; - List names = Arrays.asList(new String[] { "John", ken, "Sue" }); + List names = List.of("John", ken, "Sue"); assertEquals(ken, ReferenceResolver.resolveComplexDataReference(names, ReferenceResolver.splitReferenceToTokens("[1]"))); } @Test public void testGetFromListInvalidIndex() { - List names = Arrays.asList(new String[] { "John", "Ken", "Sue" }); + List names = List.of("John", "Ken", "Sue"); assertThrows(ArrayIndexOutOfBoundsException.class, () -> ReferenceResolver.resolveComplexDataReference(names, ReferenceResolver.splitReferenceToTokens("[10]"))); } @Test public void testGetFromInvalidIndexFormat() { - List names = Arrays.asList(new String[] { "John", "Ken", "Sue" }); + List names = List.of("John", "Ken", "Sue"); assertThrows(NumberFormatException.class, () -> ReferenceResolver.resolveComplexDataReference(names, ReferenceResolver.splitReferenceToTokens("[Ten]"))); } @@ -238,8 +229,7 @@ public class ReferenceResolverUtilTest { @Test public void testBeanFromBean() { String phone = "0331 1387 121"; - Map phones = new HashMap<>(); - phones.put("John", phone); + Map phones = Map.of("John", phone); B1> b3 = new B1<>(phones); B2>> b4 = new B2<>(b3); assertEquals(phone, ReferenceResolver.resolveComplexDataReference(b4, @@ -252,7 +242,7 @@ public class ReferenceResolverUtilTest { B1 b31 = new B1<>("Ken"); B1 b32 = new B1<>("Sue"); B1 b33 = new B1<>(name); - List> b = Arrays.asList(b31, b32, b33); + List> b = List.of(b31, b32, b33); assertEquals(name, ReferenceResolver.resolveComplexDataReference(b, ReferenceResolver.splitReferenceToTokens("[2].value"))); } diff --git a/bundles/org.openhab.core.config.core/src/main/java/org/openhab/core/config/core/ConfigDescriptionParameter.java b/bundles/org.openhab.core.config.core/src/main/java/org/openhab/core/config/core/ConfigDescriptionParameter.java index e5b87f7591..89b2087b3b 100644 --- a/bundles/org.openhab.core.config.core/src/main/java/org/openhab/core/config/core/ConfigDescriptionParameter.java +++ b/bundles/org.openhab.core.config.core/src/main/java/org/openhab/core/config/core/ConfigDescriptionParameter.java @@ -14,9 +14,7 @@ package org.openhab.core.config.core; import java.math.BigDecimal; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; -import java.util.HashSet; import java.util.LinkedList; import java.util.List; import java.util.Set; @@ -104,10 +102,9 @@ public class ConfigDescriptionParameter { private boolean advanced = false; private boolean verify = false; - private static final Set UNITS = Collections - .unmodifiableSet(new HashSet<>(Arrays.asList("A", "cd", "K", "kg", "m", "mol", "s", "g", "rad", "sr", "Hz", - "N", "Pa", "J", "W", "C", "V", "F", "Ω", "S", "Wb", "T", "H", "Cel", "lm", "lx", "Bq", "Gy", "Sv", - "kat", "m/s2", "m2v", "m3", "kph", "%", "l", "ms", "min", "h", "d", "week", "y"))); + private static final Set UNITS = Set.of("A", "cd", "K", "kg", "m", "mol", "s", "g", "rad", "sr", "Hz", "N", + "Pa", "J", "W", "C", "V", "F", "Ω", "S", "Wb", "T", "H", "Cel", "lm", "lx", "Bq", "Gy", "Sv", "kat", "m/s2", + "m2v", "m3", "kph", "%", "l", "ms", "min", "h", "d", "week", "y"); /** * Default constructor. diff --git a/bundles/org.openhab.core.config.core/src/main/java/org/openhab/core/config/core/ConfigUtil.java b/bundles/org.openhab.core.config.core/src/main/java/org/openhab/core/config/core/ConfigUtil.java index 493e10f763..da2004b2b2 100644 --- a/bundles/org.openhab.core.config.core/src/main/java/org/openhab/core/config/core/ConfigUtil.java +++ b/bundles/org.openhab.core.config.core/src/main/java/org/openhab/core/config/core/ConfigUtil.java @@ -112,7 +112,7 @@ public class ConfigUtil { if (defaultValue != null && configuration.get(parameter.getName()) == null) { if (parameter.isMultiple()) { if (defaultValue.contains(DEFAULT_LIST_DELIMITER)) { - List values = Arrays.asList(defaultValue.split(DEFAULT_LIST_DELIMITER)).stream() + List values = List.of(defaultValue.split(DEFAULT_LIST_DELIMITER)).stream() .map(v -> v.trim()).filter(v -> !v.isEmpty()) .map(v -> ConfigUtil.getDefaultValueAsCorrectType(parameter.getName(), parameter.getType(), v)) diff --git a/bundles/org.openhab.core.config.core/src/main/java/org/openhab/core/config/core/internal/ConfigMapper.java b/bundles/org.openhab.core.config.core/src/main/java/org/openhab/core/config/core/internal/ConfigMapper.java index 89016c0faf..041ee5f370 100644 --- a/bundles/org.openhab.core.config.core/src/main/java/org/openhab/core/config/core/internal/ConfigMapper.java +++ b/bundles/org.openhab.core.config.core/src/main/java/org/openhab/core/config/core/internal/ConfigMapper.java @@ -20,7 +20,6 @@ import java.math.BigDecimal; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; -import java.util.Collections; import java.util.List; import java.util.Map; @@ -161,7 +160,7 @@ public class ConfigMapper { final Enum enumvalue = Enum.valueOf(enumType, value.toString()); result = enumvalue; } else if (Collection.class.isAssignableFrom(type)) { - result = Collections.singletonList(value); + result = List.of(value); } } return result; diff --git a/bundles/org.openhab.core.config.core/src/main/java/org/openhab/core/config/core/internal/normalization/NormalizerFactory.java b/bundles/org.openhab.core.config.core/src/main/java/org/openhab/core/config/core/internal/normalization/NormalizerFactory.java index aa88f2845f..e4c43722d6 100644 --- a/bundles/org.openhab.core.config.core/src/main/java/org/openhab/core/config/core/internal/normalization/NormalizerFactory.java +++ b/bundles/org.openhab.core.config.core/src/main/java/org/openhab/core/config/core/internal/normalization/NormalizerFactory.java @@ -12,12 +12,9 @@ */ package org.openhab.core.config.core.internal.normalization; -import java.util.AbstractMap.SimpleEntry; -import java.util.Collections; +import static java.util.Map.entry; + import java.util.Map; -import java.util.Map.Entry; -import java.util.stream.Collectors; -import java.util.stream.Stream; import org.openhab.core.config.core.ConfigDescriptionParameter; import org.openhab.core.config.core.ConfigDescriptionParameter.Type; @@ -31,12 +28,9 @@ import org.openhab.core.config.core.ConfigDescriptionParameter.Type; */ public final class NormalizerFactory { - private static final Map NORMALIZERS = Collections.unmodifiableMap(Stream - .of(new SimpleEntry<>(Type.BOOLEAN, new BooleanNormalizer()), - new SimpleEntry<>(Type.TEXT, new TextNormalizer()), - new SimpleEntry<>(Type.INTEGER, new IntNormalizer()), - new SimpleEntry<>(Type.DECIMAL, new DecimalNormalizer())) - .collect(Collectors.toMap(Entry::getKey, Entry::getValue))); + private static final Map NORMALIZERS = Map.ofEntries(entry(Type.BOOLEAN, new BooleanNormalizer()), + entry(Type.TEXT, new TextNormalizer()), entry(Type.INTEGER, new IntNormalizer()), + entry(Type.DECIMAL, new DecimalNormalizer())); private NormalizerFactory() { // prevent instantiation diff --git a/bundles/org.openhab.core.config.core/src/main/java/org/openhab/core/config/core/internal/validation/TypeIntrospections.java b/bundles/org.openhab.core.config.core/src/main/java/org/openhab/core/config/core/internal/validation/TypeIntrospections.java index d374bded11..a2ede1f06f 100644 --- a/bundles/org.openhab.core.config.core/src/main/java/org/openhab/core/config/core/internal/validation/TypeIntrospections.java +++ b/bundles/org.openhab.core.config.core/src/main/java/org/openhab/core/config/core/internal/validation/TypeIntrospections.java @@ -12,13 +12,10 @@ */ package org.openhab.core.config.core.internal.validation; +import static java.util.Map.entry; + import java.math.BigDecimal; -import java.util.AbstractMap.SimpleEntry; -import java.util.Collections; import java.util.Map; -import java.util.Map.Entry; -import java.util.stream.Collectors; -import java.util.stream.Stream; import org.openhab.core.config.core.ConfigDescriptionParameter.Type; @@ -30,12 +27,9 @@ import org.openhab.core.config.core.ConfigDescriptionParameter.Type; */ final class TypeIntrospections { - private static final Map INTROSPECTIONS = Collections.unmodifiableMap(Stream - .of(new SimpleEntry<>(Type.BOOLEAN, new BooleanIntrospection()), - new SimpleEntry<>(Type.TEXT, new StringIntrospection()), - new SimpleEntry<>(Type.INTEGER, new IntegerIntrospection()), - new SimpleEntry<>(Type.DECIMAL, new FloatIntrospection())) - .collect(Collectors.toMap(Entry::getKey, Entry::getValue))); + private static final Map INTROSPECTIONS = Map.ofEntries( + entry(Type.BOOLEAN, new BooleanIntrospection()), entry(Type.TEXT, new StringIntrospection()), + entry(Type.INTEGER, new IntegerIntrospection()), entry(Type.DECIMAL, new FloatIntrospection())); private TypeIntrospections() { super(); diff --git a/bundles/org.openhab.core.config.core/src/main/java/org/openhab/core/config/core/status/events/ConfigStatusEventFactory.java b/bundles/org.openhab.core.config.core/src/main/java/org/openhab/core/config/core/status/events/ConfigStatusEventFactory.java index 7f6e29825c..1d3f23997c 100644 --- a/bundles/org.openhab.core.config.core/src/main/java/org/openhab/core/config/core/status/events/ConfigStatusEventFactory.java +++ b/bundles/org.openhab.core.config.core/src/main/java/org/openhab/core/config/core/status/events/ConfigStatusEventFactory.java @@ -12,7 +12,6 @@ */ package org.openhab.core.config.core.status.events; -import java.util.Collections; import java.util.Set; import org.openhab.core.config.core.status.ConfigStatusInfo; @@ -30,7 +29,7 @@ import org.osgi.service.component.annotations.Component; @Component(immediate = true, service = { EventFactory.class }) public final class ConfigStatusEventFactory extends AbstractEventFactory { - private static final Set SUPPORTED_EVENT_TYPES = Collections.singleton(ConfigStatusInfoEvent.TYPE); + private static final Set SUPPORTED_EVENT_TYPES = Set.of(ConfigStatusInfoEvent.TYPE); /** * Creates a new {@link ConfigStatusEventFactory}. diff --git a/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/ConfigDescriptionBuilderTest.java b/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/ConfigDescriptionBuilderTest.java index 91450d49ef..b9728d8a34 100644 --- a/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/ConfigDescriptionBuilderTest.java +++ b/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/ConfigDescriptionBuilderTest.java @@ -17,7 +17,6 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.collection.IsCollectionWithSize.hasSize; import java.net.URI; -import java.util.Arrays; import java.util.List; import org.junit.jupiter.api.BeforeEach; @@ -66,7 +65,7 @@ public class ConfigDescriptionBuilderTest { @Test public void testWithTwoParameters() { - final List params = Arrays.asList(PARAM1, PARAM2); + final List params = List.of(PARAM1, PARAM2); ConfigDescription configDescription = builder.withParameters(params).build(); assertThat(configDescription.getUID(), is(CONFIG_URI)); @@ -86,7 +85,7 @@ public class ConfigDescriptionBuilderTest { @Test public void testWithTwoParameterGroups() { - final List groups = Arrays.asList(GROUP1, GROUP2); + final List groups = List.of(GROUP1, GROUP2); ConfigDescription configDescription = builder.withParameterGroups(groups).build(); assertThat(configDescription.getUID(), is(CONFIG_URI)); diff --git a/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/ConfigDescriptionParameterBuilderTest.java b/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/ConfigDescriptionParameterBuilderTest.java index a78f537289..5f1d065083 100644 --- a/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/ConfigDescriptionParameterBuilderTest.java +++ b/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/ConfigDescriptionParameterBuilderTest.java @@ -17,7 +17,7 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.jupiter.api.Assertions.*; import java.math.BigDecimal; -import java.util.Arrays; +import java.util.List; import org.junit.jupiter.api.Test; import org.openhab.core.config.core.ConfigDescriptionParameter.Type; @@ -67,8 +67,8 @@ public class ConfigDescriptionParameterBuilderTest { .withDefault(defaultVal) .withLabel(label) .withDescription(description) - .withOptions(Arrays.asList(options)) - .withFilterCriteria(Arrays.asList(criterias)) + .withOptions(List.of(options)) + .withFilterCriteria(List.of(criterias)) .withGroupName(groupName) .withAdvanced(advanced) .withLimitToOptions(limitToOptions) diff --git a/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/ConfigDescriptionRegistryTest.java b/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/ConfigDescriptionRegistryTest.java index b60433dc71..f47565e36e 100644 --- a/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/ConfigDescriptionRegistryTest.java +++ b/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/ConfigDescriptionRegistryTest.java @@ -20,8 +20,8 @@ import static org.mockito.Mockito.when; import java.net.URI; import java.util.ArrayList; -import java.util.Collections; import java.util.List; +import java.util.Set; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -68,39 +68,36 @@ public class ConfigDescriptionRegistryTest extends JavaTest { .create("param1", ConfigDescriptionParameter.Type.INTEGER).build(); configDescription = ConfigDescriptionBuilder.create(uriDummy).withParameter(param1).build(); - when(configDescriptionProviderMock.getConfigDescriptions(any())) - .thenReturn(Collections.singleton(configDescription)); + when(configDescriptionProviderMock.getConfigDescriptions(any())).thenReturn(Set.of(configDescription)); when(configDescriptionProviderMock.getConfigDescription(eq(uriDummy), any())).thenReturn(configDescription); configDescription1 = ConfigDescriptionBuilder.create(uriDummy1).build(); - when(configDescriptionProviderMock1.getConfigDescriptions(any())) - .thenReturn(Collections.singleton(configDescription1)); + when(configDescriptionProviderMock1.getConfigDescriptions(any())).thenReturn(Set.of(configDescription1)); when(configDescriptionProviderMock1.getConfigDescription(eq(uriDummy1), any())).thenReturn(configDescription1); configDescriptionAliased = ConfigDescriptionBuilder.create(uriAliases).withParameter( ConfigDescriptionParameterBuilder.create("instanceId", ConfigDescriptionParameter.Type.INTEGER).build()) .build(); when(configDescriptionProviderAliased.getConfigDescriptions(any())) - .thenReturn(Collections.singleton(configDescriptionAliased)); + .thenReturn(Set.of(configDescriptionAliased)); when(configDescriptionProviderAliased.getConfigDescription(eq(uriAliases), any())) .thenReturn(configDescriptionAliased); ConfigDescriptionParameter param2 = ConfigDescriptionParameterBuilder .create("param2", ConfigDescriptionParameter.Type.INTEGER).build(); configDescription2 = ConfigDescriptionBuilder.create(uriDummy).withParameter(param2).build(); - when(configDescriptionProviderMock2.getConfigDescriptions(any())) - .thenReturn(Collections.singleton(configDescription2)); + when(configDescriptionProviderMock2.getConfigDescriptions(any())).thenReturn(Set.of(configDescription2)); when(configDescriptionProviderMock2.getConfigDescription(eq(uriDummy), any())).thenReturn(configDescription2); when(aliasProvider.getAlias(eq(uriAliases))).thenReturn(uriDummy); when(configOptionsProviderMockAliased.getParameterOptions(eq(uriAliases), anyString(), any(), any())) - .thenReturn(Collections.singletonList(new ParameterOption("Option", "Aliased"))); + .thenReturn(List.of(new ParameterOption("Option", "Aliased"))); when(configOptionsProviderMockAliased.getParameterOptions(eq(uriDummy), anyString(), any(), any())) .thenReturn(null); when(configOptionsProviderMock.getParameterOptions(eq(uriDummy), anyString(), any(), any())) - .thenReturn(Collections.singletonList(new ParameterOption("Option", "Original"))); + .thenReturn(List.of(new ParameterOption("Option", "Original"))); when(configOptionsProviderMock.getParameterOptions(eq(uriAliases), anyString(), any(), any())).thenReturn(null); } diff --git a/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/ConfigUtilTest.java b/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/ConfigUtilTest.java index ede0062e86..4a0396f0ae 100644 --- a/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/ConfigUtilTest.java +++ b/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/ConfigUtilTest.java @@ -19,9 +19,8 @@ import static org.openhab.core.config.core.ConfigDescriptionParameter.Type.*; import java.math.BigDecimal; import java.net.URI; import java.net.URISyntaxException; -import java.util.Arrays; -import java.util.Collections; import java.util.List; +import java.util.Map; import org.junit.jupiter.api.Test; @@ -124,7 +123,7 @@ public class ConfigUtilTest { .withParameter(configDescriptionParameterBuilder1.build()).build(); ConfigUtil.applyDefaultConfiguration(configuration, configDescription); - verifyValuesOfConfiguration(configuration.get("p1"), 1, Collections.singletonList(new BigDecimal("2.5"))); + verifyValuesOfConfiguration(configuration.get("p1"), 1, List.of(new BigDecimal("2.5"))); } @Test @@ -137,7 +136,7 @@ public class ConfigUtilTest { ConfigUtil.applyDefaultConfiguration(configuration, configDescription); verifyValuesOfConfiguration(configuration.get("p1"), 3, - Arrays.asList(new BigDecimal("2.3"), new BigDecimal("2.4"), new BigDecimal("2.5"))); + List.of(new BigDecimal("2.3"), new BigDecimal("2.4"), new BigDecimal("2.5"))); } @Test @@ -150,7 +149,7 @@ public class ConfigUtilTest { ConfigUtil.applyDefaultConfiguration(configuration, configDescription); verifyValuesOfConfiguration(configuration.get("p1"), 3, - Arrays.asList(new BigDecimal("2.3"), new BigDecimal("2.4"), new BigDecimal("2.5"))); + List.of(new BigDecimal("2.3"), new BigDecimal("2.4"), new BigDecimal("2.5"))); } @Test @@ -162,8 +161,7 @@ public class ConfigUtilTest { .withParameter(configDescriptionParameterBuilder2.build()).build(); ConfigUtil.applyDefaultConfiguration(configuration, configDescription); - verifyValuesOfConfiguration(configuration.get("p2"), 3, - Arrays.asList("first value", "second value", "third value")); + verifyValuesOfConfiguration(configuration.get("p2"), 3, List.of("first value", "second value", "third value")); } private void verifyValuesOfConfiguration(Object subject, int expectedSize, List expectedValues) { @@ -181,21 +179,15 @@ public class ConfigUtilTest { ConfigDescription configDescriptionString = ConfigDescriptionBuilder.create(new URI("thingType:fooThing")) .withParameter(ConfigDescriptionParameterBuilder.create("foo", TEXT).build()).build(); - assertThat( - ConfigUtil.normalizeTypes(Collections.singletonMap("foo", "1"), Arrays.asList(configDescriptionInteger)) - .get("foo"), + assertThat(ConfigUtil.normalizeTypes(Map.of("foo", "1"), List.of(configDescriptionInteger)).get("foo"), is(instanceOf(BigDecimal.class))); - assertThat( - ConfigUtil.normalizeTypes(Collections.singletonMap("foo", "1"), Arrays.asList(configDescriptionString)) - .get("foo"), - is(instanceOf(String.class))); - assertThat( - ConfigUtil.normalizeTypes(Collections.singletonMap("foo", "1"), - Arrays.asList(configDescriptionInteger, configDescriptionString)).get("foo"), - is(instanceOf(BigDecimal.class))); - assertThat( - ConfigUtil.normalizeTypes(Collections.singletonMap("foo", "1"), - Arrays.asList(configDescriptionString, configDescriptionInteger)).get("foo"), + assertThat(ConfigUtil.normalizeTypes(Map.of("foo", "1"), List.of(configDescriptionString)).get("foo"), is(instanceOf(String.class))); + assertThat(ConfigUtil + .normalizeTypes(Map.of("foo", "1"), List.of(configDescriptionInteger, configDescriptionString)) + .get("foo"), is(instanceOf(BigDecimal.class))); + assertThat(ConfigUtil + .normalizeTypes(Map.of("foo", "1"), List.of(configDescriptionString, configDescriptionInteger)) + .get("foo"), is(instanceOf(String.class))); } } diff --git a/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/ConfigurationTest.java b/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/ConfigurationTest.java index 57b877edd0..beeb7058a8 100644 --- a/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/ConfigurationTest.java +++ b/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/ConfigurationTest.java @@ -18,7 +18,6 @@ import static org.hamcrest.core.IsIterableContaining.hasItems; import java.math.BigDecimal; import java.util.ArrayList; -import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -62,7 +61,7 @@ public class ConfigurationTest { configuration.put("booleanField", false); configuration.put("stringField", "test"); configuration.put("enumField", "ON"); - configuration.put("listField", Arrays.asList("one", "two", "three")); + configuration.put("listField", List.of("one", "two", "three")); configuration.put("notExisitingProperty", true); ConfigClass configClass = configuration.as(ConfigClass.class); diff --git a/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/internal/metadata/MetadataConfigDescriptionProviderImplTest.java b/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/internal/metadata/MetadataConfigDescriptionProviderImplTest.java index 22407ddf13..9cb9d29d15 100644 --- a/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/internal/metadata/MetadataConfigDescriptionProviderImplTest.java +++ b/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/internal/metadata/MetadataConfigDescriptionProviderImplTest.java @@ -18,8 +18,8 @@ import static org.mockito.Mockito.when; import static org.openhab.core.config.core.internal.metadata.MetadataConfigDescriptionProviderImpl.*; import java.net.URI; -import java.util.Arrays; import java.util.Collection; +import java.util.List; import java.util.Locale; import org.junit.jupiter.api.BeforeEach; @@ -64,11 +64,11 @@ public class MetadataConfigDescriptionProviderImplTest extends JavaTest { when(mockProviderRestricted.getNamespace()).thenReturn(RESTRICTED); when(mockProviderRestricted.getDescription(any())).thenReturn("Restricted"); - when(mockProviderRestricted.getParameterOptions(any())).thenReturn(Arrays.asList( // + when(mockProviderRestricted.getParameterOptions(any())).thenReturn(List.of( // new ParameterOption("dimmer", "Dimmer"), // new ParameterOption("switch", "Switch") // )); - when(mockProviderRestricted.getParameters(eq("dimmer"), any())).thenReturn(Arrays.asList( // + when(mockProviderRestricted.getParameters(eq("dimmer"), any())).thenReturn(List.of( // ConfigDescriptionParameterBuilder.create("width", Type.INTEGER).build(), // ConfigDescriptionParameterBuilder.create("height", Type.INTEGER).build() // )); diff --git a/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/internal/validation/ConfigDescriptionValidatorTest.java b/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/internal/validation/ConfigDescriptionValidatorTest.java index a7105663d4..0e5ccd2e1d 100644 --- a/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/internal/validation/ConfigDescriptionValidatorTest.java +++ b/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/internal/validation/ConfigDescriptionValidatorTest.java @@ -23,7 +23,6 @@ import java.lang.reflect.Field; import java.math.BigDecimal; import java.net.URI; import java.net.URISyntaxException; -import java.util.Collections; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -243,7 +242,7 @@ public class ConfigDescriptionValidatorTest { } void assertRequired(String parameterName) { - List expected = Collections.singletonList(new ConfigValidationMessage(parameterName, + List expected = List.of(new ConfigValidationMessage(parameterName, MessageKey.PARAMETER_REQUIRED.defaultMessage, MessageKey.PARAMETER_REQUIRED.key)); try { @@ -326,8 +325,8 @@ public class ConfigDescriptionValidatorTest { } void assertMinMax(String parameterName, Object value, MessageKey msgKey, String minMax) { - List expected = Collections - .singletonList(new ConfigValidationMessage(parameterName, msgKey.defaultMessage, msgKey.key, minMax)); + List expected = List + .of(new ConfigValidationMessage(parameterName, msgKey.defaultMessage, msgKey.key, minMax)); try { params.put(parameterName, value); configDescriptionValidator.validate(params, CONFIG_DESCRIPTION_URI); @@ -386,7 +385,7 @@ public class ConfigDescriptionValidatorTest { } void assertType(String parameterName, Type type) { - List expected = Collections.singletonList(new ConfigValidationMessage(parameterName, + List expected = List.of(new ConfigValidationMessage(parameterName, MessageKey.DATA_TYPE_VIOLATED.defaultMessage, MessageKey.DATA_TYPE_VIOLATED.key, type)); try { params.put(parameterName, INVALID); @@ -403,8 +402,8 @@ public class ConfigDescriptionValidatorTest { @Test public void assertValidationThrowsExceptionContainingMessagesForInvalidPatternForTxtConfigParameters() { - List expected = Collections.singletonList( - new ConfigValidationMessage(TXT_PATTERN_PARAM_NAME, MessageKey.PATTERN_VIOLATED.defaultMessage, + List expected = List + .of(new ConfigValidationMessage(TXT_PATTERN_PARAM_NAME, MessageKey.PATTERN_VIOLATED.defaultMessage, MessageKey.PATTERN_VIOLATED.key, String.valueOf(MAX_VIOLATED), PATTERN)); try { params.put(TXT_PATTERN_PARAM_NAME, String.valueOf(MAX_VIOLATED)); @@ -455,9 +454,9 @@ public class ConfigDescriptionValidatorTest { @Test public void assertValidationProvidesOnlyOneMessagePerParameterAlthoughMultipleViolationsOccur() { - List expected = Collections.singletonList(new ConfigValidationMessage( - TXT_MAX_PATTERN_PARAM_NAME, MessageKey.MAX_VALUE_TXT_VIOLATED.defaultMessage, - MessageKey.MAX_VALUE_TXT_VIOLATED.key, MAX.toString())); + List expected = List.of(new ConfigValidationMessage(TXT_MAX_PATTERN_PARAM_NAME, + MessageKey.MAX_VALUE_TXT_VIOLATED.defaultMessage, MessageKey.MAX_VALUE_TXT_VIOLATED.key, + MAX.toString())); try { params.put(TXT_MAX_PATTERN_PARAM_NAME, String.valueOf(MAX_VIOLATED)); configDescriptionValidator.validate(params, CONFIG_DESCRIPTION_URI); diff --git a/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/internal/validation/ConfigValidationExceptionTest.java b/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/internal/validation/ConfigValidationExceptionTest.java index dac5164525..e217f08b63 100644 --- a/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/internal/validation/ConfigValidationExceptionTest.java +++ b/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/internal/validation/ConfigValidationExceptionTest.java @@ -12,8 +12,6 @@ */ package org.openhab.core.config.core.internal.validation; -import static java.util.Collections.*; -import static java.util.stream.Collectors.toList; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -23,7 +21,6 @@ import java.util.Collection; import java.util.List; import java.util.Locale; import java.util.Map; -import java.util.stream.Stream; import org.eclipse.jdt.annotation.Nullable; import org.junit.jupiter.api.Test; @@ -59,11 +56,11 @@ public class ConfigValidationExceptionTest { MAX); private static final ConfigValidationMessage MSG1 = createMessage(PARAM1, TXT_DEFAULT1, - MessageKey.PARAMETER_REQUIRED.key, emptyList()); + MessageKey.PARAMETER_REQUIRED.key, List.of()); private static final ConfigValidationMessage MSG2 = createMessage(PARAM2, TXT_DEFAULT2, - MessageKey.MAX_VALUE_TXT_VIOLATED.key, singletonList(MAX)); + MessageKey.MAX_VALUE_TXT_VIOLATED.key, List.of(MAX)); - private static final List ALL = Stream.of(MSG1, MSG2).collect(toList()); + private static final List ALL = List.of(MSG1, MSG2); private static final Bundle BUNDLE = Mockito.mock(Bundle.class); diff --git a/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/status/ConfigStatusInfoTest.java b/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/status/ConfigStatusInfoTest.java index 8e3e664fad..f98de5a636 100644 --- a/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/status/ConfigStatusInfoTest.java +++ b/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/status/ConfigStatusInfoTest.java @@ -12,13 +12,14 @@ */ package org.openhab.core.config.core.status; -import static java.util.Collections.*; -import static java.util.stream.Collectors.*; +import static java.util.Collections.emptySet; +import static java.util.stream.Collectors.toList; import static org.hamcrest.CoreMatchers.*; import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.jupiter.api.Assertions.assertThrows; import java.util.List; +import java.util.Set; import java.util.stream.Stream; import org.junit.jupiter.api.Test; @@ -129,14 +130,9 @@ public class ConfigStatusInfoTest { assertThat(info.getConfigStatusMessages(PARAM3, PARAM4).size(), is(2)); assertThat(info.getConfigStatusMessages(PARAM3, PARAM4), hasItems(MSG3, MSG4)); - assertThat(info - .getConfigStatusMessages(unmodifiableSet(Stream.of(Type.INFORMATION, Type.WARNING).collect(toSet())), - unmodifiableSet(Stream.of(PARAM1, PARAM6).collect(toSet()))) - .size(), is(5)); - assertThat( - info.getConfigStatusMessages( - unmodifiableSet(Stream.of(Type.INFORMATION, Type.WARNING).collect(toSet())), - unmodifiableSet(Stream.of(PARAM1, PARAM6).collect(toSet()))), + assertThat(info.getConfigStatusMessages(Set.of(Type.INFORMATION, Type.WARNING), Set.of(PARAM1, PARAM6)).size(), + is(5)); + assertThat(info.getConfigStatusMessages(Set.of(Type.INFORMATION, Type.WARNING), Set.of(PARAM1, PARAM6)), hasItems(MSG1, MSG2, MSG3, MSG4, MSG6)); assertThat(info.getConfigStatusMessages("unknown").size(), is(0)); diff --git a/bundles/org.openhab.core.config.discovery/src/main/java/org/openhab/core/config/discovery/AbstractDiscoveryService.java b/bundles/org.openhab.core.config.discovery/src/main/java/org/openhab/core/config/discovery/AbstractDiscoveryService.java index a61901c295..5c0f67e049 100644 --- a/bundles/org.openhab.core.config.discovery/src/main/java/org/openhab/core/config/discovery/AbstractDiscoveryService.java +++ b/bundles/org.openhab.core.config.discovery/src/main/java/org/openhab/core/config/discovery/AbstractDiscoveryService.java @@ -13,10 +13,8 @@ package org.openhab.core.config.discovery; import java.util.Collection; -import java.util.Collections; import java.util.Date; import java.util.HashMap; -import java.util.HashSet; import java.util.Map; import java.util.Set; import java.util.concurrent.CancellationException; @@ -88,18 +86,11 @@ public abstract class AbstractDiscoveryService implements DiscoveryService { */ public AbstractDiscoveryService(@Nullable Set supportedThingTypes, int timeout, boolean backgroundDiscoveryEnabledByDefault) throws IllegalArgumentException { - if (supportedThingTypes == null) { - this.supportedThingTypes = Collections.emptySet(); - } else { - this.supportedThingTypes = Collections.unmodifiableSet(new HashSet<>(supportedThingTypes)); - } - if (timeout < 0) { throw new IllegalArgumentException("The timeout must be >= 0!"); } - + this.supportedThingTypes = supportedThingTypes == null ? Set.of() : Set.copyOf(supportedThingTypes); this.timeout = timeout; - this.backgroundDiscoveryEnabled = backgroundDiscoveryEnabledByDefault; } diff --git a/bundles/org.openhab.core.config.discovery/src/main/java/org/openhab/core/config/discovery/internal/console/InboxConsoleCommandExtension.java b/bundles/org.openhab.core.config.discovery/src/main/java/org/openhab/core/config/discovery/internal/console/InboxConsoleCommandExtension.java index 32c751ea39..fbac3afa39 100644 --- a/bundles/org.openhab.core.config.discovery/src/main/java/org/openhab/core/config/discovery/internal/console/InboxConsoleCommandExtension.java +++ b/bundles/org.openhab.core.config.discovery/src/main/java/org/openhab/core/config/discovery/internal/console/InboxConsoleCommandExtension.java @@ -14,7 +14,6 @@ package org.openhab.core.config.discovery.internal.console; import static org.openhab.core.config.discovery.inbox.InboxPredicates.*; -import java.util.Arrays; import java.util.Date; import java.util.List; import java.util.Map; @@ -193,12 +192,12 @@ public class InboxConsoleCommandExtension extends AbstractConsoleCommandExtensio @Override public List getUsages() { - return Arrays.asList(new String[] { buildCommandUsage(SUBCMD_LIST, "lists all current inbox entries"), + return List.of(buildCommandUsage(SUBCMD_LIST, "lists all current inbox entries"), buildCommandUsage(SUBCMD_LIST_IGNORED, "lists all ignored inbox entries"), buildCommandUsage(SUBCMD_APPROVE + "