Simplify code that creates List, Map and Set objects (#3836)

Simplifies the code by using List.of, List.copyOf etc. where possible which results in less code and imports.

Signed-off-by: Wouter Born <github@maindrain.net>
This commit is contained in:
Wouter Born
2023-10-09 18:00:00 +02:00
committed by GitHub
parent 8c8f4112ea
commit e8e1c9fe73
165 changed files with 387 additions and 594 deletions
@@ -189,7 +189,7 @@ public class CommunityMarketplaceAddonService extends AbstractRemoteAddonService
List<DiscourseUser> users = pages.stream().flatMap(p -> Stream.of(p.users)).toList();
pages.stream().flatMap(p -> Stream.of(p.topicList.topics))
.filter(t -> showUnpublished || Arrays.asList(t.tags).contains(PUBLISHED_TAG))
.filter(t -> showUnpublished || List.of(t.tags).contains(PUBLISHED_TAG))
.map(t -> Optional.ofNullable(convertTopicItemToAddon(t, users)))
.forEach(a -> a.ifPresent(addons::add));
} catch (Exception e) {
@@ -12,7 +12,6 @@
*/
package org.openhab.core.addon;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.Set;
@@ -196,7 +195,7 @@ public class AddonInfo implements Identifiable<String> {
}
public Builder withCountries(@Nullable String countries) {
this.countries = countries == null || countries.isBlank() ? List.of() : Arrays.asList(countries.split(","));
this.countries = countries == null || countries.isBlank() ? List.of() : List.of(countries.split(","));
return this;
}
@@ -66,7 +66,7 @@ public class AudioConsoleCommandExtension extends AbstractConsoleCommandExtensio
@Override
public List<String> getUsages() {
return Arrays.asList(new String[] {
return List.of(
buildCommandUsage(SUBCMD_PLAY + " [<sink>] <filename>",
"plays a sound file from the sounds folder through the optionally specified audio sink(s)"),
buildCommandUsage(SUBCMD_PLAY + " <sink> <filename> <volume>",
@@ -79,7 +79,7 @@ public class AudioConsoleCommandExtension extends AbstractConsoleCommandExtensio
buildCommandUsage(SUBCMD_SYNTHESIZE + " <sink> \"<melody>\" <volume>",
"synthesize a tone melody and play it through the optionally specified audio sink(s) with the specified volume"),
buildCommandUsage(SUBCMD_SOURCES, "lists the audio sources"),
buildCommandUsage(SUBCMD_SINKS, "lists the audio sinks") });
buildCommandUsage(SUBCMD_SINKS, "lists the audio sinks"));
}
@Override
@@ -22,7 +22,6 @@ import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.util.Collection;
import java.util.Collections;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
@@ -236,7 +235,7 @@ public class AudioManagerTest {
audioManager.modified(Map.of(AudioManagerImpl.CONFIG_DEFAULT_SOURCE, audioSource.getId()));
} else {
// just to make sure there is no default source
audioManager.modified(Collections.emptyMap());
audioManager.modified(Map.of());
}
assertThat(String.format("The source %s was not registered", audioSource.getId()), audioManager.getSource(),
@@ -14,7 +14,6 @@ package org.openhab.core.auth.jaas.internal;
import java.io.IOException;
import java.security.Principal;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
@@ -73,7 +72,7 @@ public class JaasAuthenticationProvider implements AuthenticationProvider {
final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
try {
Principal userPrincipal = new GenericUser(name);
Subject subject = new Subject(true, Set.of(userPrincipal), Collections.emptySet(), Set.of(userCredentials));
Subject subject = new Subject(true, Set.of(userPrincipal), Set.of(), Set.of(userCredentials));
Thread.currentThread().setContextClassLoader(ManagedUserLoginModule.class.getClassLoader());
LoginContext loginContext = new LoginContext(realmName, subject, new CallbackHandler() {
@@ -14,9 +14,9 @@ package org.openhab.core.automation.module.script.rulesupport.internal;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
@@ -134,7 +134,7 @@ public class RuleSupportScriptExtension implements ScriptExtensionProvider {
@Override
public Collection<String> getDefaultPresets() {
return Collections.emptyList();
return List.of();
}
@Override
@@ -166,7 +166,7 @@ public abstract class SimpleRule implements Rule, SimpleRuleActionHandler {
@Override
public List<Condition> getConditions() {
return conditions == null ? Collections.emptyList() : conditions;
return conditions == null ? List.of() : conditions;
}
/**
@@ -180,12 +180,12 @@ public abstract class SimpleRule implements Rule, SimpleRuleActionHandler {
@Override
public List<Action> getActions() {
return actions == null ? Collections.emptyList() : actions;
return actions == null ? List.of() : actions;
}
@Override
public List<Trigger> getTriggers() {
return triggers == null ? Collections.emptyList() : triggers;
return triggers == null ? List.of() : triggers;
}
/**
@@ -227,7 +227,7 @@ public abstract class SimpleRule implements Rule, SimpleRuleActionHandler {
} else if (Action.class == moduleClazz) {
result = (List<T>) actions;
} else {
result = Collections.emptyList();
result = List.of();
}
return result;
}
@@ -14,7 +14,6 @@ package org.openhab.core.automation.module.script;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -71,7 +70,7 @@ public class LifecycleScriptExtensionProvider implements ScriptExtensionProvider
}
}
return Collections.emptyMap();
return Map.of();
}
@Override
@@ -18,7 +18,6 @@ import java.net.URI;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Map;
@@ -257,7 +256,7 @@ public class ScriptTransformationService implements TransformationService, Confi
return List.of(configDescription);
}
return Collections.emptyList();
return List.of();
}
@Override
@@ -220,7 +220,7 @@ public class DefaultScriptScopeProvider implements ScriptExtensionProvider {
if (PRESET_DEFAULT.equals(preset)) {
return Collections.unmodifiableMap(elements);
}
return Collections.emptyMap();
return Map.of();
}
@Override
@@ -19,7 +19,6 @@ import static org.mockito.ArgumentMatchers.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
@@ -75,8 +74,7 @@ public class ScriptTransformationServiceTest {
@BeforeEach
public void setUp() throws ScriptException {
Map<String, Object> properties = new HashMap<>();
properties.put(ScriptTransformationService.SCRIPT_TYPE_PROPERTY_NAME, SCRIPT_LANGUAGE);
Map<String, Object> properties = Map.of(ScriptTransformationService.SCRIPT_TYPE_PROPERTY_NAME, SCRIPT_LANGUAGE);
service = new ScriptTransformationService(transformationRegistry, mock(ConfigDescriptionRegistry.class),
scriptEngineManager, properties);
@@ -149,7 +149,7 @@ public class RuleImpl implements Rule {
* @param ruleTags the {@link RuleImpl}'s assigned tags.
*/
public void setTags(@Nullable Set<String> ruleTags) {
tags = ruleTags == null ? Collections.emptySet() : Collections.unmodifiableSet(ruleTags);
tags = ruleTags == null ? Set.of() : Collections.unmodifiableSet(ruleTags);
}
@Override
@@ -205,7 +205,7 @@ public class RuleImpl implements Rule {
* properties of the {@link RuleImpl}.
*/
public void setConfigurationDescriptions(@Nullable List<ConfigDescriptionParameter> configDescriptions) {
this.configDescriptions = configDescriptions == null ? Collections.emptyList()
this.configDescriptions = configDescriptions == null ? List.of()
: Collections.unmodifiableList(configDescriptions);
}
@@ -220,7 +220,7 @@ public class RuleImpl implements Rule {
* @param conditions a list with the conditions that should belong to this {@link RuleImpl}.
*/
public void setConditions(@Nullable List<Condition> conditions) {
this.conditions = conditions == null ? Collections.emptyList() : Collections.unmodifiableList(conditions);
this.conditions = conditions == null ? List.of() : Collections.unmodifiableList(conditions);
}
@Override
@@ -239,7 +239,7 @@ public class RuleImpl implements Rule {
* @param actions a list with the actions that should belong to this {@link RuleImpl}.
*/
public void setActions(@Nullable List<Action> actions) {
this.actions = actions == null ? Collections.emptyList() : Collections.unmodifiableList(actions);
this.actions = actions == null ? List.of() : Collections.unmodifiableList(actions);
}
/**
@@ -248,7 +248,7 @@ public class RuleImpl implements Rule {
* @param triggers a list with the triggers that should belong to this {@link RuleImpl}.
*/
public void setTriggers(@Nullable List<Trigger> triggers) {
this.triggers = triggers == null ? Collections.emptyList() : Collections.unmodifiableList(triggers);
this.triggers = triggers == null ? List.of() : Collections.unmodifiableList(triggers);
}
@Override
@@ -20,7 +20,6 @@ import java.io.InputStreamReader;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
@@ -146,8 +145,7 @@ public class CommandlineModuleTypeProvider extends AbstractCommandProvider<Modul
@Override
public Collection<ModuleType> getModuleTypes(@Nullable Locale locale) {
synchronized (providedObjectsHolder) {
return !providedObjectsHolder.isEmpty() ? providedObjectsHolder.values()
: Collections.<ModuleType> emptyList();
return !providedObjectsHolder.isEmpty() ? providedObjectsHolder.values() : List.of();
}
}
@@ -14,7 +14,6 @@ package org.openhab.core.automation.internal.parser.gson;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -68,6 +67,6 @@ public class RuleGSONParser extends AbstractGSONParser<Rule> {
} catch (IOException e) {
}
}
return Collections.emptySet();
return Set.of();
}
}
@@ -14,7 +14,6 @@ package org.openhab.core.automation.internal.parser.gson;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -68,6 +67,6 @@ public class TemplateGSONParser extends AbstractGSONParser<Template> {
} catch (IOException e) {
}
}
return Collections.emptySet();
return Set.of();
}
}
@@ -21,7 +21,6 @@ import java.net.URISyntaxException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.LinkedList;
import java.util.List;
@@ -393,7 +392,7 @@ public abstract class AbstractResourceBundleProvider<@NonNull E> {
return config;
}
}
return Collections.emptyList();
return List.of();
}
/**
@@ -433,7 +432,7 @@ public abstract class AbstractResourceBundleProvider<@NonNull E> {
}
}
}
return Collections.emptySet();
return Set.of();
}
@SuppressWarnings("unchecked")
@@ -15,7 +15,6 @@ package org.openhab.core.automation.internal.provider;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.Collections;
import java.util.Enumeration;
import java.util.List;
import java.util.Set;
@@ -118,11 +117,11 @@ public class RuleResourceBundleImporter extends AbstractResourceBundleProvider<R
if (parser != null) {
Set<Rule> parsedObjects = parseData(parser, url, bundle);
if (!parsedObjects.isEmpty()) {
addNewProvidedObjects(Collections.emptyList(), Collections.emptyList(), parsedObjects);
addNewProvidedObjects(List.of(), List.of(), parsedObjects);
}
}
}
putNewPortfolio(vendor, Collections.emptyList());
putNewPortfolio(vendor, List.of());
}
}
@@ -13,8 +13,8 @@
package org.openhab.core.automation.internal.provider.file;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import org.eclipse.jdt.annotation.NonNullByDefault;
@@ -56,7 +56,7 @@ public abstract class ModuleTypeFileProvider extends AbstractFileProvider<Module
public <T extends ModuleType> Collection<T> getModuleTypes(@Nullable Locale locale) {
Collection<ModuleType> values = providedObjectsHolder.values();
if (values.isEmpty()) {
return Collections.emptyList();
return List.of();
}
return (Collection<T>) new LinkedList<>(values);
}
@@ -13,8 +13,8 @@
package org.openhab.core.automation.internal.provider.file;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import org.eclipse.jdt.annotation.NonNullByDefault;
@@ -55,7 +55,7 @@ public abstract class TemplateFileProvider extends AbstractFileProvider<RuleTemp
public Collection<RuleTemplate> getTemplates(@Nullable Locale locale) {
Collection<RuleTemplate> values = providedObjectsHolder.values();
if (values.isEmpty()) {
return Collections.emptyList();
return List.of();
}
return new LinkedList<>(values);
}
@@ -33,8 +33,8 @@ import org.openhab.core.automation.type.Output;
@NonNullByDefault
public class WrappedAction extends WrappedModule<Action, ActionHandler> {
private Set<Connection> connections = Collections.emptySet();
private Map<String, String> inputs = Collections.emptyMap();
private Set<Connection> connections = Set.of();
private Map<String, String> inputs = Map.of();
public WrappedAction(final Action action) {
super(action);
@@ -47,7 +47,7 @@ public class WrappedAction extends WrappedModule<Action, ActionHandler> {
* @param connections the set of connections for this action
*/
public void setConnections(@Nullable Set<Connection> connections) {
this.connections = connections == null ? Collections.emptySet() : connections;
this.connections = connections == null ? Set.of() : connections;
}
public Set<Connection> getConnections() {
@@ -71,6 +71,6 @@ public class WrappedAction extends WrappedModule<Action, ActionHandler> {
* @param inputs map that contains the inputs for this action.
*/
public void setInputs(@Nullable Map<String, String> inputs) {
this.inputs = inputs == null ? Collections.emptyMap() : Collections.unmodifiableMap(inputs);
this.inputs = inputs == null ? Map.of() : Collections.unmodifiableMap(inputs);
}
}
@@ -33,8 +33,8 @@ import org.openhab.core.automation.type.Output;
@NonNullByDefault
public class WrappedCondition extends WrappedModule<Condition, ConditionHandler> {
private Map<String, String> inputs = Collections.emptyMap();
private Set<Connection> connections = Collections.emptySet();
private Map<String, String> inputs = Map.of();
private Set<Connection> connections = Set.of();
public WrappedCondition(final Condition condition) {
super(condition);
@@ -47,7 +47,7 @@ public class WrappedCondition extends WrappedModule<Condition, ConditionHandler>
* @param connections the set of connections for this condition
*/
public void setConnections(@Nullable Set<Connection> connections) {
this.connections = connections == null ? Collections.emptySet() : connections;
this.connections = connections == null ? Set.of() : connections;
}
public Set<Connection> getConnections() {
@@ -71,6 +71,6 @@ public class WrappedCondition extends WrappedModule<Condition, ConditionHandler>
* @param inputs map that contains the inputs for this condition.
*/
public void setInputs(@Nullable Map<String, String> inputs) {
this.inputs = inputs == null ? Collections.emptyMap() : Collections.unmodifiableMap(inputs);
this.inputs = inputs == null ? Map.of() : Collections.unmodifiableMap(inputs);
}
}
@@ -18,7 +18,6 @@ import java.lang.reflect.Parameter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
@@ -68,7 +67,7 @@ public class AnnotationActionModuleTypeHelper {
ActionScope scope = clazz.getAnnotation(ActionScope.class);
return parseAnnotations(scope.name(), actionProvider);
}
return Collections.emptyList();
return List.of();
}
public Collection<ModuleInformation> parseAnnotations(String name, Object actionProvider) {
@@ -112,8 +111,7 @@ public class AnnotationActionModuleTypeHelper {
Annotation[] paramAnnotations = annotations[i];
if (paramAnnotations.length == 0) {
// we do not have an annotation with a name for this parameter
inputs.add(new Input("p" + i, param.getType().getCanonicalName(), "", "", Collections.emptySet(), false,
"", ""));
inputs.add(new Input("p" + i, param.getType().getCanonicalName(), "", "", Set.of(), false, "", ""));
} else if (paramAnnotations.length == 1) {
Annotation a = paramAnnotations[0];
if (a instanceof ActionInput inp) {
@@ -14,7 +14,6 @@ package org.openhab.core.automation.template;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.UUID;
@@ -117,13 +116,13 @@ public class RuleTemplate implements Template {
this.uid = UID == null ? UUID.randomUUID().toString() : UID;
this.label = label;
this.description = description;
this.triggers = triggers == null ? Collections.emptyList() : Collections.unmodifiableList(triggers);
this.conditions = conditions == null ? Collections.emptyList() : Collections.unmodifiableList(conditions);
this.actions = actions == null ? Collections.emptyList() : Collections.unmodifiableList(actions);
this.configDescriptions = configDescriptions == null ? Collections.emptyList()
this.triggers = triggers == null ? List.of() : Collections.unmodifiableList(triggers);
this.conditions = conditions == null ? List.of() : Collections.unmodifiableList(conditions);
this.actions = actions == null ? List.of() : Collections.unmodifiableList(actions);
this.configDescriptions = configDescriptions == null ? List.of()
: Collections.unmodifiableList(configDescriptions);
this.visibility = visibility == null ? Visibility.VISIBLE : visibility;
this.tags = tags == null ? new HashSet<>() : new HashSet<>(tags);
this.tags = tags == null ? Set.of() : Collections.unmodifiableSet(tags);
}
/**
@@ -226,7 +225,7 @@ public class RuleTemplate implements Template {
} else if (Action.class == moduleClazz) {
result = (List<T>) actions;
} else {
result = Collections.emptyList();
result = List.of();
}
return result;
}
@@ -81,11 +81,11 @@ public class ActionType extends ModuleType {
}
/**
* Creates an instance of {@link ActionType} with UID, label, description, a {@link Set} of tags, visibility,
* Creates an instance of {@link ActionType} with uid, label, description, a {@link Set} of tags, visibility,
* a {@link List} of configuration descriptions, a {@link List} of {@link Input} descriptions and a {@link List}
* of {@link Output} descriptions.
*
* @param UID the {@link ActionType}'s identifier, or {@code null} if a random identifier should be
* @param uid the {@link ActionType}'s identifier, or {@code null} if a random identifier should be
* generated.
* @param configDescriptions describing meta-data for the configuration of the future {@link Action} instances.
* @param label is a short and accurate name of the {@link ActionType}.
@@ -99,10 +99,10 @@ public class ActionType extends ModuleType {
* @param outputs a {@link List} with {@link Output} meta-information descriptions of the future
* {@link Action} instances.
*/
public ActionType(@Nullable String UID, @Nullable List<ConfigDescriptionParameter> configDescriptions,
public ActionType(@Nullable String uid, @Nullable List<ConfigDescriptionParameter> configDescriptions,
@Nullable String label, @Nullable String description, @Nullable Set<String> tags,
@Nullable Visibility visibility, @Nullable List<Input> inputs, @Nullable List<Output> outputs) {
super(UID, configDescriptions, label, description, tags, visibility);
super(uid, configDescriptions, label, description, tags, visibility);
this.inputs = inputs != null ? Collections.unmodifiableList(inputs) : List.of();
this.outputs = outputs != null ? Collections.unmodifiableList(outputs) : List.of();
}
@@ -40,7 +40,7 @@ public class CompositeActionType extends ActionType {
* Creates an instance of {@code CompositeActionType} with list of {@link Action}s. It initializes only base
* properties of the {@code CompositeActionType}.
*
* @param UID the {@link ActionType}'s identifier, or {@code null} if a random identifier should be
* @param uid the {@link ActionType}'s identifier, or {@code null} if a random identifier should be
* generated.
* @param configDescriptions describing meta-data for the configuration of the future {@link Action} instances.
* @param children is a {@link List} of {@link Action}s.
@@ -50,17 +50,17 @@ public class CompositeActionType extends ActionType {
* {@link Action} instances.
* @param children is a {@link List} of {@link Action}s.
*/
public CompositeActionType(@Nullable String UID, @Nullable List<ConfigDescriptionParameter> configDescriptions,
public CompositeActionType(@Nullable String uid, @Nullable List<ConfigDescriptionParameter> configDescriptions,
@Nullable List<Input> inputs, @Nullable List<Output> outputs, @Nullable List<Action> children) {
super(UID, configDescriptions, inputs, outputs);
this.children = children != null ? Collections.unmodifiableList(children) : Collections.emptyList();
super(uid, configDescriptions, inputs, outputs);
this.children = children != null ? Collections.unmodifiableList(children) : List.of();
}
/**
* Creates an instance of {@code CompositeActionType} with list of {@link Action}s. It initializes all properties of
* the {@code CompositeActionType}.
*
* @param UID the {@link ActionType}'s identifier, or {@code null} if a random identifier should be
* @param uid the {@link ActionType}'s identifier, or {@code null} if a random identifier should be
* generated.
* @param configDescriptions describing meta-data for the configuration of the future {@link Action} instances.
* @param label a short and accurate, human-readable label of the {@link ActionType}.
@@ -75,12 +75,12 @@ public class CompositeActionType extends ActionType {
* {@link Action} instances.
* @param children is a {@link List} of {@link Action}s.
*/
public CompositeActionType(@Nullable String UID, @Nullable List<ConfigDescriptionParameter> configDescriptions,
public CompositeActionType(@Nullable String uid, @Nullable List<ConfigDescriptionParameter> configDescriptions,
@Nullable String label, @Nullable String description, @Nullable Set<String> tags,
@Nullable Visibility visibility, @Nullable List<Input> inputs, @Nullable List<Output> outputs,
@Nullable List<Action> children) {
super(UID, configDescriptions, label, description, tags, visibility, inputs, outputs);
this.children = children != null ? Collections.unmodifiableList(children) : Collections.emptyList();
super(uid, configDescriptions, label, description, tags, visibility, inputs, outputs);
this.children = children != null ? Collections.unmodifiableList(children) : List.of();
}
/**
@@ -39,7 +39,7 @@ public class CompositeConditionType extends ConditionType {
* Creates an instance of {@code CompositeConditionType} with ordered set of {@link Condition}s. It initializes
* only base properties of the {@code CompositeConditionType}.
*
* @param UID is the {@link ConditionType}'s identifier, or {@code null} if a random identifier
* @param uid is the {@link ConditionType}'s identifier, or {@code null} if a random identifier
* should be generated.
* @param configDescriptions is a {@link List} of configuration descriptions describing meta-data for the
* configuration of the future {@link Condition} instances.
@@ -47,17 +47,17 @@ public class CompositeConditionType extends ConditionType {
* {@link Condition} instances.
* @param children is a {@link List} of {@link Condition}s.
*/
public CompositeConditionType(@Nullable String UID, @Nullable List<ConfigDescriptionParameter> configDescriptions,
public CompositeConditionType(@Nullable String uid, @Nullable List<ConfigDescriptionParameter> configDescriptions,
@Nullable List<Input> inputs, @Nullable List<Condition> children) {
super(UID, configDescriptions, inputs);
this.children = children != null ? Collections.unmodifiableList(children) : Collections.emptyList();
super(uid, configDescriptions, inputs);
this.children = children != null ? Collections.unmodifiableList(children) : List.of();
}
/**
* Creates an instance of {@code CompositeConditionType} with ordered set of {@link Condition}s. It initializes
* all properties of the {@code CompositeConditionType}.
*
* @param UID is the {@link ConditionType}'s identifier, or {@code null} if a random identifier
* @param uid is the {@link ConditionType}'s identifier, or {@code null} if a random identifier
* should be generated.
* @param configDescriptions is a {@link List} of configuration descriptions describing meta-data for the
* configuration of the future {@link Condition} instances.
@@ -74,11 +74,11 @@ public class CompositeConditionType extends ConditionType {
* {@link Condition} instances.
* @param children is a {@link List} of {@link Condition}s.
*/
public CompositeConditionType(@Nullable String UID, @Nullable List<ConfigDescriptionParameter> configDescriptions,
public CompositeConditionType(@Nullable String uid, @Nullable List<ConfigDescriptionParameter> configDescriptions,
@Nullable String label, @Nullable String description, @Nullable Set<String> tags,
@Nullable Visibility visibility, @Nullable List<Input> inputs, @Nullable List<Condition> children) {
super(UID, configDescriptions, label, description, tags, visibility, inputs);
this.children = children != null ? Collections.unmodifiableList(children) : Collections.emptyList();
super(uid, configDescriptions, label, description, tags, visibility, inputs);
this.children = children != null ? Collections.unmodifiableList(children) : List.of();
}
/**
@@ -39,7 +39,7 @@ public class CompositeTriggerType extends TriggerType {
* Creates an instance of {@code CompositeTriggerType} with ordered set of {@link Trigger} modules. It initializes
* only base properties of the {@code CompositeTriggerType}.
*
* @param UID the {@link TriggerType}'s identifier, or {@code null} if a random identifier should be
* @param uid the {@link TriggerType}'s identifier, or {@code null} if a random identifier should be
* generated.
* @param configDescriptions describing meta-data for the configuration of the future {@link Trigger} instances.
* @param outputs a {@link List} with {@link Output} meta-information descriptions of the future
@@ -47,10 +47,10 @@ public class CompositeTriggerType extends TriggerType {
* @param children is a {@link List} of {@link Trigger} modules.
*
*/
public CompositeTriggerType(@Nullable String UID, @Nullable List<ConfigDescriptionParameter> configDescriptions,
public CompositeTriggerType(@Nullable String uid, @Nullable List<ConfigDescriptionParameter> configDescriptions,
@Nullable List<Output> outputs, @Nullable List<Trigger> children) {
super(UID, configDescriptions, outputs);
this.children = children != null ? Collections.unmodifiableList(children) : Collections.emptyList();
super(uid, configDescriptions, outputs);
this.children = children != null ? Collections.unmodifiableList(children) : List.of();
}
/**
@@ -75,7 +75,7 @@ public class CompositeTriggerType extends TriggerType {
@Nullable String label, @Nullable String description, @Nullable Set<String> tags,
@Nullable Visibility visibility, @Nullable List<Output> outputs, @Nullable List<Trigger> children) {
super(UID, configDescriptions, label, description, tags, visibility, outputs);
this.children = children != null ? Collections.unmodifiableList(children) : Collections.emptyList();
this.children = children != null ? Collections.unmodifiableList(children) : List.of();
}
/**
@@ -41,22 +41,22 @@ public class ConditionType extends ModuleType {
* Creates an instance of {@link ConditionType} with base properties - UID, a {@link List} of configuration
* descriptions and a {@link List} of {@link Input} descriptions.
*
* @param UID the {@link ConditionType}'s identifier, or {@code null} if a random identifier should
* @param uid the {@link ConditionType}'s identifier, or {@code null} if a random identifier should
* be generated.
* @param configDescriptions describing meta-data for the configuration of the future {@link Condition} instances.
* @param inputs a {@link List} with {@link Input} meta-information descriptions of the future
* {@link Condition} instances.
*/
public ConditionType(@Nullable String UID, @Nullable List<ConfigDescriptionParameter> configDescriptions,
public ConditionType(@Nullable String uid, @Nullable List<ConfigDescriptionParameter> configDescriptions,
@Nullable List<Input> inputs) {
this(UID, configDescriptions, null, null, null, null, inputs);
this(uid, configDescriptions, null, null, null, null, inputs);
}
/**
* Creates an instance of {@link ConditionType} with UID, label, description, a {@link Set} of tags, visibility,
* Creates an instance of {@link ConditionType} with uid, label, description, a {@link Set} of tags, visibility,
* a {@link List} of configuration descriptions and a {@link List} of {@link Input} descriptions.
*
* @param UID the {@link ConditionType}'s identifier, or {@code null} if a random identifier should
* @param uid the {@link ConditionType}'s identifier, or {@code null} if a random identifier should
* be generated.
* @param configDescriptions describing meta-data for the configuration of the future {@link Condition} instances.
* @param label a short and accurate, human-readable label of the {@link ConditionType}.
@@ -69,10 +69,10 @@ public class ConditionType extends ModuleType {
* @param inputs a {@link List} with {@link Input} meta-information descriptions of the future
* {@link Condition} instances.
*/
public ConditionType(@Nullable String UID, @Nullable List<ConfigDescriptionParameter> configDescriptions,
public ConditionType(@Nullable String uid, @Nullable List<ConfigDescriptionParameter> configDescriptions,
@Nullable String label, @Nullable String description, @Nullable Set<String> tags,
@Nullable Visibility visibility, @Nullable List<Input> inputs) {
super(UID, configDescriptions, label, description, tags, visibility);
super(uid, configDescriptions, label, description, tags, visibility);
this.inputs = inputs != null ? Collections.unmodifiableList(inputs) : List.of();
}
@@ -12,7 +12,6 @@
*/
package org.openhab.core.automation.type;
import java.util.Collections;
import java.util.Set;
import org.openhab.core.automation.Module;
@@ -189,7 +188,7 @@ public class Input {
* @return tags associated with this Input.
*/
public Set<String> getTags() {
return tags != null ? tags : Collections.<String> emptySet();
return tags != null ? tags : Set.of();
}
/**
@@ -78,19 +78,19 @@ public abstract class ModuleType implements Identifiable<String> {
* Creates a {@link ModuleType} instance. This constructor is responsible to initialize common base properties of
* the {@link ModuleType}s.
*
* @param UID the {@link ModuleType}'s identifier, or {@code null} if a random identifier should be
* @param uid the {@link ModuleType}'s identifier, or {@code null} if a random identifier should be
* generated.
* @param configDescriptions describing meta-data for the configuration of the future {@link Module} instances
*/
public ModuleType(@Nullable String UID, @Nullable List<ConfigDescriptionParameter> configDescriptions) {
this(UID, configDescriptions, null, null, null, null);
public ModuleType(@Nullable String uid, @Nullable List<ConfigDescriptionParameter> configDescriptions) {
this(uid, configDescriptions, null, null, null, null);
}
/**
* Creates a {@link ModuleType} instance. This constructor is responsible to initialize all common properties of
* the {@link ModuleType}s.
*
* @param UID the {@link ModuleType}'s identifier, or {@code null} if a random identifier should be
* @param uid the {@link ModuleType}'s identifier, or {@code null} if a random identifier should be
* generated.
* @param configDescriptions describing meta-data for the configuration of the future {@link Module} instances.
* @param label a short and accurate, human-readable label of the {@link ModuleType}.
@@ -102,15 +102,15 @@ public abstract class ModuleType implements Identifiable<String> {
* If {@code null} is provided the default visibility {@link Visibility#VISIBLE} will be
* used.
*/
public ModuleType(@Nullable String UID, @Nullable List<ConfigDescriptionParameter> configDescriptions,
public ModuleType(@Nullable String uid, @Nullable List<ConfigDescriptionParameter> configDescriptions,
@Nullable String label, @Nullable String description, @Nullable Set<String> tags,
@Nullable Visibility visibility) {
this.uid = UID == null ? UUID.randomUUID().toString() : UID;
this.uid = uid == null ? UUID.randomUUID().toString() : uid;
this.label = label;
this.description = description;
this.configDescriptions = configDescriptions == null ? Collections.emptyList()
this.configDescriptions = configDescriptions == null ? List.of()
: Collections.unmodifiableList(configDescriptions);
this.tags = tags == null ? Collections.emptySet() : Collections.unmodifiableSet(tags);
this.tags = tags == null ? Set.of() : Collections.unmodifiableSet(tags);
this.visibility = visibility == null ? Visibility.VISIBLE : visibility;
}
@@ -12,7 +12,6 @@
*/
package org.openhab.core.automation.type;
import java.util.Collections;
import java.util.Set;
import org.openhab.core.automation.Module;
@@ -205,7 +204,7 @@ public class Output {
* @return the tags, associated with this {@link Input}.
*/
public Set<String> getTags() {
return tags != null ? tags : Collections.<String> emptySet();
return tags != null ? tags : Set.of();
}
/**
@@ -39,23 +39,23 @@ public class TriggerType extends ModuleType {
* Creates an instance of {@link TriggerType} with base properties - UID, a {@link List} of configuration
* descriptions and a {@link List} of {@link Output} descriptions.
*
* @param UID the {@link TriggerType}'s identifier, or {@code null} if a random identifier should be
* @param uid the {@link TriggerType}'s identifier, or {@code null} if a random identifier should be
* generated.
* @param configDescriptions describing meta-data for the configuration of the future {@link Trigger} instances.
* @param outputs a {@link List} with {@link Output} meta-information descriptions of the future
* {@link Trigger} instances.
*/
public TriggerType(@Nullable String UID, @Nullable List<ConfigDescriptionParameter> configDescriptions,
public TriggerType(@Nullable String uid, @Nullable List<ConfigDescriptionParameter> configDescriptions,
@Nullable List<Output> outputs) {
super(UID, configDescriptions);
this.outputs = outputs != null ? Collections.unmodifiableList(outputs) : Collections.emptyList();
super(uid, configDescriptions);
this.outputs = outputs != null ? Collections.unmodifiableList(outputs) : List.of();
}
/**
* Creates an instance of {@link TriggerType} with UID, label, description, a {@link Set} of tags, visibility,
* a {@link List} of configuration descriptions and a {@link List} of {@link Output} descriptions.
*
* @param UID the {@link TriggerType}'s identifier, or {@code null} if a random identifier should be
* @param uid the {@link TriggerType}'s identifier, or {@code null} if a random identifier should be
* generated.
* @param configDescriptions describing meta-data for the configuration of the future {@link Trigger} instances.
* @param label a short and accurate, human-readable label of the {@link TriggerType}.
@@ -70,11 +70,11 @@ public class TriggerType extends ModuleType {
* @param outputs a {@link List} with {@link Output} meta-information descriptions of the future
* {@link Trigger} instances.
*/
public TriggerType(@Nullable String UID, @Nullable List<ConfigDescriptionParameter> configDescriptions,
public TriggerType(@Nullable String uid, @Nullable List<ConfigDescriptionParameter> configDescriptions,
@Nullable String label, @Nullable String description, @Nullable Set<String> tags,
@Nullable Visibility visibility, @Nullable List<Output> outputs) {
super(UID, configDescriptions, label, description, tags, visibility);
this.outputs = outputs != null ? Collections.unmodifiableList(outputs) : Collections.emptyList();
super(uid, configDescriptions, label, description, tags, visibility);
this.outputs = outputs != null ? Collections.unmodifiableList(outputs) : List.of();
}
/**
@@ -12,8 +12,6 @@
*/
package org.openhab.core.automation.util;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.jdt.annotation.NonNullByDefault;
@@ -49,7 +47,7 @@ public class ActionBuilder extends ModuleBuilder<ActionBuilder, Action> {
}
public ActionBuilder withInputs(@Nullable Map<String, String> inputs) {
this.inputs = inputs != null ? Collections.unmodifiableMap(new HashMap<>(inputs)) : null;
this.inputs = inputs != null ? Map.copyOf(inputs) : null;
return this;
}
@@ -12,8 +12,6 @@
*/
package org.openhab.core.automation.util;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.jdt.annotation.NonNullByDefault;
@@ -49,7 +47,7 @@ public class ConditionBuilder extends ModuleBuilder<ConditionBuilder, Condition>
}
public ConditionBuilder withInputs(@Nullable Map<String, String> inputs) {
this.inputs = inputs != null ? Collections.unmodifiableMap(new HashMap<>(inputs)) : null;
this.inputs = inputs != null ? Map.copyOf(inputs) : null;
return this;
}
@@ -14,7 +14,6 @@ package org.openhab.core.automation.util;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
@@ -146,12 +145,12 @@ public class RuleBuilder {
}
public RuleBuilder withTags(String... tags) {
withTags(new HashSet<>(Arrays.asList(tags)));
withTags(Set.of(tags));
return this;
}
public RuleBuilder withTags(@Nullable Set<String> tags) {
this.tags = tags != null ? new HashSet<>(tags) : Collections.emptySet();
this.tags = tags != null ? Set.copyOf(tags) : Set.of();
return this;
}
@@ -161,7 +160,7 @@ public class RuleBuilder {
}
public RuleBuilder withConfigurationDescriptions(@Nullable List<ConfigDescriptionParameter> configDescs) {
this.configDescriptions = configDescs != null ? new LinkedList<>(configDescs) : Collections.emptyList();
this.configDescriptions = configDescs != null ? List.copyOf(configDescs) : List.of();
return this;
}
@@ -17,8 +17,8 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.time.ZoneId;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import javax.measure.quantity.Temperature;
@@ -104,7 +104,7 @@ public class ItemStateConditionHandlerTest extends JavaTest {
}
public static Collection<Object[]> equalsParameters() {
return Arrays.asList(new Object[][] { //
return List.of(new Object[][] { //
{ new ParameterSet("Number", "5", new DecimalType(23), false) }, //
{ new ParameterSet("Number", "5", new DecimalType(5), true) }, //
{ new ParameterSet("Number:Temperature", "5 °C", new DecimalType(23), false) }, //
@@ -120,7 +120,7 @@ public class ItemStateConditionHandlerTest extends JavaTest {
}
public static Collection<Object[]> greaterThanParameters() {
return Arrays.asList(new Object[][] { //
return List.of(new Object[][] { //
{ new ParameterSet("Number", "5", new DecimalType(23), true) }, //
{ new ParameterSet("Number", "5", new DecimalType(5), false) }, //
{ new ParameterSet("Number", "5 °C", new DecimalType(23), true) }, //
@@ -137,7 +137,7 @@ public class ItemStateConditionHandlerTest extends JavaTest {
}
public static Collection<Object[]> greaterThanOrEqualsParameters() {
return Arrays.asList(new Object[][] { //
return List.of(new Object[][] { //
{ new ParameterSet("Number", "5", new DecimalType(23), true) }, //
{ new ParameterSet("Number", "5", new DecimalType(5), true) }, //
{ new ParameterSet("Number", "5", new DecimalType(4), false) }, //
@@ -160,7 +160,7 @@ public class ItemStateConditionHandlerTest extends JavaTest {
}
public static Collection<Object[]> lessThanParameters() {
return Arrays.asList(new Object[][] { //
return List.of(new Object[][] { //
{ new ParameterSet("Number", "5", new DecimalType(23), false) }, //
{ new ParameterSet("Number", "5", new DecimalType(4), true) }, //
{ new ParameterSet("Number", "5 °C", new DecimalType(23), false) }, //
@@ -178,7 +178,7 @@ public class ItemStateConditionHandlerTest extends JavaTest {
}
public static Collection<Object[]> lessThanOrEqualsParameters() {
return Arrays.asList(new Object[][] { //
return List.of(new Object[][] { //
{ new ParameterSet("Number", "5", new DecimalType(23), false) }, //
{ new ParameterSet("Number", "5", new DecimalType(5), true) }, //
{ new ParameterSet("Number", "5", new DecimalType(4), true) }, //
@@ -88,16 +88,14 @@ public class AnnotationActionModuleTypeProviderTest extends JavaTest {
public void testMultiServiceAnnotationActions() {
AnnotatedActionModuleTypeProvider prov = new AnnotatedActionModuleTypeProvider(moduleTypeI18nServiceMock);
Map<String, Object> properties1 = new HashMap<>();
properties1.put(OpenHAB.SERVICE_CONTEXT, "conf1");
Map<String, Object> properties1 = Map.of(OpenHAB.SERVICE_CONTEXT, "conf1");
prov.addActionProvider(actionProviderConf1, properties1);
Collection<String> types = prov.getTypes();
assertEquals(1, types.size());
assertTrue(types.contains(TEST_ACTION_TYPE_ID));
Map<String, Object> properties2 = new HashMap<>();
properties2.put(OpenHAB.SERVICE_CONTEXT, "conf2");
Map<String, Object> properties2 = Map.of(OpenHAB.SERVICE_CONTEXT, "conf2");
prov.addActionProvider(actionProviderConf2, properties2);
// we only have ONE type but TWO configurations for it
@@ -74,8 +74,8 @@ public class ConfigDescription implements Identifiable<URI> {
}
this.uri = uri;
this.parameters = parameters == null ? Collections.emptyList() : Collections.unmodifiableList(parameters);
this.parameterGroups = groups == null ? Collections.emptyList() : Collections.unmodifiableList(groups);
this.parameters = parameters == null ? List.of() : Collections.unmodifiableList(parameters);
this.parameterGroups = groups == null ? List.of() : Collections.unmodifiableList(groups);
}
/**
@@ -15,7 +15,6 @@ package org.openhab.core.config.core;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
@@ -224,12 +223,12 @@ public class ConfigDescriptionParameter {
if (options != null) {
this.options = Collections.unmodifiableList(options);
} else {
this.options = Collections.unmodifiableList(new LinkedList<>());
this.options = List.of();
}
if (filterCriteria != null) {
this.filterCriteria = Collections.unmodifiableList(filterCriteria);
} else {
this.filterCriteria = Collections.unmodifiableList(new LinkedList<>());
this.filterCriteria = List.of();
}
}
@@ -18,7 +18,6 @@ import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -252,7 +251,7 @@ public class ConfigUtil {
private static Collection<Object> normalizeCollection(Collection<@NonNull ?> collection)
throws IllegalArgumentException {
if (collection.isEmpty()) {
return Collections.emptyList();
return List.of();
} else {
final List<Object> lst = new ArrayList<>(collection.size());
for (final Object it : collection) {
@@ -13,9 +13,9 @@
package org.openhab.core.config.core.status;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.function.Predicate;
@@ -66,7 +66,7 @@ public final class ConfigStatusInfo {
* @return an unmodifiable collection of the corresponding configuration status messages
*/
public Collection<ConfigStatusMessage> getConfigStatusMessages(Type... types) {
final Collection<Type> typesCollection = Arrays.asList(types);
final Collection<Type> typesCollection = List.of(types);
return filter(typesCollection, configStatusMessage -> typesCollection.contains(configStatusMessage.type));
}
@@ -77,7 +77,7 @@ public final class ConfigStatusInfo {
* @return an unmodifiable collection of the corresponding configuration status messages
*/
public Collection<ConfigStatusMessage> getConfigStatusMessages(String... parameterNames) {
final Collection<String> parameterNamesCollection = Arrays.asList(parameterNames);
final Collection<String> parameterNamesCollection = List.of(parameterNames);
return filter(parameterNamesCollection,
configStatusMessage -> parameterNamesCollection.contains(configStatusMessage.parameterName));
}
@@ -49,7 +49,7 @@ public final class ConfigValidationException extends RuntimeException {
*
* @param bundle the bundle from which this exception is thrown
* @param configValidationMessages the configuration description validation messages
* @throws NullPointException if given bundle or configuration description validation messages are null
* @throws NullPointerException if given bundle or configuration description validation messages are null
*/
public ConfigValidationException(Bundle bundle, TranslationProvider translationProvider,
Collection<ConfigValidationMessage> configValidationMessages) {
@@ -13,7 +13,7 @@
package org.openhab.core.config.core.validation;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import org.openhab.core.config.core.ConfigDescription;
@@ -50,7 +50,7 @@ public final class ConfigValidationMessage {
* @param messageKey the message key to be used for internationalization
*/
public ConfigValidationMessage(String parameterName, String defaultMessage, String messageKey) {
this(parameterName, defaultMessage, messageKey, Collections.<String> emptyList());
this(parameterName, defaultMessage, messageKey, List.of());
}
/**
@@ -16,7 +16,6 @@ import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
@@ -150,7 +149,7 @@ public class XmlDocumentBundleTracker<@NonNull T> extends BundleTracker<Bundle>
private Set<Bundle> getRelevantBundles() {
BundleTracker<?> bundleTracker = relevantBundlesTracker;
if (bundleTracker == null || bundleTracker.getBundles() == null) {
return Collections.emptySet();
return Set.of();
}
return (Set<Bundle>) Arrays.stream(bundleTracker.getBundles()).collect(Collectors.toSet());
}
@@ -18,7 +18,6 @@ import static org.hamcrest.MatcherAssert.assertThat;
import java.math.BigDecimal;
import java.util.List;
import java.util.TreeSet;
import java.util.stream.Stream;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.junit.jupiter.api.Test;
@@ -152,13 +151,12 @@ public class NormalizerTest {
assertThat(normalizer.normalize(null), is(nullValue()));
List<Boolean> expectedList = Stream.of(true, false, true).toList();
List<Boolean> expectedList = List.of(true, false, true);
assertThat(normalizer.normalize(Stream.of(true, false, true).toList()), is(equalTo(expectedList)));
assertThat(normalizer.normalize(Stream.of(true, false, true).toArray()), is(equalTo(expectedList)));
assertThat(normalizer.normalize(new TreeSet<>(Stream.of(false, true).toList())),
is(equalTo(Stream.of(false, true).toList())));
assertThat(normalizer.normalize(Stream.of(true, "false", true).toList()), is(equalTo(expectedList)));
assertThat(normalizer.normalize(Stream.of(true, 0, "true").toList()), is(equalTo(expectedList)));
assertThat(normalizer.normalize(List.of(true, false, true)), is(equalTo(expectedList)));
assertThat(normalizer.normalize(List.of(true, false, true).toArray()), is(equalTo(expectedList)));
assertThat(normalizer.normalize(new TreeSet<>(List.of(false, true))), is(equalTo(List.of(false, true))));
assertThat(normalizer.normalize(List.of(true, "false", true)), is(equalTo(expectedList)));
assertThat(normalizer.normalize(List.of(true, 0, "true")), is(equalTo(expectedList)));
}
}
@@ -39,7 +39,7 @@ public class DiscoveryResultImpl implements DiscoveryResult {
private @NonNullByDefault({}) ThingUID thingUID;
private @Nullable ThingTypeUID thingTypeUID;
private Map<String, Object> properties = Collections.emptyMap();
private Map<String, Object> properties = Map.of();
private @Nullable String representationProperty;
private @NonNullByDefault({}) DiscoveryResultFlag flag;
private @NonNullByDefault({}) String label;
@@ -82,7 +82,7 @@ public class DiscoveryResultImpl implements DiscoveryResult {
this.thingUID = thingUID;
this.thingTypeUID = thingTypeUID;
this.bridgeUID = bridgeUID;
this.properties = properties == null ? Collections.emptyMap() : Collections.unmodifiableMap(properties);
this.properties = properties == null ? Map.of() : Collections.unmodifiableMap(properties);
this.representationProperty = representationProperty;
this.label = label == null ? "" : label;
@@ -14,7 +14,6 @@ package org.openhab.core.config.discovery.internal;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
@@ -263,7 +262,7 @@ public final class DiscoveryServiceRegistryImpl implements DiscoveryServiceRegis
@Override
public synchronized void thingRemoved(final DiscoveryService source, final ThingUID thingUID) {
synchronized (cachedResults) {
Iterator<DiscoveryResult> it = cachedResults.getOrDefault(source, Collections.emptySet()).iterator();
Iterator<DiscoveryResult> it = cachedResults.getOrDefault(source, Set.of()).iterator();
while (it.hasNext()) {
if (it.next().getThingUID().equals(thingUID)) {
it.remove();
@@ -17,7 +17,6 @@ import static org.openhab.core.config.discovery.inbox.InboxPredicates.forThingUI
import java.net.URI;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
@@ -632,7 +631,7 @@ public final class PersistentInbox implements Inbox, DiscoveryListener, ThingReg
}
}
}
return Collections.emptyList();
return List.of();
}
private void addThingSafely(Thing thing) {
@@ -13,7 +13,6 @@
package org.openhab.core.config.discovery.internal.console;
import java.io.IOException;
import java.util.Arrays;
import java.util.Dictionary;
import java.util.Hashtable;
import java.util.List;
@@ -134,12 +133,12 @@ public class DiscoveryConsoleCommandExtension extends AbstractConsoleCommandExte
@Override
public List<String> getUsages() {
return Arrays.asList(new String[] {
return List.of(
buildCommandUsage(SUBCMD_START + " <thingTypeUID|bindingID>",
"runs a discovery on a given thing type or binding"),
buildCommandUsage(SUBCMD_BACKGROUND_DISCOVERY_ENABLE + " <PID>",
"enables background discovery for the discovery service with the given PID"),
buildCommandUsage(SUBCMD_BACKGROUND_DISCOVERY_DISABLE + " <PID>",
"disables background discovery for the discovery service with the given PID") });
"disables background discovery for the discovery service with the given PID"));
}
}
@@ -17,8 +17,6 @@ import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.collection.IsMapContaining.hasEntry;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.jdt.annotation.NonNullByDefault;
@@ -40,23 +38,20 @@ public class DiscoveryResultBuilderTest {
private static final ThingUID BRIDGE_UID = new ThingUID(new ThingTypeUID(BINDING_ID, "bridgeTypeId"), "bridgeId");
private static final ThingTypeUID THING_TYPE_UID = new ThingTypeUID(BINDING_ID, "thingTypeId");
private static final ThingUID THING_UID = new ThingUID(THING_TYPE_UID, BRIDGE_UID, "thingId");
private static final String KEY1 = "key1";
private static final String KEY2 = "key2";
private static final String VALUE1 = "value1";
private static final String VALUE2 = "value2";
private final Map<String, Object> properties = new HashMap<String, Object>() {
private static final long serialVersionUID = 1L;
{
put(KEY1, VALUE1);
put(KEY2, VALUE2);
}
};
private static final Map<String, Object> PROPERTIES = Map.of(KEY1, VALUE1, KEY2, VALUE2);
private @NonNullByDefault({}) DiscoveryResultBuilder builder;
private @NonNullByDefault({}) DiscoveryResult discoveryResult;
@BeforeEach
public void setup() {
builder = DiscoveryResultBuilder.create(THING_UID).withThingType(THING_TYPE_UID).withProperties(properties)
builder = DiscoveryResultBuilder.create(THING_UID).withThingType(THING_TYPE_UID).withProperties(PROPERTIES)
.withRepresentationProperty(KEY1).withLabel("Test");
discoveryResult = builder.build();
}
@@ -118,8 +113,7 @@ public class DiscoveryResultBuilderTest {
@Test
@Disabled
public void subsequentBuildsCreateIndependentDiscoveryResults() {
DiscoveryResult otherDiscoveryResult = builder.withLabel("Second Test").withProperties(Collections.emptyMap())
.build();
DiscoveryResult otherDiscoveryResult = builder.withLabel("Second Test").withProperties(Map.of()).build();
assertThat(otherDiscoveryResult.getLabel(), is(not(discoveryResult.getLabel())));
assertThat(otherDiscoveryResult.getProperties().size(), is(not(discoveryResult.getProperties().size())));
@@ -19,8 +19,6 @@ import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
import static org.openhab.core.config.discovery.inbox.InboxPredicates.withFlag;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Stream;
@@ -243,7 +241,7 @@ public class AutomaticInboxProcessorTest {
assertThat(results.size(), is(1));
assertThat(results.get(0).getThingUID(), is(equalTo(THING_UID)));
when(thingMock.getProperties()).thenReturn(Collections.emptyMap());
when(thingMock.getProperties()).thenReturn(Map.of());
when(thingStatusInfoChangedEventMock.getStatusInfo())
.thenReturn(new ThingStatusInfo(ThingStatus.ONLINE, ThingStatusDetail.NONE, null));
when(thingStatusInfoChangedEventMock.getThingUID()).thenReturn(THING_UID);
@@ -410,8 +408,8 @@ public class AutomaticInboxProcessorTest {
verify(thingRegistryMock, never()).add(argThat(thing -> THING_UID.equals(thing.getUID())));
// After setting the always auto approve property, all existing inbox results are approved.
Map<String, Object> configProperties = new HashMap<>();
configProperties.put(AutomaticInboxProcessor.ALWAYS_AUTO_APPROVE_CONFIG_PROPERTY, true);
Map<String, Object> configProperties = Map.of(AutomaticInboxProcessor.ALWAYS_AUTO_APPROVE_CONFIG_PROPERTY,
true);
automaticInboxProcessor.activate(configProperties);
verify(thingRegistryMock, times(1)).add(argThat(thing -> THING_UID.equals(thing.getUID())));
@@ -14,7 +14,6 @@ package org.openhab.core.config.discovery.internal;
import static org.junit.jupiter.api.Assertions.*;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.jdt.annotation.NonNullByDefault;
@@ -71,8 +70,7 @@ public class DiscoveryResultImplTest {
public void testInvalidSynchronize() {
ThingTypeUID thingTypeUID = new ThingTypeUID("bindingId", "thingType");
Map<String, Object> discoveryResultSourceMap = new HashMap<>();
discoveryResultSourceMap.put("ipAddress", "127.0.0.1");
Map<String, Object> discoveryResultSourceMap = Map.of("ipAddress", "127.0.0.1");
DiscoveryResultImpl discoveryResult = new DiscoveryResultImpl(thingTypeUID,
new ThingUID(thingTypeUID, "thingId"), null, discoveryResultSourceMap, "ipAddress", "TARGET",
@@ -91,8 +89,7 @@ public class DiscoveryResultImplTest {
public void testIrrelevantSynchronize() {
ThingTypeUID thingTypeUID = new ThingTypeUID("bindingId", "thingType");
Map<String, Object> discoveryResultSourceMap = new HashMap<>();
discoveryResultSourceMap.put("ipAddress", "127.0.0.1");
Map<String, Object> discoveryResultSourceMap = Map.of("ipAddress", "127.0.0.1");
DiscoveryResultImpl discoveryResult = new DiscoveryResultImpl(thingTypeUID,
new ThingUID(thingTypeUID, "thingId"), null, discoveryResultSourceMap, "ipAddress", "TARGET",
@@ -114,17 +111,16 @@ public class DiscoveryResultImplTest {
public void testSynchronize() {
ThingTypeUID thingTypeUID = new ThingTypeUID("bindingId", "thingType");
Map<String, Object> discoveryResultSourceMap = new HashMap<>();
discoveryResultSourceMap.put("ipAddress", "127.0.0.1");
Map<String, Object> discoveryResultSourceMap = Map.of("ipAddress", "127.0.0.1");
DiscoveryResultImpl discoveryResult = new DiscoveryResultImpl(thingTypeUID,
new ThingUID(thingTypeUID, "thingId"), null, discoveryResultSourceMap, "ipAddress", "TARGET",
DEFAULT_TTL);
discoveryResult.setFlag(DiscoveryResultFlag.IGNORED);
Map<String, Object> discoveryResultMap = new HashMap<>();
discoveryResultMap.put("ipAddress", "192.168.178.1");
discoveryResultMap.put("macAddress", "AA:BB:CC:DD:EE:FF");
Map<String, Object> discoveryResultMap = Map.of( //
"ipAddress", "192.168.178.1", //
"macAddress", "AA:BB:CC:DD:EE:FF");
DiscoveryResultImpl discoveryResultSource = new DiscoveryResultImpl(thingTypeUID,
new ThingUID(thingTypeUID, "thingId"), null, discoveryResultMap, "macAddress", "SOURCE", DEFAULT_TTL);
@@ -20,7 +20,6 @@ import static org.mockito.Mockito.*;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -108,8 +107,7 @@ public class PersistentInboxTest {
@Test
public void testConfigUpdateNormalizationWithConfigDescription() throws URISyntaxException {
Map<String, Object> props = new HashMap<>();
props.put("foo", "1");
Map<String, Object> props = Map.of("foo", "1");
Configuration config = new Configuration(props);
Thing thing = ThingBuilder.create(THING_TYPE_UID, THING_UID).withConfiguration(config).build();
configureConfigDescriptionRegistryMock("foo", Type.TEXT);
@@ -13,7 +13,6 @@
package org.openhab.core.io.console.karaf.internal;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.List;
import org.apache.felix.service.command.Process;
@@ -115,7 +114,7 @@ public class CommandWrapper implements Command, Action {
List<Command> commands = registry.getCommands();
for (Command command : commands) {
if (SCOPE.equals(command.getScope()) && command instanceof CommandWrapper) {
command.execute(null, Arrays.asList(new Object[] { "--help" }));
command.execute(null, List.of("--help"));
}
}
@@ -12,7 +12,6 @@
*/
package org.openhab.core.io.console.internal.extension;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Set;
@@ -101,13 +100,13 @@ public class ItemConsoleCommandExtension extends AbstractConsoleCommandExtension
@Override
public List<String> getUsages() {
return Arrays.asList(new String[] {
return List.of(
buildCommandUsage(SUBCMD_LIST + " [<pattern>]",
"lists names and types of all items (matching the pattern, if given)"),
buildCommandUsage(SUBCMD_CLEAR, "removes all items"),
buildCommandUsage(SUBCMD_REMOVE + " <itemName>", "removes the given item"),
buildCommandUsage(SUBCMD_ADDTAG + " <itemName> <tag>", "adds a tag to the given item"),
buildCommandUsage(SUBCMD_RMTAG + " <itemName> <tag>", "removes a tag from the given item") });
buildCommandUsage(SUBCMD_RMTAG + " <itemName> <tag>", "removes a tag from the given item"));
}
@Override
@@ -12,7 +12,6 @@
*/
package org.openhab.core.io.console.internal.extension;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
@@ -65,7 +64,7 @@ public class MetadataConsoleCommandExtension extends AbstractConsoleCommandExten
@Override
public List<String> getUsages() {
return Arrays.asList( //
return List.of( //
buildCommandUsage(SUBCMD_LIST + " [<itemName> [<namespace>]]",
"lists all available metadata, can be filtered for a specifc item and namespace"),
buildCommandUsage(SUBCMD_LIST_INTERNAL + " [<itemName> [<namespace>]]",
@@ -16,9 +16,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.junit.jupiter.api.Test;
@@ -36,7 +35,6 @@ import org.openhab.core.thing.internal.ThingImpl;
import org.osgi.framework.BundleContext;
import io.micrometer.core.instrument.Meter;
import io.micrometer.core.instrument.Tag;
import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
/**
@@ -63,11 +61,10 @@ public class ThingStateMetricTest {
SimpleMeterRegistry meterRegistry = new SimpleMeterRegistry();
ThingStateMetric thingStateMetric = new ThingStateMetric(mock(BundleContext.class), thingRegistry,
new HashSet<Tag>());
ThingStateMetric thingStateMetric = new ThingStateMetric(mock(BundleContext.class), thingRegistry, Set.of());
// Only one meter registered at bind time
doReturn(Collections.singleton(thing)).when(thingRegistry).getAll();
doReturn(List.of(thing)).when(thingRegistry).getAll();
thingStateMetric.bindTo(meterRegistry);
List<Meter> meters = meterRegistry.getMeters();
@@ -22,7 +22,6 @@ import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.stream.Stream;
import javax.net.ssl.SSLEngine;
import javax.net.ssl.X509ExtendedTrustManager;
@@ -173,7 +172,7 @@ public class ExtensibleTrustManagerImplTest {
private Collection<List<?>> constructAlternativeNames(String... alternatives) {
Collection<List<?>> alternativeNames = new ArrayList<>();
for (String alternative : alternatives) {
alternativeNames.add(Stream.of(0, alternative).toList());
alternativeNames.add(List.of(0, alternative));
}
return alternativeNames;
@@ -20,8 +20,8 @@ import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.jose4j.jwa.AlgorithmConstraints.ConstraintType;
@@ -116,8 +116,7 @@ public class JwtHelper {
jwtClaims.setSubject(user.getName());
jwtClaims.setClaim("client_id", clientId);
jwtClaims.setClaim("scope", scope);
jwtClaims.setStringListClaim("role",
new ArrayList<>(user.getRoles() != null ? user.getRoles() : Collections.emptySet()));
jwtClaims.setStringListClaim("role", new ArrayList<>(user.getRoles() != null ? user.getRoles() : Set.of()));
JsonWebSignature jws = new JsonWebSignature();
jws.setPayload(jwtClaims.toJson());
@@ -18,7 +18,6 @@ import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Map;
@@ -206,7 +205,7 @@ public class ConfigurableServiceResource implements RESTResource {
try {
Configuration configuration = configurationService.get(serviceId);
return configuration != null ? Response.ok(configuration.getProperties()).build()
: Response.ok(Collections.emptyMap()).build();
: Response.ok(Map.of()).build();
} catch (IOException ex) {
logger.error("Cannot get configuration for service {}: ", serviceId, ex);
return Response.status(Status.INTERNAL_SERVER_ERROR).build();
@@ -19,7 +19,6 @@ import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
@@ -637,7 +636,7 @@ public class ThingResource implements RESTResource {
if (info != null) {
return Response.ok().entity(info.getConfigStatusMessages()).build();
}
return Response.ok().entity(Collections.EMPTY_SET).build();
return Response.ok().entity(Set.of()).build();
}
@PUT
@@ -14,7 +14,6 @@ package org.openhab.core.io.rest.core.internal.thing;
import java.net.URI;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.stream.Stream;
@@ -203,7 +202,7 @@ public class ThingTypeResource implements RESTResource {
// Default to the channelGroupDefinition label/description to override the channelGroupType
String label = channelGroupDefinition.getLabel();
String description = channelGroupDefinition.getDescription();
List<ChannelDefinition> channelDefinitions = Collections.emptyList();
List<ChannelDefinition> channelDefinitions = List.of();
if (channelGroupType == null) {
logger.warn("Cannot find channel group type: {}", channelGroupDefinition.getTypeUID());
@@ -13,7 +13,6 @@
package org.openhab.core.io.rest.core.thing;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -49,7 +48,7 @@ public class EnrichedThingDTOMapper extends ThingDTOMapper {
List<EnrichedChannelDTO> channels = new ArrayList<>();
for (ChannelDTO channel : thingDTO.channels) {
Set<String> linkedItems = linkedItemsMap != null ? linkedItemsMap.get(channel.id) : Collections.emptySet();
Set<String> linkedItems = linkedItemsMap != null ? linkedItemsMap.get(channel.id) : Set.of();
channels.add(new EnrichedChannelDTO(channel, linkedItems));
}
@@ -19,9 +19,9 @@ import static org.hamcrest.core.IsIterableContaining.hasItem;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.when;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.junit.jupiter.api.BeforeEach;
@@ -63,12 +63,12 @@ public class MetadataSelectorMatcherTest {
@Test
public void nullSelectorShouldReturnEmptySet() {
assertThat(matcher.filterNamespaces(null, null), is(Collections.emptySet()));
assertThat(matcher.filterNamespaces(null, null), is(Set.of()));
}
@Test
public void emptySelectorShouldReturnEmptySet() {
assertThat(matcher.filterNamespaces("", null), is(Collections.emptySet()));
assertThat(matcher.filterNamespaces("", null), is(Set.of()));
}
@Test
@@ -22,8 +22,6 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.hamcrest.CoreMatchers;
@@ -75,8 +73,7 @@ public class EnrichedThingDTOMapperTest {
@Test
public void shouldMapEnrichedThingDTO() {
when(linkedItemsMapMock.get("1"))
.thenReturn(Stream.of("linkedItem1", "linkedItem2").collect(Collectors.toSet()));
when(linkedItemsMapMock.get("1")).thenReturn(Set.of("linkedItem1", "linkedItem2"));
EnrichedThingDTO enrichedThingDTO = EnrichedThingDTOMapper.map(thingMock, thingStatusInfoMock,
firmwareStatusMock, linkedItemsMapMock, true);
@@ -63,7 +63,7 @@ public class PageChangeListener implements EventSubscriber {
private Set<Item> items;
private final HashSet<String> filterItems = new HashSet<>();
private final List<SitemapSubscriptionCallback> callbacks = Collections.synchronizedList(new ArrayList<>());
private Set<SitemapSubscriptionCallback> distinctCallbacks = Collections.emptySet();
private Set<SitemapSubscriptionCallback> distinctCallbacks = Set.of();
/**
* Creates a new instance.
@@ -18,7 +18,6 @@ import static org.hamcrest.MatcherAssert.assertThat;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.List;
import java.util.stream.Stream;
@@ -40,7 +39,7 @@ public class Stream2JSONInputStreamTest {
@Test
public void shouldReturnForEmptyStream() throws Exception {
List<Object> emptyList = Collections.emptyList();
List<Object> emptyList = List.of();
Stream2JSONInputStream collection2InputStream = new Stream2JSONInputStream(emptyList.stream());
assertThat(inputStreamToString(collection2InputStream), is(GSON.toJson(emptyList)));
@@ -17,8 +17,8 @@ import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.stream.Stream;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.junit.jupiter.params.ParameterizedTest;
@@ -39,7 +39,7 @@ public class BitUtilitiesExtractStateFromRegistersTest {
}
public static Collection<Object[]> data() {
return Stream.of(
return List.of(
//
// BIT
//
@@ -348,8 +348,7 @@ public class BitUtilitiesExtractStateFromRegistersTest {
new Object[] {
// out of bounds of unsigned 64bit
new DecimalType("16124500437522872585"), ValueType.UINT64_SWAP,
shortArrayToRegisterArray(0x7909, 0x772E, 0xBBB7, 0xDFC5), 0 })
.toList();
shortArrayToRegisterArray(0x7909, 0x772E, 0xBBB7, 0xDFC5), 0 });
}
@SuppressWarnings("unchecked")
@@ -17,6 +17,7 @@ import static org.junit.jupiter.api.Assertions.*;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Collection;
import java.util.List;
import java.util.stream.Stream;
import java.util.stream.Stream.Builder;
@@ -37,7 +38,7 @@ public class BitUtilitiesExtractStringTest {
}
public static Collection<Object[]> data() {
return Stream.of(new Object[] { "", shortArrayToRegisterArray(0), 0, 0, StandardCharsets.UTF_8 },
return List.of(new Object[] { "", shortArrayToRegisterArray(0), 0, 0, StandardCharsets.UTF_8 },
new Object[] { "hello", shortArrayToRegisterArray(0x6865, 0x6c6c, 0x6f00), 0, 5,
StandardCharsets.UTF_8 },
new Object[] { "he", shortArrayToRegisterArray(0x6865, 0x6c6c, 0x6f00), 0, 2, StandardCharsets.UTF_8 }, // limited
@@ -73,8 +74,7 @@ public class BitUtilitiesExtractStringTest {
StandardCharsets.UTF_8 },
// out of bounds
new Object[] { IllegalArgumentException.class, shortArrayToRegisterArray(0, 0), 0, 5,
StandardCharsets.UTF_8 })
.toList();
StandardCharsets.UTF_8 });
}
public static Stream<Object[]> dataWithByteVariations() {
@@ -14,8 +14,8 @@ package org.openhab.core.io.transport.serial.internal;
import java.net.URI;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.function.Predicate;
import org.eclipse.jdt.annotation.NonNullByDefault;
@@ -83,7 +83,7 @@ public class SerialPortRegistry {
public Collection<SerialPortProvider> getPortCreators() {
synchronized (portCreators) {
return Collections.unmodifiableCollection(new HashSet<>(portCreators));
return Set.copyOf(portCreators);
}
}
}
@@ -90,11 +90,11 @@ public class SerialCommandExtension extends AbstractConsoleCommandExtension {
@Override
public List<String> getUsages() {
return Arrays.asList(new String[] { //
return List.of( //
buildCommandUsage(SUBCMD_IDENTIFIER_ALL, "lists all identifiers"), //
buildCommandUsage(SUBCMD_IDENTIFIER_NAME, "lists a specific identifier"), //
buildCommandUsage(SUBCMD_PORT_CREATORS, "gets details about the port creators") //
});
);
}
private static String str(final @Nullable SerialPortIdentifier id) {
@@ -21,8 +21,7 @@ import static org.mockito.Mockito.when;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletException;
@@ -74,8 +73,7 @@ public class CommonWebSocketServletTest {
when(factory.getPolicy()).thenReturn(wsPolicy);
servlet.configure(factory);
verify(factory).setCreator(webSocketCreatorAC.capture());
var params = new HashMap<String, List<String>>();
when(request.getParameterMap()).thenReturn(params);
when(request.getParameterMap()).thenReturn(Map.of());
when(authFilter.getSecurityContext(any(), anyBoolean())).thenReturn(new AnonymousUserSecurityContext());
when(testDefaultWsAdapter.getId()).thenReturn(CommonWebSocketServlet.DEFAULT_ADAPTER_ID);
when(testWsAdapter.getId()).thenReturn(testAdapterId);
@@ -13,7 +13,6 @@
package org.openhab.core.karaf.internal.jaas;
import java.security.Principal;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
@@ -67,12 +66,12 @@ public class ManagedUserBackingEngine implements BackingEngine {
@Override
public List<GroupPrincipal> listGroups(UserPrincipal user) {
return Collections.emptyList();
return List.of();
}
@Override
public Map<GroupPrincipal, String> listGroups() {
return Collections.emptyMap();
return Map.of();
}
@Override
@@ -96,7 +95,7 @@ public class ManagedUserBackingEngine implements BackingEngine {
if (user != null) {
return user.getRoles().stream().map(r -> new RolePrincipal(r)).toList();
}
return Collections.emptyList();
return List.of();
}
@Override
@@ -15,7 +15,6 @@ package org.openhab.core.model.item.internal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
@@ -477,7 +476,7 @@ public class GenericItemProvider extends AbstractProvider<Item>
private Map<String, Item> toItemMap(@Nullable Collection<Item> items) {
if (items == null || items.isEmpty()) {
return Collections.emptyMap();
return Map.of();
}
Map<String, Item> ret = new LinkedHashMap<>();
@@ -15,7 +15,6 @@ package org.openhab.core.model.item.internal;
import static java.util.stream.Collectors.toSet;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
@@ -107,7 +106,7 @@ public class GenericMetadataProvider extends AbstractProvider<Metadata> implemen
public Collection<Metadata> getAll() {
try {
lock.readLock().lock();
return Collections.unmodifiableSet(new HashSet<>(metadata));
return Set.copyOf(metadata);
} finally {
lock.readLock().unlock();
}
@@ -14,8 +14,8 @@ package org.openhab.core.model.script.runtime.internal.engine;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.URI;
@@ -188,7 +188,7 @@ public class ScriptEngineImpl implements ScriptEngine, ModelParser {
private void deleteResource(Resource resource) {
try {
resource.delete(Collections.emptyMap());
resource.delete(Map.of());
} catch (IOException e) {
// Do nothing
}
@@ -12,7 +12,6 @@
*/
package org.openhab.core.model.script.internal;
import java.util.Collections;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
@@ -110,6 +109,6 @@ public class RuleHumanLanguageInterpreter implements HumanLanguageInterpreter {
@Override
public Set<String> getSupportedGrammarFormats() {
return Collections.emptySet();
return Set.of();
}
}
@@ -13,7 +13,6 @@
package org.openhab.core.model.thing.internal;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Map;
import java.util.Optional;
@@ -117,7 +116,7 @@ public class GenericItemChannelLinkProvider extends AbstractProvider<ItemChannel
logger.warn("There already is an update transaction for generic item channel links. Continuing anyway.");
}
Set<String> previous = contextMap.get(context);
previousItemNames = previous != null ? new HashSet<>(previous) : Collections.emptySet();
previousItemNames = previous != null ? new HashSet<>(previous) : new HashSet<>();
}
@Override
@@ -293,7 +293,7 @@ public class JsonStorage<T> implements Storage<T> {
private List<Long> calculateFileTimes() {
File folder = new File(file.getParent() + File.separator + BACKUP_EXTENSION);
if (!folder.isDirectory()) {
return Collections.emptyList();
return List.of();
}
List<Long> fileTimes = new ArrayList<>();
File[] files = folder.listFiles();
@@ -16,7 +16,6 @@ import static org.openhab.core.config.core.ConfigDescriptionParameterBuilder.cre
import java.util.List;
import java.util.Locale;
import java.util.stream.Stream;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
@@ -47,32 +46,32 @@ public class MagicMetadataProvider implements MetadataConfigDescriptionProvider
@Override
public @Nullable List<ParameterOption> getParameterOptions(@Nullable Locale locale) {
return Stream.of( //
return List.of( //
new ParameterOption("just", "Just Magic"), //
new ParameterOption("pure", "Pure Magic") //
).toList();
);
}
@Override
public @Nullable List<ConfigDescriptionParameter> getParameters(String value, @Nullable Locale locale) {
switch (value) {
case "just":
return Stream.of( //
return List.of( //
create("electric", Type.BOOLEAN).withLabel("Use Electricity").build() //
).toList();
);
case "pure":
return Stream.of( //
return List.of( //
create("spell", Type.TEXT).withLabel("Spell").withDescription("The exact spell to use").build(), //
create("price", Type.DECIMAL).withLabel("Price")
.withDescription("...because magic always comes with a price").build(), //
create("power", Type.INTEGER).withLabel("Power").withLimitToOptions(true).withOptions( //
Stream.of( //
List.of( //
new ParameterOption("0", "Very High"), //
new ParameterOption("1", "Incredible"), //
new ParameterOption("2", "Insane"), //
new ParameterOption("3", "Ludicrous") //
).toList()).build() //
).toList();
)).build() //
);
}
return null;
}
@@ -18,7 +18,6 @@ import static org.junit.jupiter.api.Assertions.fail;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Dictionary;
import java.util.HashMap;
import java.util.List;
@@ -114,7 +113,7 @@ public class JavaOSGiTest extends JavaTest {
if (serviceReferences == null) {
new MissingServiceAnalyzer(System.out, bundleContext).printMissingServiceDetails(clazz);
return Collections.emptyList();
return List.of();
}
return (List<T>) Arrays //
@@ -195,7 +194,7 @@ public class JavaOSGiTest extends JavaTest {
if (serviceReferences == null) {
new MissingServiceAnalyzer(System.out, bundleContext).printMissingServiceDetails(clazz);
return Collections.emptyList();
return List.of();
}
return Arrays //
@@ -13,7 +13,7 @@
package org.openhab.core.thing.binding;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import org.eclipse.jdt.annotation.NonNullByDefault;
@@ -178,6 +178,6 @@ public interface ThingHandler {
* @return - list of classes that will be registered as OSGi services
*/
default Collection<Class<? extends ThingHandlerService>> getServices() {
return Collections.emptyList();
return List.of();
}
}
@@ -13,7 +13,7 @@
package org.openhab.core.thing.firmware;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import org.eclipse.jdt.annotation.NonNullByDefault;
@@ -53,7 +53,7 @@ public final class FirmwareUpdateProgressInfo {
thingUID = new ThingUID("internal:reflective:constructor");
firmwareVersion = "";
progressStep = ProgressStep.WAITING;
sequence = Collections.emptyList();
sequence = List.of();
pending = false;
progress = null;
}
@@ -14,7 +14,6 @@ package org.openhab.core.thing.internal;
import java.util.List;
import java.util.Locale;
import java.util.stream.Stream;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
@@ -44,10 +43,10 @@ public class AutoUpdateConfigDescriptionProvider implements MetadataConfigDescri
@Override
public @Nullable List<ParameterOption> getParameterOptions(@Nullable Locale locale) {
return Stream.of( //
return List.of( //
new ParameterOption("true", "Enforce an auto update"), //
new ParameterOption("false", "Veto an auto update") //
).toList();
);
}
@Override
@@ -12,7 +12,6 @@
*/
package org.openhab.core.thing.internal.console;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
@@ -196,11 +195,10 @@ public final class FirmwareUpdateConsoleCommandExtension extends AbstractConsole
@Override
public List<String> getUsages() {
return Arrays.asList(new String[] {
buildCommandUsage(SUBCMD_LIST + " <thingUID>", "lists the available firmwares for a thing"),
return List.of(buildCommandUsage(SUBCMD_LIST + " <thingUID>", "lists the available firmwares for a thing"),
buildCommandUsage(SUBCMD_STATUS + " <thingUID>", "lists the firmware status for a thing"),
buildCommandUsage(SUBCMD_CANCEL + " <thingUID>", "cancels the update for a thing"), buildCommandUsage(
SUBCMD_UPDATE + " <thingUID> <firmware version>", "updates the firmware for a thing") });
SUBCMD_UPDATE + " <thingUID> <firmware version>", "updates the firmware for a thing"));
}
@Reference(cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC)
@@ -12,7 +12,6 @@
*/
package org.openhab.core.thing.internal.console;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
@@ -142,11 +141,11 @@ public class LinkConsoleCommandExtension extends AbstractConsoleCommandExtension
@Override
public List<String> getUsages() {
return Arrays.asList(new String[] { buildCommandUsage(SUBCMD_LIST, "lists all links"),
return List.of(buildCommandUsage(SUBCMD_LIST, "lists all links"),
buildCommandUsage(SUBCMD_LINK + " <itemName> <channelUID>", "links an item with a channel"),
buildCommandUsage(SUBCMD_UNLINK + " <itemName> <thingUID>", "unlinks an item with a channel"),
buildCommandUsage(SUBCMD_CLEAR, "removes all managed links"),
buildCommandUsage(SUBCMD_ORPHAN, "<list|purge> lists/purges all links with one missing element") });
buildCommandUsage(SUBCMD_ORPHAN, "<list|purge> lists/purges all links with one missing element"));
}
private void clear(Console console) {
@@ -13,7 +13,6 @@
package org.openhab.core.thing.internal.console;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
@@ -89,7 +88,7 @@ public class ThingConsoleCommandExtension extends AbstractConsoleCommandExtensio
printThings(console, things);
return;
case SUBCMD_SHOW:
printThingsDetails(console, Arrays.asList(args).subList(1, args.length));
printThingsDetails(console, List.of(args).subList(1, args.length));
return;
case SUBCMD_CLEAR:
removeAllThings(console, things);
@@ -101,7 +101,7 @@ public final class FirmwareImpl implements Firmware {
this.onlineChangelog = onlineChangelog;
this.inputStream = inputStream;
this.md5Hash = md5Hash;
this.properties = Collections.unmodifiableMap(properties != null ? properties : Collections.emptyMap());
this.properties = properties != null ? Collections.unmodifiableMap(properties) : Map.of();
}
@Override
@@ -12,10 +12,9 @@
*/
package org.openhab.core.thing.internal.firmware;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import org.openhab.core.events.Event;
@@ -90,7 +89,7 @@ final class ProgressCallbackImpl implements ProgressCallback {
if (sequence == null || sequence.length == 0) {
throw new IllegalArgumentException("Sequence must not be null or empty.");
}
this.sequence = Collections.unmodifiableCollection(Arrays.asList(sequence));
this.sequence = List.of(sequence);
progressIterator = this.sequence.iterator();
this.state = InternalState.INITIALIZED;
}
@@ -59,16 +59,11 @@ public class ChannelDefinition {
throw new IllegalArgumentException("The ID must neither be null nor empty!");
}
if (properties != null) {
this.properties = Collections.unmodifiableMap(properties);
} else {
this.properties = Collections.emptyMap();
}
this.id = id;
this.channelTypeUID = channelTypeUID;
this.label = label;
this.description = description;
this.properties = properties != null ? Collections.unmodifiableMap(properties) : Map.of();
this.autoUpdatePolicy = autoUpdatePolicy;
}
@@ -114,7 +109,7 @@ public class ChannelDefinition {
/**
* Returns the properties for this {@link ChannelDefinition}
*
* @return the unmodfiable properties for this {@link ChannelDefinition} (not null)
* @return the unmodifiable properties for this {@link ChannelDefinition} (not null)
*/
public Map<String, String> getProperties() {
return properties;
@@ -49,7 +49,7 @@ public class ChannelGroupType extends AbstractDescriptionType {
super(uid, label, description, null);
this.category = category;
this.channelDefinitions = channelDefinitions == null ? Collections.emptyList()
this.channelDefinitions = channelDefinitions == null ? List.of()
: Collections.unmodifiableList(channelDefinitions);
}
@@ -80,15 +80,15 @@ public class ThingType extends AbstractDescriptionType {
this.category = category;
this.listed = listed;
this.representationProperty = representationProperty;
this.supportedBridgeTypeUIDs = supportedBridgeTypeUIDs == null ? Collections.emptyList()
this.supportedBridgeTypeUIDs = supportedBridgeTypeUIDs == null ? List.of()
: Collections.unmodifiableList(supportedBridgeTypeUIDs);
this.channelDefinitions = channelDefinitions == null ? Collections.emptyList()
this.channelDefinitions = channelDefinitions == null ? List.of()
: Collections.unmodifiableList(channelDefinitions);
this.channelGroupDefinitions = channelGroupDefinitions == null ? Collections.emptyList()
this.channelGroupDefinitions = channelGroupDefinitions == null ? List.of()
: Collections.unmodifiableList(channelGroupDefinitions);
this.extensibleChannelTypeIds = extensibleChannelTypeIds == null ? Collections.emptyList()
this.extensibleChannelTypeIds = extensibleChannelTypeIds == null ? List.of()
: Collections.unmodifiableList(extensibleChannelTypeIds);
this.properties = properties == null ? Collections.emptyMap() : Collections.unmodifiableMap(properties);
this.properties = properties == null ? Map.of() : Collections.unmodifiableMap(properties);
}
/**
@@ -13,7 +13,6 @@
package org.openhab.core.thing.xml.internal;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
@@ -111,7 +110,7 @@ public class ThingTypeConverter extends AbstractDescriptionTypeConverter<ThingTy
protected List<String> getExtensibleChannelTypeIds(Map<String, String> attributes) {
String extensible = attributes.get("extensible");
if (extensible == null) {
return Collections.emptyList();
return List.of();
}
return Arrays.stream(extensible.split(",")).map(String::trim).toList();
@@ -17,8 +17,6 @@ import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.collection.IsCollectionWithSize.hasSize;
import static org.openhab.core.thing.DefaultSystemChannelTypeProvider.SYSTEM_OUTDOOR_TEMPERATURE;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.jdt.annotation.NonNullByDefault;
@@ -45,13 +43,9 @@ public class ChannelBuilderTest {
private static final String KEY2 = "key2";
private static final String VALUE1 = "value1";
private static final String VALUE2 = "value2";
private final Map<String, String> properties = new HashMap<String, String>() {
private static final long serialVersionUID = 1L;
{
put(KEY1, VALUE1);
put(KEY2, VALUE2);
}
};
private static final Map<String, String> PROPERTIES = Map.of(KEY1, VALUE1, KEY2, VALUE2);
private @NonNullByDefault({}) ChannelBuilder builder;
private @NonNullByDefault({}) Channel channel;
@@ -62,7 +56,7 @@ public class ChannelBuilderTest {
ChannelUID channelUID = new ChannelUID(new ThingUID(thingType.getUID(), "thingId"), "temperature");
builder = ChannelBuilder.create(channelUID, SYSTEM_OUTDOOR_TEMPERATURE.getItemType()).withLabel("Test")
.withDescription("My test channel").withType(SYSTEM_OUTDOOR_TEMPERATURE.getUID())
.withProperties(properties);
.withProperties(PROPERTIES);
channel = builder.build();
}
@@ -99,7 +93,7 @@ public class ChannelBuilderTest {
@Test
public void subsequentBuildsCreateIndependentChannels() {
Channel otherChannel = builder.withLabel("Second Test").withDescription("My second test channel")
.withAcceptedItemType(CoreItemFactory.NUMBER).withProperties(Collections.emptyMap()).build();
.withAcceptedItemType(CoreItemFactory.NUMBER).withProperties(Map.of()).build();
assertThat(otherChannel.getDescription(), is(not(channel.getDescription())));
assertThat(otherChannel.getLabel(), is(not(channel.getLabel())));
@@ -17,7 +17,6 @@ import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.collection.IsCollectionWithSize.hasSize;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.Collections;
import java.util.List;
import java.util.Map;
@@ -114,8 +113,8 @@ public class ThingBuilderTest {
@Test
public void subsequentBuildsCreateIndependentThings() {
Thing thing = thingBuilder.withLabel("Test").withLocation("Some Place").withProperties(properties).build();
Thing otherThing = thingBuilder.withLabel("Second Test").withLocation("Other Place")
.withProperties(Collections.emptyMap()).build();
Thing otherThing = thingBuilder.withLabel("Second Test").withLocation("Other Place").withProperties(Map.of())
.build();
assertThat(otherThing.getLabel(), is(not(thing.getLabel())));
assertThat(otherThing.getLocation(), is(not(thing.getLocation())));
@@ -123,7 +123,7 @@ public class AutoUpdateManagerTest {
.thenAnswer(answer -> ChannelBuilder.create(CHANNEL_UID_OFFLINE_1, CoreItemFactory.STRING)
.withAutoUpdatePolicy(policies.get(CHANNEL_UID_OFFLINE_1)).build());
aum = new AutoUpdateManager(new HashMap<>(), channelTypeRegistryMock, eventPublisherMock, iclRegistryMock,
aum = new AutoUpdateManager(Map.of(), channelTypeRegistryMock, eventPublisherMock, iclRegistryMock,
metadataRegistryMock, thingRegistryMock);
}
@@ -18,7 +18,6 @@ import static org.mockito.Mockito.*;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
@@ -85,7 +84,7 @@ public class SystemHysteresisStateProfileTest {
}
public static Collection<Object[]> parameters() {
return Arrays.asList(new Object[][] { //
return List.of(new Object[][] { //
// lower bound = upper bound = 10, one state update / command (PercentType)
{ new ParameterSet(List.of(PercentType.HUNDRED), List.of(OnOffType.ON), BigDecimal.TEN, null) }, //
{ new ParameterSet(List.of(PERCENT_TYPE_TWENTY_FIVE), List.of(OnOffType.ON), BigDecimal.TEN, null) }, //
@@ -18,7 +18,6 @@ import static org.mockito.Mockito.*;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
@@ -86,7 +85,7 @@ public class SystemRangeStateProfileTest {
}
public static Collection<Object[]> parameters() {
return Arrays.asList(new Object[][] { //
return List.of(new Object[][] { //
// lower bound = 10, upper bound = 40 (as BigDecimal), one state update / command (PercentType), not
// inverted
{ new ParameterSet(List.of(PercentType.HUNDRED), List.of(OnOffType.OFF), BigDecimal.TEN,
@@ -17,7 +17,6 @@ import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.*;
import static org.openhab.core.thing.profiles.SystemProfiles.*;
import java.util.Collections;
import java.util.Map;
import java.util.stream.Stream;
@@ -152,8 +151,7 @@ public class ToggleProfileTest extends JavaTest {
}
private void initializeContextMock(@Nullable String triggerEvent) {
Map<String, Object> params = triggerEvent == null ? Collections.emptyMap()
: Map.of(ToggleProfile.EVENT_PARAM, triggerEvent);
Map<String, Object> params = triggerEvent == null ? Map.of() : Map.of(ToggleProfile.EVENT_PARAM, triggerEvent);
when(contextMock.getConfiguration()).thenReturn(new Configuration(params));
}
@@ -20,7 +20,6 @@ import static org.mockito.Mockito.mock;
import java.net.URI;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -212,11 +211,7 @@ public class ThingTypeBuilderTest {
}
private Map<String, String> mockProperties() {
Map<String, String> result = new HashMap<>();
result.put("key1", "value1");
result.put("key2", "value2");
return result;
return Map.of("key1", "value1", "key2", "value2");
}
private <T> List<T> mockList(Class<T> entityClass, int size) {

Some files were not shown because too many files have changed in this diff Show More