SOLR-13655:Upgrade Collections.unModifiableSet to Set.of and Set.copyOf (#817)

This commit is contained in:
Atri Sharma 2019-08-24 03:01:28 +05:30 committed by Tomas Fernandez Lobbe
parent 07f1364800
commit 19aecb0f7d
14 changed files with 29 additions and 51 deletions

View File

@ -16,12 +16,11 @@
*/
package org.apache.solr.handler.dataimport.config;
import org.apache.solr.handler.dataimport.SolrWriter;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import org.apache.solr.handler.dataimport.SolrWriter;
public class ConfigNameConstants {
public static final String SCRIPT = "script";
@ -55,6 +54,6 @@ public class ConfigNameConstants {
rw.add("functions");
rw.add("session");
rw.add(SolrWriter.LAST_INDEX_KEY);
RESERVED_WORDS = Collections.unmodifiableSet(rw);
}
RESERVED_WORDS = Set.copyOf(rw);
}
}

View File

@ -19,9 +19,7 @@ package org.apache.solr.cloud.api.collections;
import java.lang.invoke.MethodHandles;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
@ -58,12 +56,12 @@ public class CategoryRoutedAlias extends RoutedAlias {
* Parameters required for creating a category routed alias
*/
@SuppressWarnings("WeakerAccess")
public static final Set<String> REQUIRED_ROUTER_PARAMS = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
public static final Set<String> REQUIRED_ROUTER_PARAMS = Set.of(
CommonParams.NAME,
ROUTER_TYPE_NAME,
ROUTER_FIELD,
ROUTER_MAX_CARDINALITY
)));
);
public static final String ROUTER_MUST_MATCH = "router.mustMatch";
@ -71,9 +69,9 @@ public class CategoryRoutedAlias extends RoutedAlias {
* Optional parameters for creating a category routed alias excluding parameters for collection creation.
*/
@SuppressWarnings("WeakerAccess")
public static final Set<String> OPTIONAL_ROUTER_PARAMS = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
public static final Set<String> OPTIONAL_ROUTER_PARAMS = Set.of(
ROUTER_MAX_CARDINALITY,
ROUTER_MUST_MATCH)));
ROUTER_MUST_MATCH);
private Aliases aliases;
private final String aliasName;

View File

@ -23,7 +23,6 @@ import java.lang.invoke.MethodHandles;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
@ -43,9 +42,9 @@ import java.util.concurrent.locks.ReentrantLock;
import java.util.stream.Collectors;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.apache.solr.client.solrj.cloud.autoscaling.AutoScalingConfig;
import org.apache.solr.client.solrj.cloud.DistribStateManager;
import org.apache.solr.client.solrj.cloud.SolrCloudManager;
import org.apache.solr.client.solrj.cloud.autoscaling.AutoScalingConfig;
import org.apache.solr.client.solrj.cloud.autoscaling.TriggerEventProcessorStage;
import org.apache.solr.client.solrj.cloud.autoscaling.VersionedData;
import org.apache.solr.client.solrj.request.CollectionAdminRequest.RequestStatusResponse;
@ -508,7 +507,7 @@ public class ScheduledTriggers implements Closeable {
* @return an unmodifiable set of names of all triggers being managed by this class
*/
public synchronized Set<String> getScheduledTriggerNames() {
return Collections.unmodifiableSet(new HashSet<>(scheduledTriggerWrappers.keySet())); // shallow copy
return Set.copyOf(scheduledTriggerWrappers.keySet()); // shallow copy
}
/**

View File

@ -21,7 +21,6 @@ import java.io.UnsupportedEncodingException;
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.Objects;
@ -45,7 +44,7 @@ public class SnapshotClusterStateProvider implements ClusterStateProvider {
final Map<String, Object> clusterProperties;
public SnapshotClusterStateProvider(ClusterStateProvider other) throws Exception {
liveNodes = Collections.unmodifiableSet(new HashSet<>(other.getLiveNodes()));
liveNodes = Set.copyOf(other.getLiveNodes());
ClusterState otherState = other.getClusterState();
clusterState = new ClusterState(otherState.getZNodeVersion(), liveNodes, otherState.getCollectionsMap());
clusterProperties = new HashMap<>(other.getClusterProperties());
@ -53,7 +52,7 @@ public class SnapshotClusterStateProvider implements ClusterStateProvider {
public SnapshotClusterStateProvider(Map<String, Object> snapshot) {
Objects.requireNonNull(snapshot);
liveNodes = Collections.unmodifiableSet(new HashSet<>((Collection<String>)snapshot.getOrDefault("liveNodes", Collections.emptySet())));
liveNodes = Set.copyOf((Collection<String>)snapshot.getOrDefault("liveNodes", Collections.emptySet()));
clusterProperties = (Map<String, Object>)snapshot.getOrDefault("clusterProperties", Collections.emptyMap());
Map<String, Object> stateMap = new HashMap<>((Map<String, Object>)snapshot.getOrDefault("clusterState", Collections.emptyMap()));
Number version = (Number)stateMap.remove("version");

View File

@ -16,7 +16,6 @@
*/
package org.apache.solr.core;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
@ -49,7 +48,7 @@ public class InitParams {
Set<String> paths = null;
String pathStr = p.attributes.get(PATH);
if (pathStr != null) {
paths = Collections.unmodifiableSet(new HashSet<>(StrUtils.splitSmart(pathStr, ',')));
paths = Set.copyOf(StrUtils.splitSmart(pathStr, ','));
}
this.paths = paths;
NamedList nl = (NamedList) p.initArgs.get(DEFAULTS);

View File

@ -18,10 +18,8 @@ package org.apache.solr.handler.component;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
@ -214,7 +212,7 @@ public class DebugComponent extends SearchComponent
}
}
private final static Set<String> EXCLUDE_SET = Collections.unmodifiableSet(new HashSet<>(Arrays.asList("explain")));
private final static Set<String> EXCLUDE_SET = Set.of("explain");
@Override
public void finishStage(ResponseBuilder rb) {

View File

@ -16,14 +16,10 @@
*/
package org.apache.solr.util;
import java.util.TimeZone;
import java.util.Set;
import java.util.HashSet;
import java.util.Collections;
import java.util.Arrays;
import java.util.regex.Pattern;
import java.util.TimeZone;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.solr.common.SolrException;
@ -44,8 +40,7 @@ public final class TimeZoneUtils {
* @see TimeZone#getAvailableIDs
*/
public static final Set<String> KNOWN_TIMEZONE_IDS
= Collections.unmodifiableSet(new HashSet<>
(Arrays.asList(TimeZone.getAvailableIDs())));
= Set.of(TimeZone.getAvailableIDs());
/**
* This method is provided as a replacement for TimeZone.getTimeZone but

View File

@ -23,7 +23,6 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
@ -32,8 +31,6 @@ import org.apache.solr.client.solrj.request.RequestWriter;
import org.apache.solr.common.params.SolrParams;
import org.apache.solr.common.util.ContentStream;
import static java.util.Collections.unmodifiableSet;
/**
*
*
@ -58,11 +55,11 @@ public abstract class SolrRequest<T extends SolrResponse> implements Serializabl
DELETE
};
public static final Set<String> SUPPORTED_METHODS = unmodifiableSet(new HashSet<>(Arrays.<String>asList(
public static final Set<String> SUPPORTED_METHODS = Set.of(
METHOD.GET.toString(),
METHOD.POST.toString(),
METHOD.PUT.toString(),
METHOD.DELETE.toString())));
METHOD.DELETE.toString());
private METHOD method = METHOD.GET;
private String path = null;

View File

@ -78,7 +78,7 @@ public class Policy implements MapWriter {
public static final String POLICIES = "policies";
public static final String CLUSTER_POLICY = "cluster-policy";
public static final String CLUSTER_PREFERENCES = "cluster-preferences";
public static final Set<String> GLOBAL_ONLY_TAGS = Collections.unmodifiableSet(new HashSet<>(Arrays.asList("cores", CollectionAdminParams.WITH_COLLECTION)));
public static final Set<String> GLOBAL_ONLY_TAGS = Set.of("cores", CollectionAdminParams.WITH_COLLECTION);
public static final List<Preference> DEFAULT_PREFERENCES = Collections.unmodifiableList(
Arrays.asList(
// NOTE - if you change this, make sure to update the solrcloud-autoscaling-overview.adoc which

View File

@ -23,7 +23,6 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.function.Consumer;
@ -32,7 +31,7 @@ import org.apache.solr.common.cloud.rule.ImplicitSnitch;
import static java.util.Collections.emptySet;
import static java.util.Collections.unmodifiableMap;
import static java.util.Collections.unmodifiableSet;
/**
* A Variable Type used in Autoscaling policy rules. Each variable type may have unique implementation
@ -277,7 +276,7 @@ public interface Variable {
this.metricsAttribute = readStr(meta.metricsKey());
this.supportedComputedTypes = meta.computedValues()[0] == ComputedType.NULL ?
emptySet() :
unmodifiableSet(new HashSet(Arrays.asList(meta.computedValues())));
Set.of(meta.computedValues());
this.wildCards = readSet(meta.wildCards());
}
@ -297,7 +296,7 @@ public interface Variable {
Set<String> readSet(String[] vals) {
if (NULL.equals(vals[0])) return emptySet();
return unmodifiableSet(new HashSet<>(Arrays.asList(vals)));
return Set.of(vals);
}
@Override

View File

@ -99,7 +99,7 @@ public class DelegationTokenHttpSolrClient extends HttpSolrClient {
@Override
public void setQueryParams(Set<String> queryParams) {
queryParams = queryParams == null ?
Collections.unmodifiableSet(new HashSet<String>(Arrays.asList(DELEGATION_TOKEN_PARAM))): queryParams;
Set.of(DELEGATION_TOKEN_PARAM): queryParams;
if (!queryParams.contains(DELEGATION_TOKEN_PARAM)) {
queryParams = new HashSet<String>(queryParams);
queryParams.add(DELEGATION_TOKEN_PARAM);

View File

@ -73,7 +73,6 @@ import static java.util.Collections.EMPTY_MAP;
import static java.util.Collections.emptyMap;
import static java.util.Collections.emptySet;
import static java.util.Collections.emptySortedSet;
import static java.util.Collections.unmodifiableSet;
import static org.apache.solr.common.util.Utils.fromJSON;
public class ZkStateReader implements SolrCloseable {
@ -272,7 +271,7 @@ public class ZkStateReader implements SolrCloseable {
}
public static final Set<String> KNOWN_CLUSTER_PROPS = unmodifiableSet(new HashSet<>(asList(
public static final Set<String> KNOWN_CLUSTER_PROPS = Set.of(
LEGACY_CLOUD,
URL_SCHEME,
AUTO_ADD_REPLICAS,
@ -281,7 +280,7 @@ public class ZkStateReader implements SolrCloseable {
MAX_CORES_PER_NODE,
SAMPLE_PERCENTAGE,
SOLR_ENVIRONMENT,
CollectionAdminParams.DEFAULTS)));
CollectionAdminParams.DEFAULTS);
/**
* Returns config set name for collection.

View File

@ -22,7 +22,6 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
@ -54,7 +53,7 @@ public class ImplicitSnitch extends Snitch {
public static final String HEAPUSAGE = "heapUsage";
public static final String DISKTYPE = "diskType";
public static final List<String> IP_SNITCHES = Collections.unmodifiableList(Arrays.asList("ip_1", "ip_2", "ip_3", "ip_4"));
public static final Set<String> tags = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(NODE, PORT, HOST, CORES, DISK, ROLE, "ip_1", "ip_2", "ip_3", "ip_4")));
public static final Set<String> tags = Set.of(NODE, PORT, HOST, CORES, DISK, ROLE, "ip_1", "ip_2", "ip_3", "ip_4");
@Override
public void getTags(String solrNode, Set<String> requestedTags, SnitchContext ctx) {

View File

@ -16,9 +16,6 @@
*/
package org.apache.solr.common.params;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Locale;
import java.util.Set;
@ -196,7 +193,7 @@ public interface CommonParams {
String OK = "OK";
String FAILURE = "FAILURE";
Set<String> ADMIN_PATHS = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
Set<String> ADMIN_PATHS = Set.of(
CORES_HANDLER_PATH,
COLLECTIONS_HANDLER_PATH,
HEALTH_CHECK_HANDLER_PATH,
@ -209,7 +206,7 @@ public interface CommonParams {
AUTOSCALING_PATH,
AUTOSCALING_HISTORY_PATH,
AUTOSCALING_DIAGNOSTICS_PATH,
AUTOSCALING_SUGGESTIONS_PATH)));
AUTOSCALING_SUGGESTIONS_PATH);
String APISPEC_LOCATION = "apispec/";
String INTROSPECT = "/_introspect";