mirror of
https://github.com/danieldemus/openhab-core.git
synced 2026-07-29 12:34:22 +02:00
Simplify adding elements to Collections (#4006)
* Simplify adding elements to Collections This optimizes and simplifies the code that adds elements to Collections. Signed-off-by: Wouter Born <github@maindrain.net>
This commit is contained in:
+1
-2
@@ -164,8 +164,7 @@ public class ScriptedAutomationManager {
|
|||||||
// triggers are optional
|
// triggers are optional
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Action> actions = new ArrayList<>();
|
List<Action> actions = new ArrayList<>(element.getActions());
|
||||||
actions.addAll(element.getActions());
|
|
||||||
|
|
||||||
if (element instanceof SimpleRuleActionHandler handler) {
|
if (element instanceof SimpleRuleActionHandler handler) {
|
||||||
String privId = addPrivateActionHandler(new SimpleRuleActionHandlerDelegate(handler));
|
String privId = addPrivateActionHandler(new SimpleRuleActionHandlerDelegate(handler));
|
||||||
|
|||||||
+1
-3
@@ -87,9 +87,7 @@ public class RulePredicates {
|
|||||||
*/
|
*/
|
||||||
public static Predicate<Rule> hasAnyOfPrefixes(String... prefixes) {
|
public static Predicate<Rule> hasAnyOfPrefixes(String... prefixes) {
|
||||||
final HashSet<String> namespaceSet = new HashSet<>(prefixes.length);
|
final HashSet<String> namespaceSet = new HashSet<>(prefixes.length);
|
||||||
for (final String namespace : prefixes) {
|
namespaceSet.addAll(Arrays.asList(prefixes));
|
||||||
namespaceSet.add(namespace);
|
|
||||||
}
|
|
||||||
|
|
||||||
// this will even work for null namespace
|
// this will even work for null namespace
|
||||||
return r -> namespaceSet.contains(getPrefix(r));
|
return r -> namespaceSet.contains(getPrefix(r));
|
||||||
|
|||||||
+2
-2
@@ -396,8 +396,8 @@ public class Printer {
|
|||||||
int[] columnWidths = new int[] { COLUMN_PROPERTY_VALUE };
|
int[] columnWidths = new int[] { COLUMN_PROPERTY_VALUE };
|
||||||
List<String> columnValues = new ArrayList<>();
|
List<String> columnValues = new ArrayList<>();
|
||||||
columnValues.add(module.getId());
|
columnValues.add(module.getId());
|
||||||
List<String> moduleContent = new ArrayList<>();
|
List<String> moduleContent = new ArrayList<>(
|
||||||
moduleContent.addAll(Utils.getTableTitle(Utils.getRow(columnWidths, columnValues), COLUMN_PROPERTY_VALUE));
|
Utils.getTableTitle(Utils.getRow(columnWidths, columnValues), COLUMN_PROPERTY_VALUE));
|
||||||
|
|
||||||
columnWidths = new int[] { COLUMN_CONFIG_PARAMETER, COLUMN_CONFIG_PARAMETER_VALUE };
|
columnWidths = new int[] { COLUMN_CONFIG_PARAMETER, COLUMN_CONFIG_PARAMETER_VALUE };
|
||||||
columnValues.set(0, ID);
|
columnValues.set(0, ID);
|
||||||
|
|||||||
+2
-9
@@ -126,12 +126,7 @@ public class ConfigDescriptionRegistry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Now convert the map into the collection
|
// Now convert the map into the collection
|
||||||
Collection<ConfigDescription> configDescriptions = new ArrayList<>(configMap.size());
|
return Collections.unmodifiableCollection(new ArrayList<>(configMap.values()));
|
||||||
for (ConfigDescription configDescription : configMap.values()) {
|
|
||||||
configDescriptions.add(configDescription);
|
|
||||||
}
|
|
||||||
|
|
||||||
return Collections.unmodifiableCollection(configDescriptions);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -245,10 +240,8 @@ public class ConfigDescriptionRegistry {
|
|||||||
*/
|
*/
|
||||||
private ConfigDescriptionParameter getConfigOptions(URI uri, Set<URI> aliases, ConfigDescriptionParameter parameter,
|
private ConfigDescriptionParameter getConfigOptions(URI uri, Set<URI> aliases, ConfigDescriptionParameter parameter,
|
||||||
@Nullable Locale locale) {
|
@Nullable Locale locale) {
|
||||||
List<ParameterOption> options = new ArrayList<>();
|
|
||||||
|
|
||||||
// Add all the existing options that may be provided by the initial config description provider
|
// Add all the existing options that may be provided by the initial config description provider
|
||||||
options.addAll(parameter.getOptions());
|
List<ParameterOption> options = new ArrayList<>(parameter.getOptions());
|
||||||
|
|
||||||
boolean found = fillFromProviders(uri, parameter, locale, options);
|
boolean found = fillFromProviders(uri, parameter, locale, options);
|
||||||
|
|
||||||
|
|||||||
+1
-3
@@ -71,9 +71,7 @@ public class MetadataConfigDescriptionProviderImpl implements ConfigDescriptionP
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<ConfigDescription> getConfigDescriptions(@Nullable Locale locale) {
|
public Collection<ConfigDescription> getConfigDescriptions(@Nullable Locale locale) {
|
||||||
List<ConfigDescription> ret = new LinkedList<>();
|
return new LinkedList<>(getValueConfigDescriptions(locale));
|
||||||
ret.addAll(getValueConfigDescriptions(locale));
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+1
-4
@@ -17,7 +17,6 @@ import java.util.Collection;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
|
||||||
import java.util.SortedMap;
|
import java.util.SortedMap;
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
|
|
||||||
@@ -64,9 +63,7 @@ public class ConsoleSupportEclipse implements CommandProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Collection<ConsoleCommandExtension> getConsoleCommandExtensions() {
|
private Collection<ConsoleCommandExtension> getConsoleCommandExtensions() {
|
||||||
final Set<ConsoleCommandExtension> set = new HashSet<>();
|
return new HashSet<>(consoleCommandExtensions.values());
|
||||||
set.addAll(consoleCommandExtensions.values());
|
|
||||||
return set;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+1
-3
@@ -175,9 +175,7 @@ public class ChannelTypeResource implements RESTResource {
|
|||||||
for (ProfileType profileType : profileTypeRegistry.getProfileTypes()) {
|
for (ProfileType profileType : profileTypeRegistry.getProfileTypes()) {
|
||||||
if (profileType instanceof TriggerProfileType type) {
|
if (profileType instanceof TriggerProfileType type) {
|
||||||
if (type.getSupportedChannelTypeUIDs().contains(ctUID)) {
|
if (type.getSupportedChannelTypeUIDs().contains(ctUID)) {
|
||||||
for (String itemType : profileType.getSupportedItemTypes()) {
|
result.addAll(profileType.getSupportedItemTypes());
|
||||||
result.add(itemType);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-5
@@ -175,11 +175,7 @@ public class ExpiringCacheMap<K, V> {
|
|||||||
* @return the set of all keys
|
* @return the set of all keys
|
||||||
*/
|
*/
|
||||||
public synchronized Set<K> keys() {
|
public synchronized Set<K> keys() {
|
||||||
final Set<K> keys = new LinkedHashSet<>();
|
return new LinkedHashSet<>(items.keySet());
|
||||||
for (final K key : items.keySet()) {
|
|
||||||
keys.add(key);
|
|
||||||
}
|
|
||||||
return keys;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+2
-3
@@ -13,6 +13,7 @@
|
|||||||
package org.openhab.core.internal.i18n;
|
package org.openhab.core.internal.i18n;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -127,9 +128,7 @@ public class ResourceBundleTracker extends BundleTracker {
|
|||||||
List<Bundle> hosts = new ArrayList<>();
|
List<Bundle> hosts = new ArrayList<>();
|
||||||
Bundle[] bundles = pkgAdmin.getHosts(fragment);
|
Bundle[] bundles = pkgAdmin.getHosts(fragment);
|
||||||
if (bundles != null) {
|
if (bundles != null) {
|
||||||
for (int i = 0; i < bundles.length; i++) {
|
hosts.addAll(Arrays.asList(bundles));
|
||||||
hosts.add(bundles[i]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return hosts;
|
return hosts;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user