diff --git a/core/src/main/java/org/elasticsearch/cluster/metadata/AliasMetaData.java b/core/src/main/java/org/elasticsearch/cluster/metadata/AliasMetaData.java index fb640eedc5a..c083396482e 100644 --- a/core/src/main/java/org/elasticsearch/cluster/metadata/AliasMetaData.java +++ b/core/src/main/java/org/elasticsearch/cluster/metadata/AliasMetaData.java @@ -19,7 +19,6 @@ package org.elasticsearch.cluster.metadata; -import com.google.common.collect.ImmutableSet; import org.elasticsearch.ElasticsearchGenerationException; import org.elasticsearch.cluster.AbstractDiffable; import org.elasticsearch.common.Strings; @@ -36,6 +35,8 @@ import java.util.Collections; import java.util.Map; import java.util.Set; +import static java.util.Collections.emptySet; + /** * */ @@ -61,7 +62,7 @@ public class AliasMetaData extends AbstractDiffable { if (searchRouting != null) { searchRoutingValues = Collections.unmodifiableSet(Strings.splitStringByCommaToSet(searchRouting)); } else { - searchRoutingValues = ImmutableSet.of(); + searchRoutingValues = emptySet(); } } diff --git a/core/src/main/java/org/elasticsearch/cluster/metadata/MetaData.java b/core/src/main/java/org/elasticsearch/cluster/metadata/MetaData.java index 3ca3ec39bbd..d8b98d62564 100644 --- a/core/src/main/java/org/elasticsearch/cluster/metadata/MetaData.java +++ b/core/src/main/java/org/elasticsearch/cluster/metadata/MetaData.java @@ -22,7 +22,7 @@ package org.elasticsearch.cluster.metadata; import com.carrotsearch.hppc.ObjectHashSet; import com.carrotsearch.hppc.cursors.ObjectCursor; import com.carrotsearch.hppc.cursors.ObjectObjectCursor; -import com.google.common.collect.ImmutableSet; + import org.apache.lucene.util.CollectionUtil; import org.elasticsearch.cluster.Diff; import org.elasticsearch.cluster.Diffable; @@ -59,12 +59,26 @@ import org.elasticsearch.rest.RestStatus; import org.elasticsearch.search.warmer.IndexWarmersMetaData; import java.io.IOException; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; +import java.util.EnumSet; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.SortedMap; +import java.util.TreeMap; import java.util.stream.Collectors; +import static java.util.Collections.unmodifiableSet; import static org.elasticsearch.common.settings.Settings.readSettingsFromStream; import static org.elasticsearch.common.settings.Settings.settingsBuilder; import static org.elasticsearch.common.settings.Settings.writeSettingsToStream; +import static org.elasticsearch.common.util.set.Sets.newHashSet; public class MetaData implements Iterable, Diffable, FromXContentBuilder, ToXContent { @@ -729,16 +743,16 @@ public class MetaData implements Iterable, Diffable, Fr } /** All known byte-sized cluster settings. */ - public static final Set CLUSTER_BYTES_SIZE_SETTINGS = ImmutableSet.of( + public static final Set CLUSTER_BYTES_SIZE_SETTINGS = unmodifiableSet(newHashSet( IndicesStore.INDICES_STORE_THROTTLE_MAX_BYTES_PER_SEC, RecoverySettings.INDICES_RECOVERY_FILE_CHUNK_SIZE, RecoverySettings.INDICES_RECOVERY_TRANSLOG_SIZE, RecoverySettings.INDICES_RECOVERY_MAX_BYTES_PER_SEC, - RecoverySettings.INDICES_RECOVERY_MAX_SIZE_PER_SEC); + RecoverySettings.INDICES_RECOVERY_MAX_SIZE_PER_SEC)); /** All known time cluster settings. */ - public static final Set CLUSTER_TIME_SETTINGS = ImmutableSet.of( + public static final Set CLUSTER_TIME_SETTINGS = unmodifiableSet(newHashSet( IndicesTTLService.INDICES_TTL_INTERVAL, RecoverySettings.INDICES_RECOVERY_RETRY_DELAY_STATE_SYNC, RecoverySettings.INDICES_RECOVERY_RETRY_DELAY_NETWORK, @@ -749,7 +763,7 @@ public class MetaData implements Iterable, Diffable, Fr InternalClusterInfoService.INTERNAL_CLUSTER_INFO_UPDATE_INTERVAL, InternalClusterInfoService.INTERNAL_CLUSTER_INFO_TIMEOUT, DiscoverySettings.PUBLISH_TIMEOUT, - InternalClusterService.SETTING_CLUSTER_SERVICE_SLOW_TASK_LOGGING_THRESHOLD); + InternalClusterService.SETTING_CLUSTER_SERVICE_SLOW_TASK_LOGGING_THRESHOLD)); /** As of 2.0 we require units for time and byte-sized settings. This methods adds default units to any cluster settings that don't * specify a unit. */ diff --git a/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexUpgradeService.java b/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexUpgradeService.java index 365783b8bdd..a17fe044dcb 100644 --- a/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexUpgradeService.java +++ b/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexUpgradeService.java @@ -19,6 +19,7 @@ package org.elasticsearch.cluster.metadata; import com.carrotsearch.hppc.cursors.ObjectCursor; + import org.apache.lucene.analysis.Analyzer; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.Version; @@ -29,7 +30,6 @@ import org.elasticsearch.cluster.routing.UnassignedInfo; import org.elasticsearch.common.component.AbstractComponent; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; -import com.google.common.collect.ImmutableSet; import org.elasticsearch.index.Index; import org.elasticsearch.index.analysis.AnalysisService; import org.elasticsearch.index.analysis.NamedAnalyzer; @@ -41,6 +41,9 @@ import org.elasticsearch.script.ScriptService; import java.util.Locale; import java.util.Set; +import static java.util.Collections.unmodifiableSet; +import static org.elasticsearch.common.util.set.Sets.newHashSet; + /** * This service is responsible for upgrading legacy index metadata to the current version *

@@ -217,7 +220,7 @@ public class MetaDataIndexUpgradeService extends AbstractComponent { } /** All known byte-sized settings for an index. */ - public static final Set INDEX_BYTES_SIZE_SETTINGS = ImmutableSet.of( + public static final Set INDEX_BYTES_SIZE_SETTINGS = unmodifiableSet(newHashSet( "index.merge.policy.floor_segment", "index.merge.policy.max_merged_segment", "index.merge.policy.max_merge_size", @@ -227,10 +230,10 @@ public class MetaDataIndexUpgradeService extends AbstractComponent { "index.store.throttle.max_bytes_per_sec", "index.translog.flush_threshold_size", "index.translog.fs.buffer_size", - "index.version_map_size"); + "index.version_map_size")); /** All known time settings for an index. */ - public static final Set INDEX_TIME_SETTINGS = ImmutableSet.of( + public static final Set INDEX_TIME_SETTINGS = unmodifiableSet(newHashSet( "index.gateway.wait_for_mapping_update_post_recovery", "index.shard.wait_for_mapping_update_post_recovery", "index.gc_deletes", @@ -252,7 +255,7 @@ public class MetaDataIndexUpgradeService extends AbstractComponent { "index.translog.flush_threshold_period", "index.translog.interval", "index.translog.sync_interval", - UnassignedInfo.INDEX_DELAYED_NODE_LEFT_TIMEOUT_SETTING); + UnassignedInfo.INDEX_DELAYED_NODE_LEFT_TIMEOUT_SETTING)); /** * Elasticsearch 2.0 requires units on byte/memory and time settings; this method adds the default unit to any such settings that are diff --git a/core/src/main/java/org/elasticsearch/common/Strings.java b/core/src/main/java/org/elasticsearch/common/Strings.java index 08777696bc5..641db0ef963 100644 --- a/core/src/main/java/org/elasticsearch/common/Strings.java +++ b/core/src/main/java/org/elasticsearch/common/Strings.java @@ -19,7 +19,6 @@ package org.elasticsearch.common; -import com.google.common.collect.ImmutableSet; import org.apache.lucene.util.BytesRefBuilder; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.io.FastStringReader; @@ -30,7 +29,21 @@ import org.elasticsearch.common.xcontent.json.JsonXContent; import java.io.BufferedReader; import java.io.IOException; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Properties; +import java.util.Random; +import java.util.Set; +import java.util.StringTokenizer; +import java.util.TreeSet; + +import static java.util.Collections.unmodifiableSet; +import static org.elasticsearch.common.util.set.Sets.newHashSet; /** * @@ -443,7 +456,8 @@ public class Strings { return sb.toString(); } - public static final ImmutableSet INVALID_FILENAME_CHARS = ImmutableSet.of('\\', '/', '*', '?', '"', '<', '>', '|', ' ', ','); + public static final Set INVALID_FILENAME_CHARS = unmodifiableSet( + newHashSet('\\', '/', '*', '?', '"', '<', '>', '|', ' ', ',')); public static boolean validFileName(String fileName) { for (int i = 0; i < fileName.length(); i++) { @@ -596,7 +610,7 @@ public class Strings { result[res++] = builder.toString(); builder.setLength(0); } - + } else { builder.append(s.charAt(i)); } @@ -1010,11 +1024,11 @@ public class Strings { private Strings() { } - + public static byte[] toUTF8Bytes(CharSequence charSequence) { return toUTF8Bytes(charSequence, new BytesRefBuilder()); } - + public static byte[] toUTF8Bytes(CharSequence charSequence, BytesRefBuilder spare) { spare.copyChars(charSequence); return Arrays.copyOf(spare.bytes(), spare.length()); diff --git a/core/src/main/java/org/elasticsearch/common/inject/BindingProcessor.java b/core/src/main/java/org/elasticsearch/common/inject/BindingProcessor.java index 0ef8c26a69d..e560eeb1efd 100644 --- a/core/src/main/java/org/elasticsearch/common/inject/BindingProcessor.java +++ b/core/src/main/java/org/elasticsearch/common/inject/BindingProcessor.java @@ -16,7 +16,6 @@ package org.elasticsearch.common.inject; -import com.google.common.collect.ImmutableSet; import org.elasticsearch.common.inject.internal.Annotations; import org.elasticsearch.common.inject.internal.BindingImpl; import org.elasticsearch.common.inject.internal.Errors; @@ -47,6 +46,9 @@ import java.util.ArrayList; import java.util.List; import java.util.Set; +import static java.util.Collections.unmodifiableSet; +import static org.elasticsearch.common.util.set.Sets.newHashSet; + /** * Handles {@link Binder#bind} and {@link Binder#bindConstant} elements. * @@ -282,7 +284,7 @@ class BindingProcessor extends AbstractProcessor { // It's unfortunate that we have to maintain a blacklist of specific // classes, but we can't easily block the whole package because of // all our unit tests. - private static final Set> FORBIDDEN_TYPES = ImmutableSet.of( + private static final Set> FORBIDDEN_TYPES = unmodifiableSet(newHashSet( AbstractModule.class, Binder.class, Binding.class, @@ -292,7 +294,7 @@ class BindingProcessor extends AbstractProcessor { Module.class, Provider.class, Scope.class, - TypeLiteral.class); + TypeLiteral.class)); // TODO(jessewilson): fix BuiltInModule, then add Stage interface CreationListener { diff --git a/core/src/main/java/org/elasticsearch/common/inject/InheritingState.java b/core/src/main/java/org/elasticsearch/common/inject/InheritingState.java index 12c317b1b08..eb05b1dbe6e 100644 --- a/core/src/main/java/org/elasticsearch/common/inject/InheritingState.java +++ b/core/src/main/java/org/elasticsearch/common/inject/InheritingState.java @@ -16,14 +16,12 @@ package org.elasticsearch.common.inject; -import com.google.common.collect.ImmutableSet; import org.elasticsearch.common.inject.internal.BindingImpl; import org.elasticsearch.common.inject.internal.Errors; import org.elasticsearch.common.inject.internal.InstanceBindingImpl; import org.elasticsearch.common.inject.internal.InternalFactory; import org.elasticsearch.common.inject.internal.MatcherAndConverter; import org.elasticsearch.common.inject.internal.SourceProvider; -import org.elasticsearch.common.inject.spi.InjectionPoint; import org.elasticsearch.common.inject.spi.TypeListenerBinding; import java.lang.annotation.Annotation; @@ -35,6 +33,8 @@ import java.util.List; import java.util.Map; import java.util.Objects; +import static java.util.Collections.emptySet; + /** * @author jessewilson@google.com (Jesse Wilson) */ @@ -155,7 +155,8 @@ class InheritingState implements State { Key key = entry.getKey(); BindingImpl binding = (BindingImpl) entry.getValue(); Object value = binding.getProvider().get(); - x.put(key, new InstanceBindingImpl(injector, key, SourceProvider.UNKNOWN_SOURCE, new InternalFactory.Instance(value), ImmutableSet.of(), value)); + x.put(key, new InstanceBindingImpl(injector, key, SourceProvider.UNKNOWN_SOURCE, new InternalFactory.Instance(value), + emptySet(), value)); } this.explicitBindingsMutable.clear(); this.explicitBindingsMutable.putAll(x); diff --git a/core/src/main/java/org/elasticsearch/common/inject/InjectorImpl.java b/core/src/main/java/org/elasticsearch/common/inject/InjectorImpl.java index 15fb181b56f..7ad62af64ea 100644 --- a/core/src/main/java/org/elasticsearch/common/inject/InjectorImpl.java +++ b/core/src/main/java/org/elasticsearch/common/inject/InjectorImpl.java @@ -16,7 +16,6 @@ package org.elasticsearch.common.inject; -import com.google.common.collect.ImmutableSet; import org.elasticsearch.common.Classes; import org.elasticsearch.common.inject.internal.Annotations; import org.elasticsearch.common.inject.internal.BindingImpl; @@ -35,7 +34,6 @@ import org.elasticsearch.common.inject.internal.ToStringBuilder; import org.elasticsearch.common.inject.spi.BindingTargetVisitor; import org.elasticsearch.common.inject.spi.ConvertedConstantBinding; import org.elasticsearch.common.inject.spi.Dependency; -import org.elasticsearch.common.inject.spi.InjectionPoint; import org.elasticsearch.common.inject.spi.ProviderBinding; import org.elasticsearch.common.inject.spi.ProviderKeyBinding; import org.elasticsearch.common.inject.util.Providers; @@ -54,6 +52,8 @@ import java.util.List; import java.util.Map; import java.util.Set; +import static java.util.Collections.emptySet; +import static java.util.Collections.singleton; import static org.elasticsearch.common.inject.internal.Annotations.findScopeAnnotation; /** @@ -221,7 +221,7 @@ class InjectorImpl implements Injector, Lookups { return new InstanceBindingImpl<>(this, key, SourceProvider.UNKNOWN_SOURCE, - factory, ImmutableSet.of(), membersInjector); + factory, emptySet(), membersInjector); } /** @@ -379,7 +379,7 @@ class InjectorImpl implements Injector, Lookups { @Override public Set> getDependencies() { - return ImmutableSet.>of(Dependency.get(getSourceKey())); + return singleton(Dependency.get(getSourceKey())); } @Override @@ -502,7 +502,7 @@ class InjectorImpl implements Injector, Lookups { InternalFactory> factory = new ConstantFactory<>( Initializables.of(value)); return new InstanceBindingImpl<>(this, key, SourceProvider.UNKNOWN_SOURCE, - factory, ImmutableSet.of(), value); + factory, emptySet(), value); } /** diff --git a/core/src/main/java/org/elasticsearch/common/inject/State.java b/core/src/main/java/org/elasticsearch/common/inject/State.java index 0388bb04a68..2337816b01c 100644 --- a/core/src/main/java/org/elasticsearch/common/inject/State.java +++ b/core/src/main/java/org/elasticsearch/common/inject/State.java @@ -16,7 +16,6 @@ package org.elasticsearch.common.inject; -import com.google.common.collect.ImmutableSet; import org.elasticsearch.common.inject.internal.BindingImpl; import org.elasticsearch.common.inject.internal.Errors; import org.elasticsearch.common.inject.internal.MatcherAndConverter; @@ -27,6 +26,8 @@ import java.util.Collections; import java.util.List; import java.util.Map; +import static java.util.Collections.emptySet; + /** * The inheritable data within an injector. This class is intended to allow parent and local * injector data to be accessed as a unit. @@ -79,7 +80,7 @@ interface State { @Override public Iterable getConvertersThisLevel() { - return ImmutableSet.of(); + return emptySet(); } @Override diff --git a/core/src/main/java/org/elasticsearch/common/inject/assistedinject/FactoryProvider.java b/core/src/main/java/org/elasticsearch/common/inject/assistedinject/FactoryProvider.java index fb1395d834c..ea5a664ceb1 100644 --- a/core/src/main/java/org/elasticsearch/common/inject/assistedinject/FactoryProvider.java +++ b/core/src/main/java/org/elasticsearch/common/inject/assistedinject/FactoryProvider.java @@ -17,7 +17,6 @@ package org.elasticsearch.common.inject.assistedinject; import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; import org.elasticsearch.common.inject.ConfigurationException; import org.elasticsearch.common.inject.Inject; @@ -43,6 +42,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import static java.util.Collections.singleton; import static java.util.Collections.unmodifiableSet; /** @@ -338,6 +338,6 @@ public class FactoryProvider implements Provider, HasDependencies { } private static ConfigurationException newConfigurationException(String format, Object... args) { - return new ConfigurationException(ImmutableSet.of(new Message(Errors.format(format, args)))); + return new ConfigurationException(singleton(new Message(Errors.format(format, args)))); } } diff --git a/core/src/main/java/org/elasticsearch/common/inject/internal/Errors.java b/core/src/main/java/org/elasticsearch/common/inject/internal/Errors.java index acfcc178814..d9e193b1f62 100644 --- a/core/src/main/java/org/elasticsearch/common/inject/internal/Errors.java +++ b/core/src/main/java/org/elasticsearch/common/inject/internal/Errors.java @@ -16,8 +16,6 @@ package org.elasticsearch.common.inject.internal; -import com.google.common.collect.ImmutableSet; - import org.apache.lucene.util.CollectionUtil; import org.elasticsearch.common.inject.ConfigurationException; import org.elasticsearch.common.inject.CreationException; @@ -50,6 +48,7 @@ import java.util.Formatter; import java.util.List; import java.util.Locale; +import static java.util.Collections.emptySet; import static java.util.Collections.unmodifiableList; /** @@ -319,7 +318,7 @@ public final class Errors implements Serializable { } else if (throwable instanceof CreationException) { return ((CreationException) throwable).getErrorMessages(); } else { - return ImmutableSet.of(); + return emptySet(); } } diff --git a/core/src/main/java/org/elasticsearch/common/inject/internal/ExposedBindingImpl.java b/core/src/main/java/org/elasticsearch/common/inject/internal/ExposedBindingImpl.java index 335b415fa63..d59a2db4a85 100644 --- a/core/src/main/java/org/elasticsearch/common/inject/internal/ExposedBindingImpl.java +++ b/core/src/main/java/org/elasticsearch/common/inject/internal/ExposedBindingImpl.java @@ -16,7 +16,6 @@ package org.elasticsearch.common.inject.internal; -import com.google.common.collect.ImmutableSet; import org.elasticsearch.common.inject.Binder; import org.elasticsearch.common.inject.Injector; import org.elasticsearch.common.inject.Key; @@ -27,6 +26,8 @@ import org.elasticsearch.common.inject.spi.PrivateElements; import java.util.Set; +import static java.util.Collections.singleton; + public class ExposedBindingImpl extends BindingImpl implements ExposedBinding { private final PrivateElements privateElements; @@ -50,7 +51,7 @@ public class ExposedBindingImpl extends BindingImpl implements ExposedBind @Override public Set> getDependencies() { - return ImmutableSet.>of(Dependency.get(Key.get(Injector.class))); + return singleton(Dependency.get(Key.get(Injector.class))); } @Override diff --git a/core/src/main/java/org/elasticsearch/common/inject/internal/MoreTypes.java b/core/src/main/java/org/elasticsearch/common/inject/internal/MoreTypes.java index 737b8fa7d1c..1b68f2cc113 100644 --- a/core/src/main/java/org/elasticsearch/common/inject/internal/MoreTypes.java +++ b/core/src/main/java/org/elasticsearch/common/inject/internal/MoreTypes.java @@ -18,18 +18,29 @@ package org.elasticsearch.common.inject.internal; import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; + import org.elasticsearch.common.inject.ConfigurationException; import org.elasticsearch.common.inject.TypeLiteral; import org.elasticsearch.common.inject.spi.Message; import java.io.Serializable; -import java.lang.reflect.*; +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.GenericArrayType; +import java.lang.reflect.GenericDeclaration; +import java.lang.reflect.Member; +import java.lang.reflect.Method; +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; +import java.lang.reflect.TypeVariable; +import java.lang.reflect.WildcardType; import java.util.Arrays; import java.util.Map; import java.util.NoSuchElementException; import java.util.Objects; +import static java.util.Collections.singleton; + /** * Static methods for working with types that we aren't publishing in the * public {@code Types} API. @@ -65,7 +76,7 @@ public class MoreTypes { public static TypeLiteral makeKeySafe(TypeLiteral type) { if (!isFullySpecified(type.getType())) { String message = type + " cannot be used as a key; It is not fully specified."; - throw new ConfigurationException(ImmutableSet.of(new Message(message))); + throw new ConfigurationException(singleton(new Message(message))); } @SuppressWarnings("unchecked") diff --git a/core/src/main/java/org/elasticsearch/common/inject/multibindings/MapBinder.java b/core/src/main/java/org/elasticsearch/common/inject/multibindings/MapBinder.java index 81f66561b81..a9a1bb173b7 100644 --- a/core/src/main/java/org/elasticsearch/common/inject/multibindings/MapBinder.java +++ b/core/src/main/java/org/elasticsearch/common/inject/multibindings/MapBinder.java @@ -16,9 +16,12 @@ package org.elasticsearch.common.inject.multibindings; -import com.google.common.collect.ImmutableSet; - -import org.elasticsearch.common.inject.*; +import org.elasticsearch.common.inject.Binder; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.inject.Key; +import org.elasticsearch.common.inject.Module; +import org.elasticsearch.common.inject.Provider; +import org.elasticsearch.common.inject.TypeLiteral; import org.elasticsearch.common.inject.binder.LinkedBindingBuilder; import org.elasticsearch.common.inject.multibindings.Multibinder.RealMultibinder; import org.elasticsearch.common.inject.spi.Dependency; @@ -32,6 +35,7 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Set; +import static java.util.Collections.singleton; import static org.elasticsearch.common.inject.util.Types.newParameterizedType; import static org.elasticsearch.common.inject.util.Types.newParameterizedTypeWithOwner; @@ -261,15 +265,15 @@ public abstract class MapBinder { binder.getProvider(valueKey))); return binder.bind(valueKey); } - + public static class MapBinderProviderWithDependencies implements ProviderWithDependencies>> { private Map> providerMap; - + @SuppressWarnings("rawtypes") // code is silly stupid with generics private final RealMapBinder binder; private final Set> dependencies; private final Provider>>> provider; - + @SuppressWarnings("rawtypes") // code is silly stupid with generics MapBinderProviderWithDependencies(RealMapBinder binder, Set> dependencies, Provider>>> provider) { this.binder = binder; @@ -306,8 +310,7 @@ public abstract class MapBinder { public void configure(Binder binder) { Multibinder.checkConfiguration(!isInitialized(), "MapBinder was already initialized"); - final ImmutableSet> dependencies - = ImmutableSet.>of(Dependency.get(entrySetBinder.getSetKey())); + final Set> dependencies = singleton(Dependency.get(entrySetBinder.getSetKey())); // binds a Map> from a collection of Map> final Provider>>> entrySetProvider = binder diff --git a/core/src/main/java/org/elasticsearch/common/inject/multibindings/Multibinder.java b/core/src/main/java/org/elasticsearch/common/inject/multibindings/Multibinder.java index 1c84f7886d9..56f0ec0f055 100644 --- a/core/src/main/java/org/elasticsearch/common/inject/multibindings/Multibinder.java +++ b/core/src/main/java/org/elasticsearch/common/inject/multibindings/Multibinder.java @@ -16,8 +16,6 @@ package org.elasticsearch.common.inject.multibindings; -import com.google.common.collect.ImmutableSet; - import org.elasticsearch.common.inject.Binder; import org.elasticsearch.common.inject.Binding; import org.elasticsearch.common.inject.ConfigurationException; @@ -44,6 +42,8 @@ import java.util.List; import java.util.Objects; import java.util.Set; +import static java.util.Collections.emptyList; +import static java.util.Collections.singleton; import static java.util.Collections.unmodifiableSet; /** @@ -321,7 +321,7 @@ public abstract class Multibinder { return; } - throw new ConfigurationException(ImmutableSet.of(new Message(Errors.format(format, args)))); + throw new ConfigurationException(singleton(new Message(Errors.format(format, args)))); } static T checkNotNull(T reference, String name) { @@ -330,7 +330,7 @@ public abstract class Multibinder { } NullPointerException npe = new NullPointerException(name); - throw new ConfigurationException(ImmutableSet.of( - new Message(Collections.emptyList(), npe.toString(), npe))); + throw new ConfigurationException(singleton( + new Message(emptyList(), npe.toString(), npe))); } } diff --git a/core/src/main/java/org/elasticsearch/gateway/AsyncShardFetch.java b/core/src/main/java/org/elasticsearch/gateway/AsyncShardFetch.java index eccff4d2bf6..4c72894969e 100644 --- a/core/src/main/java/org/elasticsearch/gateway/AsyncShardFetch.java +++ b/core/src/main/java/org/elasticsearch/gateway/AsyncShardFetch.java @@ -19,7 +19,6 @@ package org.elasticsearch.gateway; import com.carrotsearch.hppc.cursors.ObjectObjectCursor; -import com.google.common.collect.ImmutableSet; import org.elasticsearch.ElasticsearchTimeoutException; import org.elasticsearch.ExceptionsHelper; @@ -45,6 +44,7 @@ import java.util.Iterator; import java.util.Map; import java.util.Set; +import static java.util.Collections.emptySet; import static java.util.Collections.unmodifiableSet; /** @@ -80,6 +80,7 @@ public abstract class AsyncShardFetch implements Rel this.action = (List, T>) action; } + @Override public synchronized void close() { this.closed = true; } @@ -126,7 +127,7 @@ public abstract class AsyncShardFetch implements Rel // if we are still fetching, return null to indicate it if (hasAnyNodeFetching(cache) == true) { - return new FetchResult<>(shardId, null, ImmutableSet.of(), ImmutableSet.of()); + return new FetchResult<>(shardId, null, emptySet(), emptySet()); } else { // nothing to fetch, yay, build the return value Map fetchData = new HashMap<>(); diff --git a/core/src/main/java/org/elasticsearch/gateway/GatewayMetaState.java b/core/src/main/java/org/elasticsearch/gateway/GatewayMetaState.java index 5fbcfcf693d..cb462fbbd78 100644 --- a/core/src/main/java/org/elasticsearch/gateway/GatewayMetaState.java +++ b/core/src/main/java/org/elasticsearch/gateway/GatewayMetaState.java @@ -19,7 +19,6 @@ package org.elasticsearch.gateway; -import com.google.common.collect.ImmutableSet; import org.elasticsearch.Version; import org.elasticsearch.cluster.ClusterChangedEvent; import org.elasticsearch.cluster.ClusterState; @@ -110,7 +109,7 @@ public class GatewayMetaState extends AbstractComponent implements ClusterStateL if (state.blocks().disableStatePersistence()) { // reset the current metadata, we need to start fresh... this.previousMetaData = null; - previouslyWrittenIndices = ImmutableSet.of(); + previouslyWrittenIndices = emptySet(); return; } diff --git a/core/src/main/java/org/elasticsearch/index/fielddata/plain/AbstractAtomicParentChildFieldData.java b/core/src/main/java/org/elasticsearch/index/fielddata/plain/AbstractAtomicParentChildFieldData.java index f1c64dc8219..1a801d75411 100644 --- a/core/src/main/java/org/elasticsearch/index/fielddata/plain/AbstractAtomicParentChildFieldData.java +++ b/core/src/main/java/org/elasticsearch/index/fielddata/plain/AbstractAtomicParentChildFieldData.java @@ -19,8 +19,6 @@ package org.elasticsearch.index.fielddata.plain; -import com.google.common.collect.ImmutableSet; - import org.apache.lucene.index.DocValues; import org.apache.lucene.index.SortedDocValues; import org.apache.lucene.util.Accountable; @@ -34,6 +32,8 @@ import java.util.Collection; import java.util.Collections; import java.util.Set; +import static java.util.Collections.emptySet; + /** */ @@ -92,7 +92,7 @@ abstract class AbstractAtomicParentChildFieldData implements AtomicParentChildFi public long ramBytesUsed() { return 0; } - + @Override public Collection getChildResources() { return Collections.emptyList(); @@ -109,7 +109,7 @@ abstract class AbstractAtomicParentChildFieldData implements AtomicParentChildFi @Override public Set types() { - return ImmutableSet.of(); + return emptySet(); } }; } diff --git a/core/src/main/java/org/elasticsearch/index/fielddata/plain/DocValuesIndexFieldData.java b/core/src/main/java/org/elasticsearch/index/fielddata/plain/DocValuesIndexFieldData.java index 97fb3e5c549..d7329be5d25 100644 --- a/core/src/main/java/org/elasticsearch/index/fielddata/plain/DocValuesIndexFieldData.java +++ b/core/src/main/java/org/elasticsearch/index/fielddata/plain/DocValuesIndexFieldData.java @@ -19,7 +19,6 @@ package org.elasticsearch.index.fielddata.plain; -import com.google.common.collect.ImmutableSet; import org.apache.lucene.index.IndexReader; import org.elasticsearch.Version; import org.elasticsearch.common.logging.ESLogger; @@ -30,7 +29,6 @@ import org.elasticsearch.index.fielddata.FieldDataType; import org.elasticsearch.index.fielddata.IndexFieldData; import org.elasticsearch.index.fielddata.IndexFieldDataCache; import org.elasticsearch.index.fielddata.IndexNumericFieldData.NumericType; -import org.elasticsearch.index.mapper.FieldMapper; import org.elasticsearch.index.mapper.MappedFieldType; import org.elasticsearch.index.mapper.MappedFieldType.Names; import org.elasticsearch.index.mapper.MapperService; @@ -42,6 +40,9 @@ import org.elasticsearch.indices.breaker.CircuitBreakerService; import java.util.Map; import java.util.Set; +import static java.util.Collections.unmodifiableSet; +import static org.elasticsearch.common.util.set.Sets.newHashSet; + /** {@link IndexFieldData} impl based on Lucene's doc values. Caching is done on the Lucene side. */ public abstract class DocValuesIndexFieldData { @@ -79,9 +80,7 @@ public abstract class DocValuesIndexFieldData { } public static class Builder implements IndexFieldData.Builder { - - private static final Set BINARY_INDEX_FIELD_NAMES = ImmutableSet.of(UidFieldMapper.NAME, IdFieldMapper.NAME); - private static final Set NUMERIC_INDEX_FIELD_NAMES = ImmutableSet.of(TimestampFieldMapper.NAME); + private static final Set BINARY_INDEX_FIELD_NAMES = unmodifiableSet(newHashSet(UidFieldMapper.NAME, IdFieldMapper.NAME)); private NumericType numericType; diff --git a/core/src/main/java/org/elasticsearch/index/fieldvisitor/FieldsVisitor.java b/core/src/main/java/org/elasticsearch/index/fieldvisitor/FieldsVisitor.java index 31b0a080224..fa4b58760b3 100644 --- a/core/src/main/java/org/elasticsearch/index/fieldvisitor/FieldsVisitor.java +++ b/core/src/main/java/org/elasticsearch/index/fieldvisitor/FieldsVisitor.java @@ -19,9 +19,10 @@ package org.elasticsearch.index.fieldvisitor; import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; + import org.apache.lucene.index.FieldInfo; import org.apache.lucene.index.StoredFieldVisitor; +import org.apache.lucene.index.StoredFieldVisitor; import org.apache.lucene.util.BytesRef; import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.bytes.BytesReference; @@ -46,20 +47,19 @@ import java.util.List; import java.util.Map; import java.util.Set; -import org.apache.lucene.index.StoredFieldVisitor; +import static java.util.Collections.unmodifiableSet; +import static org.elasticsearch.common.util.set.Sets.newHashSet; /** * Base {@link StoredFieldVisitor} that retrieves all non-redundant metadata. */ public class FieldsVisitor extends StoredFieldVisitor { - - private static final Set BASE_REQUIRED_FIELDS = ImmutableSet.of( + private static final Set BASE_REQUIRED_FIELDS = unmodifiableSet(newHashSet( UidFieldMapper.NAME, TimestampFieldMapper.NAME, TTLFieldMapper.NAME, RoutingFieldMapper.NAME, - ParentFieldMapper.NAME - ); + ParentFieldMapper.NAME)); private final boolean loadSource; private final Set requiredFields; diff --git a/core/src/main/java/org/elasticsearch/rest/RestController.java b/core/src/main/java/org/elasticsearch/rest/RestController.java index cc6c09a20ad..888fb54ac03 100644 --- a/core/src/main/java/org/elasticsearch/rest/RestController.java +++ b/core/src/main/java/org/elasticsearch/rest/RestController.java @@ -19,7 +19,6 @@ package org.elasticsearch.rest; -import com.google.common.collect.ImmutableSet; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.component.AbstractLifecycleComponent; import org.elasticsearch.common.inject.Inject; @@ -31,17 +30,19 @@ import org.elasticsearch.rest.support.RestUtils; import java.io.IOException; import java.util.Arrays; import java.util.Comparator; +import java.util.Set; import java.util.concurrent.atomic.AtomicInteger; -import static org.elasticsearch.rest.RestStatus.*; +import static java.util.Collections.emptySet; +import static java.util.Collections.unmodifiableSet; +import static org.elasticsearch.common.util.set.Sets.newHashSetCopyWith; +import static org.elasticsearch.rest.RestStatus.BAD_REQUEST; +import static org.elasticsearch.rest.RestStatus.OK; /** * */ public class RestController extends AbstractLifecycleComponent { - - private ImmutableSet relevantHeaders = ImmutableSet.of(); - private final PathTrie getHandlers = new PathTrie<>(RestUtils.REST_DECODER); private final PathTrie postHandlers = new PathTrie<>(RestUtils.REST_DECODER); private final PathTrie putHandlers = new PathTrie<>(RestUtils.REST_DECODER); @@ -51,6 +52,8 @@ public class RestController extends AbstractLifecycleComponent { private final RestHandlerFilter handlerFilter = new RestHandlerFilter(); + private Set relevantHeaders = emptySet(); + // non volatile since the assumption is that pre processors are registered on startup private RestFilter[] filters = new RestFilter[0]; @@ -81,7 +84,7 @@ public class RestController extends AbstractLifecycleComponent { * By default no headers get copied but it is possible to extend this behaviour via plugins by calling this method. */ public synchronized void registerRelevantHeaders(String... headers) { - relevantHeaders = new ImmutableSet.Builder().addAll(relevantHeaders).add(headers).build(); + relevantHeaders = unmodifiableSet(newHashSetCopyWith(relevantHeaders, headers)); } /** @@ -89,7 +92,7 @@ public class RestController extends AbstractLifecycleComponent { * its corresponding {@link org.elasticsearch.transport.TransportRequest}(s). * By default no headers get copied but it is possible to extend this behaviour via plugins by calling {@link #registerRelevantHeaders(String...)}. */ - public ImmutableSet relevantHeaders() { + public Set relevantHeaders() { return relevantHeaders; } diff --git a/core/src/main/java/org/elasticsearch/search/highlight/HighlightUtils.java b/core/src/main/java/org/elasticsearch/search/highlight/HighlightUtils.java index b26be721d93..db64af82398 100644 --- a/core/src/main/java/org/elasticsearch/search/highlight/HighlightUtils.java +++ b/core/src/main/java/org/elasticsearch/search/highlight/HighlightUtils.java @@ -18,7 +18,6 @@ */ package org.elasticsearch.search.highlight; -import com.google.common.collect.ImmutableSet; import org.apache.lucene.search.highlight.DefaultEncoder; import org.apache.lucene.search.highlight.Encoder; import org.apache.lucene.search.highlight.SimpleHTMLEncoder; @@ -32,6 +31,8 @@ import java.io.IOException; import java.util.Collections; import java.util.List; +import static java.util.Collections.singleton; + public final class HighlightUtils { //U+2029 PARAGRAPH SEPARATOR (PS): each value holds a discrete passage for highlighting (postings highlighter) @@ -47,7 +48,7 @@ public final class HighlightUtils { boolean forceSource = searchContext.highlight().forceSource(field); List textsToHighlight; if (!forceSource && mapper.fieldType().stored()) { - CustomFieldsVisitor fieldVisitor = new CustomFieldsVisitor(ImmutableSet.of(mapper.fieldType().names().indexName()), false); + CustomFieldsVisitor fieldVisitor = new CustomFieldsVisitor(singleton(mapper.fieldType().names().indexName()), false); hitContext.reader().document(hitContext.docId(), fieldVisitor); textsToHighlight = fieldVisitor.fields().get(mapper.fieldType().names().indexName()); if (textsToHighlight == null) { diff --git a/core/src/test/java/org/elasticsearch/ExceptionSerializationTests.java b/core/src/test/java/org/elasticsearch/ExceptionSerializationTests.java index ccdd52b02fd..f62f50e206f 100644 --- a/core/src/test/java/org/elasticsearch/ExceptionSerializationTests.java +++ b/core/src/test/java/org/elasticsearch/ExceptionSerializationTests.java @@ -20,7 +20,6 @@ package org.elasticsearch; import com.fasterxml.jackson.core.JsonLocation; import com.fasterxml.jackson.core.JsonParseException; -import com.google.common.collect.ImmutableSet; import org.apache.lucene.util.Constants; import org.codehaus.groovy.runtime.typehandling.GroovyCastException; @@ -39,6 +38,7 @@ import org.elasticsearch.cluster.routing.RoutingValidationException; import org.elasticsearch.cluster.routing.ShardRouting; import org.elasticsearch.cluster.routing.ShardRoutingState; import org.elasticsearch.cluster.routing.TestShardRouting; +import org.elasticsearch.common.ParsingException; import org.elasticsearch.common.breaker.CircuitBreakingException; import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.io.stream.BytesStreamOutput; @@ -60,7 +60,6 @@ import org.elasticsearch.index.engine.CreateFailedEngineException; import org.elasticsearch.index.engine.IndexFailedEngineException; import org.elasticsearch.index.engine.RecoveryEngineException; import org.elasticsearch.index.mapper.MergeMappingException; -import org.elasticsearch.common.ParsingException; import org.elasticsearch.index.query.TestParsingException; import org.elasticsearch.index.shard.IllegalIndexShardStateException; import org.elasticsearch.index.shard.IndexShardState; @@ -100,6 +99,8 @@ import java.nio.file.attribute.BasicFileAttributes; import java.util.HashSet; import java.util.Set; +import static java.util.Collections.singleton; + public class ExceptionSerializationTests extends ESTestCase { public void testExceptionRegistration() @@ -534,7 +535,7 @@ public class ExceptionSerializationTests extends ESTestCase { } public void testClusterBlockException() throws IOException { - ClusterBlockException ex = serialize(new ClusterBlockException(ImmutableSet.of(DiscoverySettings.NO_MASTER_BLOCK_WRITES))); + ClusterBlockException ex = serialize(new ClusterBlockException(singleton(DiscoverySettings.NO_MASTER_BLOCK_WRITES))); assertEquals("blocked by: [SERVICE_UNAVAILABLE/2/no master];", ex.getMessage()); assertTrue(ex.blocks().contains(DiscoverySettings.NO_MASTER_BLOCK_WRITES)); assertEquals(1, ex.blocks().size()); diff --git a/core/src/test/java/org/elasticsearch/cluster/ClusterInfoServiceIT.java b/core/src/test/java/org/elasticsearch/cluster/ClusterInfoServiceIT.java index c5ec864c54c..606911fae04 100644 --- a/core/src/test/java/org/elasticsearch/cluster/ClusterInfoServiceIT.java +++ b/core/src/test/java/org/elasticsearch/cluster/ClusterInfoServiceIT.java @@ -19,8 +19,6 @@ package org.elasticsearch.cluster; -import com.google.common.collect.ImmutableSet; - import org.elasticsearch.ElasticsearchException; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionModule; @@ -207,7 +205,7 @@ public class ClusterInfoServiceIT extends ESIntegTestCase { MockTransportService mockTransportService = (MockTransportService) internalCluster().getInstance(TransportService.class, internalTestCluster.getMasterName()); final AtomicBoolean timeout = new AtomicBoolean(false); - final Set blockedActions = ImmutableSet.of(NodesStatsAction.NAME, NodesStatsAction.NAME + "[n]", IndicesStatsAction.NAME, IndicesStatsAction.NAME + "[n]"); + final Set blockedActions = newHashSet(NodesStatsAction.NAME, NodesStatsAction.NAME + "[n]", IndicesStatsAction.NAME, IndicesStatsAction.NAME + "[n]"); // drop all outgoing stats requests to force a timeout. for (DiscoveryNode node : internalTestCluster.clusterService().state().getNodes()) { mockTransportService.addDelegate(node, new MockTransportService.DelegateTransport(mockTransportService.original()) { diff --git a/core/src/test/java/org/elasticsearch/explain/ExplainActionIT.java b/core/src/test/java/org/elasticsearch/explain/ExplainActionIT.java index be998b18a2b..d2b1e6d4e38 100644 --- a/core/src/test/java/org/elasticsearch/explain/ExplainActionIT.java +++ b/core/src/test/java/org/elasticsearch/explain/ExplainActionIT.java @@ -19,8 +19,6 @@ package org.elasticsearch.explain; -import com.google.common.collect.ImmutableSet; - import org.apache.lucene.search.Explanation; import org.elasticsearch.action.admin.indices.alias.Alias; import org.elasticsearch.action.explain.ExplainResponse; @@ -42,6 +40,7 @@ import java.util.HashSet; import java.util.Map; import java.util.Set; +import static java.util.Collections.singleton; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; import static org.elasticsearch.index.query.QueryBuilders.queryStringQuery; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; @@ -60,7 +59,7 @@ public class ExplainActionIT extends ESIntegTestCase { ensureGreen("test"); client().prepareIndex("test", "test", "1").setSource("field", "value1").get(); - + ExplainResponse response = client().prepareExplain(indexOrAlias(), "test", "1") .setQuery(QueryBuilders.matchAllQuery()).get(); assertNotNull(response); @@ -145,7 +144,7 @@ public class ExplainActionIT extends ESIntegTestCase { assertThat(response.getGetResult().getId(), equalTo("1")); Set fields = new HashSet<>(response.getGetResult().getFields().keySet()); fields.remove(TimestampFieldMapper.NAME); // randomly added via templates - assertThat(fields, equalTo((Set) ImmutableSet.of("obj1.field1"))); + assertThat(fields, equalTo(singleton("obj1.field1"))); assertThat(response.getGetResult().getFields().get("obj1.field1").getValue().toString(), equalTo("value1")); assertThat(response.getGetResult().isSourceEmpty(), equalTo(true)); @@ -162,7 +161,7 @@ public class ExplainActionIT extends ESIntegTestCase { assertThat(response.getGetResult().getId(), equalTo("1")); fields = new HashSet<>(response.getGetResult().getFields().keySet()); fields.remove(TimestampFieldMapper.NAME); // randomly added via templates - assertThat(fields, equalTo((Set) ImmutableSet.of("obj1.field1"))); + assertThat(fields, equalTo(singleton("obj1.field1"))); assertThat(response.getGetResult().getFields().get("obj1.field1").getValue().toString(), equalTo("value1")); assertThat(response.getGetResult().isSourceEmpty(), equalTo(false)); diff --git a/core/src/test/java/org/elasticsearch/gateway/AsyncShardFetchTests.java b/core/src/test/java/org/elasticsearch/gateway/AsyncShardFetchTests.java index c9139d22f7e..88f47e7b83a 100644 --- a/core/src/test/java/org/elasticsearch/gateway/AsyncShardFetchTests.java +++ b/core/src/test/java/org/elasticsearch/gateway/AsyncShardFetchTests.java @@ -18,7 +18,6 @@ */ package org.elasticsearch.gateway; -import com.google.common.collect.ImmutableSet; import org.elasticsearch.Version; import org.elasticsearch.action.FailedNodeException; import org.elasticsearch.action.support.nodes.BaseNodeResponse; @@ -39,6 +38,7 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.CountDownLatch; import java.util.concurrent.atomic.AtomicInteger; +import static java.util.Collections.emptySet; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.sameInstance; @@ -56,6 +56,7 @@ public class AsyncShardFetchTests extends ESTestCase { private ThreadPool threadPool; private TestFetch test; + @Override @Before public void setUp() throws Exception { super.setUp(); @@ -74,7 +75,7 @@ public class AsyncShardFetchTests extends ESTestCase { test.addSimulation(node1.getId(), response1); // first fetch, no data, still on going - AsyncShardFetch.FetchResult fetchData = test.fetchData(nodes, MetaData.EMPTY_META_DATA, ImmutableSet.of()); + AsyncShardFetch.FetchResult fetchData = test.fetchData(nodes, MetaData.EMPTY_META_DATA, emptySet()); assertThat(fetchData.hasData(), equalTo(false)); assertThat(test.reroute.get(), equalTo(0)); @@ -84,7 +85,7 @@ public class AsyncShardFetchTests extends ESTestCase { assertThat(test.reroute.get(), equalTo(1)); test.close(); try { - test.fetchData(nodes, MetaData.EMPTY_META_DATA, ImmutableSet.of()); + test.fetchData(nodes, MetaData.EMPTY_META_DATA, emptySet()); fail("fetch data should fail when closed"); } catch (IllegalStateException e) { // all is well @@ -98,7 +99,7 @@ public class AsyncShardFetchTests extends ESTestCase { test.addSimulation(node1.getId(), response1); // first fetch, no data, still on going - AsyncShardFetch.FetchResult fetchData = test.fetchData(nodes, MetaData.EMPTY_META_DATA, ImmutableSet.of()); + AsyncShardFetch.FetchResult fetchData = test.fetchData(nodes, MetaData.EMPTY_META_DATA, emptySet()); assertThat(fetchData.hasData(), equalTo(false)); assertThat(test.reroute.get(), equalTo(0)); @@ -106,7 +107,7 @@ public class AsyncShardFetchTests extends ESTestCase { test.fireSimulationAndWait(node1.getId()); // verify we get back the data node assertThat(test.reroute.get(), equalTo(1)); - fetchData = test.fetchData(nodes, MetaData.EMPTY_META_DATA, ImmutableSet.of()); + fetchData = test.fetchData(nodes, MetaData.EMPTY_META_DATA, emptySet()); assertThat(fetchData.hasData(), equalTo(true)); assertThat(fetchData.getData().size(), equalTo(1)); assertThat(fetchData.getData().get(node1), sameInstance(response1)); @@ -119,7 +120,7 @@ public class AsyncShardFetchTests extends ESTestCase { test.addSimulation(node1.getId(), failure1); // first fetch, no data, still on going - AsyncShardFetch.FetchResult fetchData = test.fetchData(nodes, MetaData.EMPTY_META_DATA, ImmutableSet.of()); + AsyncShardFetch.FetchResult fetchData = test.fetchData(nodes, MetaData.EMPTY_META_DATA, emptySet()); assertThat(fetchData.hasData(), equalTo(false)); assertThat(test.reroute.get(), equalTo(0)); @@ -127,19 +128,19 @@ public class AsyncShardFetchTests extends ESTestCase { test.fireSimulationAndWait(node1.getId()); // failure, fetched data exists, but has no data assertThat(test.reroute.get(), equalTo(1)); - fetchData = test.fetchData(nodes, MetaData.EMPTY_META_DATA, ImmutableSet.of()); + fetchData = test.fetchData(nodes, MetaData.EMPTY_META_DATA, emptySet()); assertThat(fetchData.hasData(), equalTo(true)); assertThat(fetchData.getData().size(), equalTo(0)); // on failure, we reset the failure on a successive call to fetchData, and try again afterwards test.addSimulation(node1.getId(), response1); - fetchData = test.fetchData(nodes, MetaData.EMPTY_META_DATA, ImmutableSet.of()); + fetchData = test.fetchData(nodes, MetaData.EMPTY_META_DATA, emptySet()); assertThat(fetchData.hasData(), equalTo(false)); test.fireSimulationAndWait(node1.getId()); // 2 reroutes, cause we have a failure that we clear assertThat(test.reroute.get(), equalTo(3)); - fetchData = test.fetchData(nodes, MetaData.EMPTY_META_DATA, ImmutableSet.of()); + fetchData = test.fetchData(nodes, MetaData.EMPTY_META_DATA, emptySet()); assertThat(fetchData.hasData(), equalTo(true)); assertThat(fetchData.getData().size(), equalTo(1)); assertThat(fetchData.getData().get(node1), sameInstance(response1)); @@ -152,7 +153,7 @@ public class AsyncShardFetchTests extends ESTestCase { test.addSimulation(node2.getId(), response2); // no fetched data, 2 requests still on going - AsyncShardFetch.FetchResult fetchData = test.fetchData(nodes, MetaData.EMPTY_META_DATA, ImmutableSet.of()); + AsyncShardFetch.FetchResult fetchData = test.fetchData(nodes, MetaData.EMPTY_META_DATA, emptySet()); assertThat(fetchData.hasData(), equalTo(false)); assertThat(test.reroute.get(), equalTo(0)); @@ -160,14 +161,14 @@ public class AsyncShardFetchTests extends ESTestCase { test.fireSimulationAndWait(node1.getId()); // there is still another on going request, so no data assertThat(test.getNumberOfInFlightFetches(), equalTo(1)); - fetchData = test.fetchData(nodes, MetaData.EMPTY_META_DATA, ImmutableSet.of()); + fetchData = test.fetchData(nodes, MetaData.EMPTY_META_DATA, emptySet()); assertThat(fetchData.hasData(), equalTo(false)); // fire the second simulation, this should allow us to get the data test.fireSimulationAndWait(node2.getId()); // no more ongoing requests, we should fetch the data assertThat(test.reroute.get(), equalTo(2)); - fetchData = test.fetchData(nodes, MetaData.EMPTY_META_DATA, ImmutableSet.of()); + fetchData = test.fetchData(nodes, MetaData.EMPTY_META_DATA, emptySet()); assertThat(fetchData.hasData(), equalTo(true)); assertThat(fetchData.getData().size(), equalTo(2)); assertThat(fetchData.getData().get(node1), sameInstance(response1)); @@ -181,21 +182,21 @@ public class AsyncShardFetchTests extends ESTestCase { test.addSimulation(node2.getId(), failure2); // no fetched data, 2 requests still on going - AsyncShardFetch.FetchResult fetchData = test.fetchData(nodes, MetaData.EMPTY_META_DATA, ImmutableSet.of()); + AsyncShardFetch.FetchResult fetchData = test.fetchData(nodes, MetaData.EMPTY_META_DATA, emptySet()); assertThat(fetchData.hasData(), equalTo(false)); assertThat(test.reroute.get(), equalTo(0)); // fire the first response, it should trigger a reroute test.fireSimulationAndWait(node1.getId()); assertThat(test.reroute.get(), equalTo(1)); - fetchData = test.fetchData(nodes, MetaData.EMPTY_META_DATA, ImmutableSet.of()); + fetchData = test.fetchData(nodes, MetaData.EMPTY_META_DATA, emptySet()); assertThat(fetchData.hasData(), equalTo(false)); // fire the second simulation, this should allow us to get the data test.fireSimulationAndWait(node2.getId()); assertThat(test.reroute.get(), equalTo(2)); // since one of those failed, we should only have one entry - fetchData = test.fetchData(nodes, MetaData.EMPTY_META_DATA, ImmutableSet.of()); + fetchData = test.fetchData(nodes, MetaData.EMPTY_META_DATA, emptySet()); assertThat(fetchData.hasData(), equalTo(true)); assertThat(fetchData.getData().size(), equalTo(1)); assertThat(fetchData.getData().get(node1), sameInstance(response1)); @@ -207,7 +208,7 @@ public class AsyncShardFetchTests extends ESTestCase { test.addSimulation(node1.getId(), response1); // no fetched data, 2 requests still on going - AsyncShardFetch.FetchResult fetchData = test.fetchData(nodes, MetaData.EMPTY_META_DATA, ImmutableSet.of()); + AsyncShardFetch.FetchResult fetchData = test.fetchData(nodes, MetaData.EMPTY_META_DATA, emptySet()); assertThat(fetchData.hasData(), equalTo(false)); assertThat(test.reroute.get(), equalTo(0)); @@ -218,14 +219,14 @@ public class AsyncShardFetchTests extends ESTestCase { nodes = DiscoveryNodes.builder(nodes).put(node2).build(); test.addSimulation(node2.getId(), response2); // no fetch data, has a new node introduced - fetchData = test.fetchData(nodes, MetaData.EMPTY_META_DATA, ImmutableSet.of()); + fetchData = test.fetchData(nodes, MetaData.EMPTY_META_DATA, emptySet()); assertThat(fetchData.hasData(), equalTo(false)); // fire the second simulation, this should allow us to get the data test.fireSimulationAndWait(node2.getId()); // since one of those failed, we should only have one entry - fetchData = test.fetchData(nodes, MetaData.EMPTY_META_DATA, ImmutableSet.of()); + fetchData = test.fetchData(nodes, MetaData.EMPTY_META_DATA, emptySet()); assertThat(fetchData.hasData(), equalTo(true)); assertThat(fetchData.getData().size(), equalTo(2)); assertThat(fetchData.getData().get(node1), sameInstance(response1)); diff --git a/core/src/test/java/org/elasticsearch/get/GetActionIT.java b/core/src/test/java/org/elasticsearch/get/GetActionIT.java index 743304df941..55b104d14b8 100644 --- a/core/src/test/java/org/elasticsearch/get/GetActionIT.java +++ b/core/src/test/java/org/elasticsearch/get/GetActionIT.java @@ -19,8 +19,6 @@ package org.elasticsearch.get; -import com.google.common.collect.ImmutableSet; - import org.elasticsearch.ElasticsearchException; import org.elasticsearch.Version; import org.elasticsearch.action.ShardOperationFailedException; @@ -52,9 +50,17 @@ import java.util.HashSet; import java.util.Map; import java.util.Set; +import static java.util.Collections.singleton; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; -import static org.hamcrest.Matchers.*; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.hasKey; +import static org.hamcrest.Matchers.instanceOf; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.not; +import static org.hamcrest.Matchers.notNullValue; +import static org.hamcrest.Matchers.nullValue; +import static org.hamcrest.Matchers.startsWith; public class GetActionIT extends ESIntegTestCase { @@ -295,7 +301,7 @@ public class GetActionIT extends ESIntegTestCase { assertThat(response.getType(), equalTo("type1")); Set fields = new HashSet<>(response.getFields().keySet()); fields.remove(TimestampFieldMapper.NAME); // randomly enabled via templates - assertThat(fields, equalTo((Set) ImmutableSet.of("field"))); + assertThat(fields, equalTo(singleton("field"))); assertThat(response.getFields().get("field").getValues().size(), equalTo(2)); assertThat(response.getFields().get("field").getValues().get(0).toString(), equalTo("1")); assertThat(response.getFields().get("field").getValues().get(1).toString(), equalTo("2")); @@ -307,7 +313,7 @@ public class GetActionIT extends ESIntegTestCase { assertThat(response.getId(), equalTo("1")); fields = new HashSet<>(response.getFields().keySet()); fields.remove(TimestampFieldMapper.NAME); // randomly enabled via templates - assertThat(fields, equalTo((Set) ImmutableSet.of("field"))); + assertThat(fields, equalTo(singleton("field"))); assertThat(response.getFields().get("field").getValues().size(), equalTo(2)); assertThat(response.getFields().get("field").getValues().get(0).toString(), equalTo("1")); assertThat(response.getFields().get("field").getValues().get(1).toString(), equalTo("2")); @@ -319,7 +325,7 @@ public class GetActionIT extends ESIntegTestCase { assertThat(response.getId(), equalTo("1")); fields = new HashSet<>(response.getFields().keySet()); fields.remove(TimestampFieldMapper.NAME); // randomly enabled via templates - assertThat(fields, equalTo((Set) ImmutableSet.of("field"))); + assertThat(fields, equalTo(singleton("field"))); assertThat(response.getFields().get("field").getValues().size(), equalTo(2)); assertThat(response.getFields().get("field").getValues().get(0).toString(), equalTo("1")); assertThat(response.getFields().get("field").getValues().get(1).toString(), equalTo("2")); @@ -329,7 +335,7 @@ public class GetActionIT extends ESIntegTestCase { assertThat(response.getId(), equalTo("1")); fields = new HashSet<>(response.getFields().keySet()); fields.remove(TimestampFieldMapper.NAME); // randomly enabled via templates - assertThat(fields, equalTo((Set) ImmutableSet.of("field"))); + assertThat(fields, equalTo(singleton("field"))); assertThat(response.getFields().get("field").getValues().size(), equalTo(2)); assertThat(response.getFields().get("field").getValues().get(0).toString(), equalTo("1")); assertThat(response.getFields().get("field").getValues().get(1).toString(), equalTo("2")); diff --git a/core/src/test/java/org/elasticsearch/index/TransportIndexFailuresIT.java b/core/src/test/java/org/elasticsearch/index/TransportIndexFailuresIT.java index ba73d9e61a8..aed603ce394 100644 --- a/core/src/test/java/org/elasticsearch/index/TransportIndexFailuresIT.java +++ b/core/src/test/java/org/elasticsearch/index/TransportIndexFailuresIT.java @@ -19,7 +19,6 @@ package org.elasticsearch.index; -import com.google.common.collect.ImmutableSet; import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus; import org.elasticsearch.action.index.IndexAction; import org.elasticsearch.action.index.IndexResponse; @@ -40,6 +39,7 @@ import org.junit.Test; import java.util.Collection; import java.util.List; +import static java.util.Collections.singleton; import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING; import static org.elasticsearch.cluster.routing.ShardRoutingState.RELOCATING; import static org.elasticsearch.cluster.routing.ShardRoutingState.STARTED; @@ -118,12 +118,12 @@ public class TransportIndexFailuresIT extends ESIntegTestCase { TransportService mockTransportService = internalCluster().getInstance(TransportService.class, primaryNode); ((MockTransportService) mockTransportService).addFailToSendNoConnectRule( internalCluster().getInstance(Discovery.class, replicaNode).localNode(), - ImmutableSet.of(IndexAction.NAME + "[r]") + singleton(IndexAction.NAME + "[r]") ); mockTransportService = internalCluster().getInstance(TransportService.class, replicaNode); ((MockTransportService) mockTransportService).addFailToSendNoConnectRule( internalCluster().getInstance(Discovery.class, primaryNode).localNode(), - ImmutableSet.of(IndexAction.NAME + "[r]") + singleton(IndexAction.NAME + "[r]") ); logger.info("--> indexing into primary"); diff --git a/core/src/test/java/org/elasticsearch/script/NativeScriptTests.java b/core/src/test/java/org/elasticsearch/script/NativeScriptTests.java index cf7f7b1ec82..99982347700 100644 --- a/core/src/test/java/org/elasticsearch/script/NativeScriptTests.java +++ b/core/src/test/java/org/elasticsearch/script/NativeScriptTests.java @@ -19,7 +19,6 @@ package org.elasticsearch.script; -import com.google.common.collect.ImmutableSet; import org.elasticsearch.common.ContextAndHeaderHolder; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.inject.Injector; @@ -41,6 +40,7 @@ import java.util.HashMap; import java.util.Map; import java.util.Set; +import static java.util.Collections.singleton; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.notNullValue; @@ -85,7 +85,7 @@ public class NativeScriptTests extends ESTestCase { ResourceWatcherService resourceWatcherService = new ResourceWatcherService(settings, null); Map nativeScriptFactoryMap = new HashMap<>(); nativeScriptFactoryMap.put("my", new MyNativeScriptFactory()); - Set scriptEngineServices = ImmutableSet.of(new NativeScriptEngineService(settings, nativeScriptFactoryMap)); + Set scriptEngineServices = singleton(new NativeScriptEngineService(settings, nativeScriptFactoryMap)); ScriptContextRegistry scriptContextRegistry = new ScriptContextRegistry(new ArrayList()); ScriptService scriptService = new ScriptService(settings, environment, scriptEngineServices, resourceWatcherService, scriptContextRegistry); diff --git a/core/src/test/java/org/elasticsearch/script/ScriptModesTests.java b/core/src/test/java/org/elasticsearch/script/ScriptModesTests.java index cfa4eda82db..37030a2e235 100644 --- a/core/src/test/java/org/elasticsearch/script/ScriptModesTests.java +++ b/core/src/test/java/org/elasticsearch/script/ScriptModesTests.java @@ -20,7 +20,7 @@ package org.elasticsearch.script; import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; + import org.elasticsearch.common.Nullable; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.script.ScriptService.ScriptType; @@ -38,13 +38,16 @@ import java.util.HashSet; import java.util.Map; import java.util.Set; +import static java.util.Collections.singleton; +import static java.util.Collections.unmodifiableSet; +import static org.elasticsearch.common.util.set.Sets.newHashSet; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.notNullValue; // TODO: this needs to be a base test class, and all scripting engines extend it public class ScriptModesTests extends ESTestCase { - - private static final Set ALL_LANGS = ImmutableSet.of(GroovyScriptEngineService.NAME, MustacheScriptEngineService.NAME, "custom", "test"); + private static final Set ALL_LANGS = unmodifiableSet( + newHashSet(GroovyScriptEngineService.NAME, MustacheScriptEngineService.NAME, "custom", "test")); static final String[] ENABLE_VALUES = new String[]{"on", "true", "yes", "1"}; static final String[] DISABLE_VALUES = new String[]{"off", "false", "no", "0"}; @@ -71,7 +74,7 @@ public class ScriptModesTests extends ESTestCase { } scriptContextRegistry = new ScriptContextRegistry(contexts.values()); scriptContexts = scriptContextRegistry.scriptContexts().toArray(new ScriptContext[scriptContextRegistry.scriptContexts().size()]); - scriptEngines = buildScriptEnginesByLangMap(ImmutableSet.of( + scriptEngines = buildScriptEnginesByLangMap(newHashSet( new GroovyScriptEngineService(Settings.EMPTY), new MustacheScriptEngineService(Settings.EMPTY), //add the native engine just to make sure it gets filtered out @@ -195,7 +198,7 @@ public class ScriptModesTests extends ESTestCase { Settings.Builder builder = Settings.builder() .put(specificEngineOpSettings(GroovyScriptEngineService.NAME, ScriptType.INLINE, ScriptContext.Standard.MAPPING), randomFrom(DISABLE_VALUES)) .put(specificEngineOpSettings(GroovyScriptEngineService.NAME, ScriptType.INLINE, ScriptContext.Standard.UPDATE), randomFrom(DISABLE_VALUES)); - ImmutableSet groovyLangSet = ImmutableSet.of(GroovyScriptEngineService.NAME); + Set groovyLangSet = singleton(GroovyScriptEngineService.NAME); Set allButGroovyLangSet = new HashSet<>(ALL_LANGS); allButGroovyLangSet.remove(GroovyScriptEngineService.NAME); this.scriptModes = new ScriptModes(scriptEngines, scriptContextRegistry, builder.build()); @@ -211,7 +214,7 @@ public class ScriptModesTests extends ESTestCase { Settings.Builder builder = Settings.builder().put("script.inline", randomFrom(DISABLE_VALUES)) .put(specificEngineOpSettings(MustacheScriptEngineService.NAME, ScriptType.INLINE, ScriptContext.Standard.AGGS), randomFrom(ENABLE_VALUES)) .put(specificEngineOpSettings(MustacheScriptEngineService.NAME, ScriptType.INLINE, ScriptContext.Standard.SEARCH), randomFrom(ENABLE_VALUES)); - ImmutableSet mustacheLangSet = ImmutableSet.of(MustacheScriptEngineService.NAME); + Set mustacheLangSet = singleton(MustacheScriptEngineService.NAME); Set allButMustacheLangSet = new HashSet<>(ALL_LANGS); allButMustacheLangSet.remove(MustacheScriptEngineService.NAME); this.scriptModes = new ScriptModes(scriptEngines, scriptContextRegistry, builder.build()); diff --git a/core/src/test/java/org/elasticsearch/script/ScriptServiceTests.java b/core/src/test/java/org/elasticsearch/script/ScriptServiceTests.java index 6b33de8c135..4f19cd9426c 100644 --- a/core/src/test/java/org/elasticsearch/script/ScriptServiceTests.java +++ b/core/src/test/java/org/elasticsearch/script/ScriptServiceTests.java @@ -18,7 +18,6 @@ */ package org.elasticsearch.script; -import com.google.common.collect.ImmutableSet; import org.elasticsearch.common.ContextAndHeaderHolder; import org.elasticsearch.common.HasContextAndHeaders; import org.elasticsearch.common.Nullable; @@ -42,6 +41,7 @@ import java.util.Map; import java.util.Set; import static org.elasticsearch.common.settings.Settings.settingsBuilder; +import static org.elasticsearch.common.util.set.Sets.newHashSet; import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.notNullValue; @@ -75,7 +75,7 @@ public class ScriptServiceTests extends ESTestCase { .put("path.conf", genericConfigFolder) .build(); resourceWatcherService = new ResourceWatcherService(baseSettings, null); - scriptEngineServices = ImmutableSet.of(new TestEngineService(), new GroovyScriptEngineService(baseSettings), + scriptEngineServices = newHashSet(new TestEngineService(), new GroovyScriptEngineService(baseSettings), new MustacheScriptEngineService(baseSettings)); scriptEnginesByLangMap = ScriptModesTests.buildScriptEnginesByLangMap(scriptEngineServices); //randomly register custom script contexts diff --git a/core/src/test/java/org/elasticsearch/search/fields/SearchFieldsIT.java b/core/src/test/java/org/elasticsearch/search/fields/SearchFieldsIT.java index 107534765b6..21afbd5baa0 100644 --- a/core/src/test/java/org/elasticsearch/search/fields/SearchFieldsIT.java +++ b/core/src/test/java/org/elasticsearch/search/fields/SearchFieldsIT.java @@ -19,8 +19,6 @@ package org.elasticsearch.search.fields; -import com.google.common.collect.ImmutableSet; - import org.apache.lucene.util.BytesRef; import org.elasticsearch.action.index.IndexRequestBuilder; import org.elasticsearch.action.search.SearchPhaseExecutionException; @@ -55,7 +53,9 @@ import java.util.Map; import java.util.Set; import java.util.concurrent.ExecutionException; +import static java.util.Collections.singleton; import static org.elasticsearch.client.Requests.refreshRequest; +import static org.elasticsearch.common.util.set.Sets.newHashSet; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; @@ -63,7 +63,10 @@ import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertFail import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse; -import static org.hamcrest.Matchers.*; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.notNullValue; +import static org.hamcrest.Matchers.nullValue; /** * @@ -170,21 +173,21 @@ public class SearchFieldsIT extends ESIntegTestCase { assertThat(response.getHits().getAt(0).id(), equalTo("1")); Set fields = new HashSet<>(response.getHits().getAt(0).fields().keySet()); fields.remove(TimestampFieldMapper.NAME); // randomly enabled via templates - assertThat(fields, equalTo((Set) ImmutableSet.of("sNum1", "sNum1_field", "date1"))); + assertThat(fields, equalTo(newHashSet("sNum1", "sNum1_field", "date1"))); assertThat((Double) response.getHits().getAt(0).fields().get("sNum1").values().get(0), equalTo(1.0)); assertThat((Double) response.getHits().getAt(0).fields().get("sNum1_field").values().get(0), equalTo(1.0)); assertThat((Long) response.getHits().getAt(0).fields().get("date1").values().get(0), equalTo(0l)); assertThat(response.getHits().getAt(1).id(), equalTo("2")); fields = new HashSet<>(response.getHits().getAt(0).fields().keySet()); fields.remove(TimestampFieldMapper.NAME); // randomly enabled via templates - assertThat(fields, equalTo((Set) ImmutableSet.of("sNum1", "sNum1_field", "date1"))); + assertThat(fields, equalTo(newHashSet("sNum1", "sNum1_field", "date1"))); assertThat((Double) response.getHits().getAt(1).fields().get("sNum1").values().get(0), equalTo(2.0)); assertThat((Double) response.getHits().getAt(1).fields().get("sNum1_field").values().get(0), equalTo(2.0)); assertThat((Long) response.getHits().getAt(1).fields().get("date1").values().get(0), equalTo(25000l)); assertThat(response.getHits().getAt(2).id(), equalTo("3")); fields = new HashSet<>(response.getHits().getAt(0).fields().keySet()); fields.remove(TimestampFieldMapper.NAME); // randomly enabled via templates - assertThat(fields, equalTo((Set) ImmutableSet.of("sNum1", "sNum1_field", "date1"))); + assertThat(fields, equalTo(newHashSet("sNum1", "sNum1_field", "date1"))); assertThat((Double) response.getHits().getAt(2).fields().get("sNum1").values().get(0), equalTo(3.0)); assertThat((Double) response.getHits().getAt(2).fields().get("sNum1_field").values().get(0), equalTo(3.0)); assertThat((Long) response.getHits().getAt(2).fields().get("date1").values().get(0), equalTo(120000l)); @@ -201,17 +204,17 @@ public class SearchFieldsIT extends ESIntegTestCase { assertThat(response.getHits().getAt(0).id(), equalTo("1")); fields = new HashSet<>(response.getHits().getAt(0).fields().keySet()); fields.remove(TimestampFieldMapper.NAME); // randomly enabled via templates - assertThat(fields, equalTo((Set) ImmutableSet.of("sNum1"))); + assertThat(fields, equalTo(singleton("sNum1"))); assertThat((Double) response.getHits().getAt(0).fields().get("sNum1").values().get(0), equalTo(2.0)); assertThat(response.getHits().getAt(1).id(), equalTo("2")); fields = new HashSet<>(response.getHits().getAt(0).fields().keySet()); fields.remove(TimestampFieldMapper.NAME); // randomly enabled via templates - assertThat(fields, equalTo((Set) ImmutableSet.of("sNum1"))); + assertThat(fields, equalTo(singleton("sNum1"))); assertThat((Double) response.getHits().getAt(1).fields().get("sNum1").values().get(0), equalTo(4.0)); assertThat(response.getHits().getAt(2).id(), equalTo("3")); fields = new HashSet<>(response.getHits().getAt(0).fields().keySet()); fields.remove(TimestampFieldMapper.NAME); // randomly enabled via templates - assertThat(fields, equalTo((Set) ImmutableSet.of("sNum1"))); + assertThat(fields, equalTo(singleton("sNum1"))); assertThat((Double) response.getHits().getAt(2).fields().get("sNum1").values().get(0), equalTo(6.0)); } @@ -239,7 +242,7 @@ public class SearchFieldsIT extends ESIntegTestCase { assertThat(response.getHits().getAt(i).id(), equalTo(Integer.toString(i))); Set fields = new HashSet<>(response.getHits().getAt(i).fields().keySet()); fields.remove(TimestampFieldMapper.NAME); // randomly enabled via templates - assertThat(fields, equalTo((Set) ImmutableSet.of("uid"))); + assertThat(fields, equalTo(singleton("uid"))); assertThat((String)response.getHits().getAt(i).fields().get("uid").value(), equalTo("type1#" + Integer.toString(i))); } @@ -254,7 +257,7 @@ public class SearchFieldsIT extends ESIntegTestCase { assertThat(response.getHits().getAt(i).id(), equalTo(Integer.toString(i))); Set fields = new HashSet<>(response.getHits().getAt(i).fields().keySet()); fields.remove(TimestampFieldMapper.NAME); // randomly enabled via templates - assertThat(fields, equalTo((Set) ImmutableSet.of("id"))); + assertThat(fields, equalTo(singleton("id"))); assertThat((String)response.getHits().getAt(i).fields().get("id").value(), equalTo(Integer.toString(i))); } @@ -269,7 +272,7 @@ public class SearchFieldsIT extends ESIntegTestCase { assertThat(response.getHits().getAt(i).id(), equalTo(Integer.toString(i))); Set fields = new HashSet<>(response.getHits().getAt(i).fields().keySet()); fields.remove(TimestampFieldMapper.NAME); // randomly enabled via templates - assertThat(fields, equalTo((Set) ImmutableSet.of("type"))); + assertThat(fields, equalTo(singleton("type"))); assertThat((String)response.getHits().getAt(i).fields().get("type").value(), equalTo("type1")); } @@ -285,7 +288,7 @@ public class SearchFieldsIT extends ESIntegTestCase { assertThat(response.getHits().getAt(i).id(), equalTo(Integer.toString(i))); Set fields = new HashSet<>(response.getHits().getAt(i).fields().keySet()); fields.remove(TimestampFieldMapper.NAME); // randomly enabled via templates - assertThat(fields, equalTo((Set) ImmutableSet.of("uid", "type", "id"))); + assertThat(fields, equalTo(newHashSet("uid", "type", "id"))); assertThat((String)response.getHits().getAt(i).fields().get("uid").value(), equalTo("type1#" + Integer.toString(i))); assertThat((String)response.getHits().getAt(i).fields().get("type").value(), equalTo("type1")); assertThat((String)response.getHits().getAt(i).fields().get("id").value(), equalTo(Integer.toString(i))); @@ -406,7 +409,7 @@ public class SearchFieldsIT extends ESIntegTestCase { assertThat(searchResponse.getHits().hits().length, equalTo(1)); Set fields = new HashSet<>(searchResponse.getHits().getAt(0).fields().keySet()); fields.remove(TimestampFieldMapper.NAME); // randomly enabled via templates - assertThat(fields, equalTo((Set) ImmutableSet.of("byte_field", "short_field", "integer_field", "long_field", + assertThat(fields, equalTo(newHashSet("byte_field", "short_field", "integer_field", "long_field", "float_field", "double_field", "date_field", "boolean_field", "binary_field"))); @@ -585,7 +588,7 @@ public class SearchFieldsIT extends ESIntegTestCase { assertThat(searchResponse.getHits().hits().length, equalTo(1)); Set fields = new HashSet<>(searchResponse.getHits().getAt(0).fields().keySet()); fields.remove(TimestampFieldMapper.NAME); // randomly enabled via templates - assertThat(fields, equalTo((Set) ImmutableSet.of("byte_field", "short_field", "integer_field", "long_field", + assertThat(fields, equalTo(newHashSet("byte_field", "short_field", "integer_field", "long_field", "float_field", "double_field", "date_field", "boolean_field", "string_field"))); assertThat(searchResponse.getHits().getAt(0).fields().get("byte_field").value().toString(), equalTo("1")); diff --git a/dev-tools/src/main/resources/forbidden/all-signatures.txt b/dev-tools/src/main/resources/forbidden/all-signatures.txt index 8fb564df8e7..83dbfc01f8a 100644 --- a/dev-tools/src/main/resources/forbidden/all-signatures.txt +++ b/dev-tools/src/main/resources/forbidden/all-signatures.txt @@ -133,6 +133,13 @@ com.google.common.collect.ImmutableSet#copyOf(java.lang.Iterable) com.google.common.collect.ImmutableSet#copyOf(java.util.Iterator) com.google.common.collect.ImmutableSet#copyOf(java.util.Collection) com.google.common.collect.ImmutableSet#copyOf(java.lang.Object[]) +com.google.common.collect.ImmutableSet#of() +com.google.common.collect.ImmutableSet#of(java.lang.Object) +com.google.common.collect.ImmutableSet#of(java.lang.Object, java.lang.Object) +com.google.common.collect.ImmutableSet#of(java.lang.Object, java.lang.Object, java.lang.Object) +com.google.common.collect.ImmutableSet#of(java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object) +com.google.common.collect.ImmutableSet#of(java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object) +com.google.common.collect.ImmutableSet#of(java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object[]) @defaultMessage Do not violate java's access system java.lang.reflect.AccessibleObject#setAccessible(boolean)