Merge pull request #13540 from jasontedor/preconditions-be-gone
Remove and forbid use of com.google.common.base.Preconditions
This commit is contained in:
commit
6e3a4e21a1
|
@ -21,7 +21,6 @@ package org.elasticsearch.cluster.metadata;
|
|||
|
||||
import com.carrotsearch.hppc.cursors.ObjectCursor;
|
||||
import com.carrotsearch.hppc.cursors.ObjectObjectCursor;
|
||||
import com.google.common.base.Preconditions;
|
||||
import org.elasticsearch.ElasticsearchException;
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.cluster.Diff;
|
||||
|
@ -205,8 +204,12 @@ public class IndexMetaData implements Diffable<IndexMetaData>, FromXContentBuild
|
|||
private final boolean useTypeForRouting;
|
||||
|
||||
private IndexMetaData(String index, long version, State state, Settings settings, ImmutableOpenMap<String, MappingMetaData> mappings, ImmutableOpenMap<String, AliasMetaData> aliases, ImmutableOpenMap<String, Custom> customs) {
|
||||
Preconditions.checkArgument(settings.getAsInt(SETTING_NUMBER_OF_SHARDS, null) != null, "must specify numberOfShards for index [" + index + "]");
|
||||
Preconditions.checkArgument(settings.getAsInt(SETTING_NUMBER_OF_REPLICAS, null) != null, "must specify numberOfReplicas for index [" + index + "]");
|
||||
if (settings.getAsInt(SETTING_NUMBER_OF_SHARDS, null) == null) {
|
||||
throw new IllegalArgumentException("must specify numberOfShards for index [" + index + "]");
|
||||
}
|
||||
if (settings.getAsInt(SETTING_NUMBER_OF_REPLICAS, null) == null) {
|
||||
throw new IllegalArgumentException("must specify numberOfReplicas for index [" + index + "]");
|
||||
}
|
||||
this.index = index;
|
||||
this.version = version;
|
||||
this.state = state;
|
||||
|
|
|
@ -19,11 +19,9 @@
|
|||
|
||||
package org.elasticsearch.common.cli;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import org.apache.commons.cli.CommandLine;
|
||||
import org.apache.commons.cli.CommandLineParser;
|
||||
import org.apache.commons.cli.DefaultParser;
|
||||
import org.elasticsearch.common.collect.Tuple;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.node.internal.InternalSettingsPreparer;
|
||||
|
@ -101,7 +99,9 @@ public abstract class CliTool {
|
|||
}
|
||||
|
||||
protected CliTool(CliToolConfig config, Terminal terminal) {
|
||||
Preconditions.checkArgument(config.cmds().size() != 0, "At least one command must be configured");
|
||||
if (config.cmds().size() == 0) {
|
||||
throw new IllegalArgumentException("At least one command must be configured");
|
||||
}
|
||||
this.config = config;
|
||||
this.terminal = terminal;
|
||||
env = InternalSettingsPreparer.prepareEnvironment(EMPTY_SETTINGS, terminal);
|
||||
|
|
|
@ -19,25 +19,11 @@
|
|||
|
||||
package org.elasticsearch.common.collect;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.base.Suppliers;
|
||||
import com.google.common.collect.UnmodifiableIterator;
|
||||
import org.apache.lucene.util.mutable.MutableValueInt;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.AbstractMap;
|
||||
import java.util.AbstractSet;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Deque;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Set;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.*;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
|
@ -487,7 +473,9 @@ public final class CopyOnWriteHashMap<K, V> extends AbstractMap<K, V> {
|
|||
|
||||
@Override
|
||||
public V get(Object key) {
|
||||
Preconditions.checkArgument(key != null, "Null keys are not supported");
|
||||
if (key == null) {
|
||||
throw new IllegalArgumentException("null keys are not supported");
|
||||
}
|
||||
final int hash = key.hashCode();
|
||||
return root.get(key, hash);
|
||||
}
|
||||
|
@ -503,8 +491,12 @@ public final class CopyOnWriteHashMap<K, V> extends AbstractMap<K, V> {
|
|||
* of the hash table. The current hash table is not modified.
|
||||
*/
|
||||
public CopyOnWriteHashMap<K, V> copyAndPut(K key, V value) {
|
||||
Preconditions.checkArgument(key != null, "null keys are not supported");
|
||||
Preconditions.checkArgument(value != null, "null values are not supported");
|
||||
if (key == null) {
|
||||
throw new IllegalArgumentException("null keys are not supported");
|
||||
}
|
||||
if (value == null) {
|
||||
throw new IllegalArgumentException("null values are not supported");
|
||||
}
|
||||
final int hash = key.hashCode();
|
||||
final MutableValueInt newValue = new MutableValueInt();
|
||||
final InnerNode<K, V> newRoot = root.put(key, hash, TOTAL_HASH_BITS, value, newValue);
|
||||
|
@ -535,7 +527,9 @@ public final class CopyOnWriteHashMap<K, V> extends AbstractMap<K, V> {
|
|||
* Remove the given key from this map. The current hash table is not modified.
|
||||
*/
|
||||
public CopyOnWriteHashMap<K, V> copyAndRemove(Object key) {
|
||||
Preconditions.checkArgument(key != null, "Null keys are not supported");
|
||||
if (key == null) {
|
||||
throw new IllegalArgumentException("null keys are not supported");
|
||||
}
|
||||
final int hash = key.hashCode();
|
||||
final InnerNode<K, V> newRoot = root.remove(key, hash);
|
||||
if (root == newRoot) {
|
||||
|
|
|
@ -27,8 +27,6 @@ import org.elasticsearch.common.inject.spi.TypeListener;
|
|||
import java.lang.annotation.Annotation;
|
||||
import java.util.Objects;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
|
||||
/**
|
||||
* A support class for {@link Module}s which reduces repetition and results in
|
||||
* a more readable configuration. Simply extend this class, implement {@link
|
||||
|
@ -54,8 +52,9 @@ public abstract class AbstractModule implements Module {
|
|||
|
||||
@Override
|
||||
public final synchronized void configure(Binder builder) {
|
||||
checkState(this.binder == null, "Re-entry is not allowed.");
|
||||
|
||||
if (this.binder != null) {
|
||||
throw new IllegalStateException("Re-entry is not allowed.");
|
||||
}
|
||||
this.binder = Objects.requireNonNull(builder, "builder");
|
||||
try {
|
||||
configure();
|
||||
|
|
|
@ -21,8 +21,7 @@ import org.elasticsearch.common.inject.internal.Errors;
|
|||
import org.elasticsearch.common.inject.spi.Message;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Thrown when a programming error such as a misplaced annotation, illegal binding, or unsupported
|
||||
|
@ -48,8 +47,10 @@ public final class ConfigurationException extends RuntimeException {
|
|||
* Returns a copy of this configuration exception with the specified partial value.
|
||||
*/
|
||||
public ConfigurationException withPartialValue(Object partialValue) {
|
||||
checkState(this.partialValue == null,
|
||||
"Can't clobber existing partial value %s with %s", this.partialValue, partialValue);
|
||||
if (this.partialValue != null) {
|
||||
String message = String.format(Locale.ROOT, "Can't clobber existing partial value %s with %s", this.partialValue, partialValue);
|
||||
throw new IllegalStateException(message);
|
||||
}
|
||||
ConfigurationException result = new ConfigurationException(messages);
|
||||
result.partialValue = partialValue;
|
||||
return result;
|
||||
|
|
|
@ -25,8 +25,6 @@ import org.elasticsearch.common.inject.spi.InjectionPoint;
|
|||
|
||||
import java.util.Set;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
|
||||
class ConstructorBindingImpl<T> extends BindingImpl<T> implements ConstructorBinding<T> {
|
||||
|
||||
private final Factory<T> factory;
|
||||
|
@ -52,19 +50,25 @@ class ConstructorBindingImpl<T> extends BindingImpl<T> implements ConstructorBin
|
|||
|
||||
@Override
|
||||
public <V> V acceptTargetVisitor(BindingTargetVisitor<? super T, V> visitor) {
|
||||
checkState(factory.constructorInjector != null, "not initialized");
|
||||
if (factory.constructorInjector == null) {
|
||||
throw new IllegalStateException("not initialized");
|
||||
}
|
||||
return visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public InjectionPoint getConstructor() {
|
||||
checkState(factory.constructorInjector != null, "Binding is not ready");
|
||||
if (factory.constructorInjector == null) {
|
||||
throw new IllegalStateException("Binding is not ready");
|
||||
}
|
||||
return factory.constructorInjector.getConstructionProxy().getInjectionPoint();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<InjectionPoint> getInjectableMembers() {
|
||||
checkState(factory.constructorInjector != null, "Binding is not ready");
|
||||
if (factory.constructorInjector == null) {
|
||||
throw new IllegalStateException("Binding is not ready");
|
||||
}
|
||||
return factory.constructorInjector.getInjectableMembers();
|
||||
}
|
||||
|
||||
|
@ -97,7 +101,9 @@ class ConstructorBindingImpl<T> extends BindingImpl<T> implements ConstructorBin
|
|||
@SuppressWarnings("unchecked")
|
||||
public T get(Errors errors, InternalContext context, Dependency<?> dependency)
|
||||
throws ErrorsException {
|
||||
checkState(constructorInjector != null, "Constructor not ready");
|
||||
if (constructorInjector == null) {
|
||||
throw new IllegalStateException("Constructor not ready");
|
||||
}
|
||||
|
||||
// This may not actually be safe because it could return a super type of T (if that's all the
|
||||
// client needs), but it should be OK in practice thanks to the wonders of erasure.
|
||||
|
|
|
@ -22,8 +22,6 @@ import org.elasticsearch.common.inject.spi.Message;
|
|||
|
||||
import java.util.Collection;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
|
||||
/**
|
||||
* Thrown when errors occur while creating a {@link Injector}. Includes a list of encountered
|
||||
* errors. Clients should catch this exception, log it, and stop execution.
|
||||
|
@ -39,7 +37,9 @@ public class CreationException extends RuntimeException {
|
|||
*/
|
||||
public CreationException(Collection<Message> messages) {
|
||||
this.messages = ImmutableSet.copyOf(messages);
|
||||
checkArgument(!this.messages.isEmpty());
|
||||
if (this.messages.isEmpty()) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
initCause(Errors.getOnlyCause(this.messages));
|
||||
}
|
||||
|
||||
|
|
|
@ -25,8 +25,6 @@ import java.util.ArrayList;
|
|||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
|
||||
/**
|
||||
* @author jessewilson@google.com (Jesse Wilson)
|
||||
*/
|
||||
|
@ -61,7 +59,9 @@ final class EncounterImpl<T> implements TypeEncounter<T> {
|
|||
|
||||
@Override
|
||||
public void register(MembersInjector<? super T> membersInjector) {
|
||||
checkState(valid, "Encounters may not be used after hear() returns.");
|
||||
if (!valid) {
|
||||
throw new IllegalStateException("Encounters may not be used after hear() returns.");
|
||||
}
|
||||
|
||||
if (membersInjectors == null) {
|
||||
membersInjectors = new ArrayList<>();
|
||||
|
@ -72,7 +72,9 @@ final class EncounterImpl<T> implements TypeEncounter<T> {
|
|||
|
||||
@Override
|
||||
public void register(InjectionListener<? super T> injectionListener) {
|
||||
checkState(valid, "Encounters may not be used after hear() returns.");
|
||||
if (!valid) {
|
||||
throw new IllegalStateException("Encounters may not be used after hear() returns.");
|
||||
}
|
||||
|
||||
if (injectionListeners == null) {
|
||||
injectionListeners = new ArrayList<>();
|
||||
|
@ -83,25 +85,33 @@ final class EncounterImpl<T> implements TypeEncounter<T> {
|
|||
|
||||
@Override
|
||||
public void addError(String message, Object... arguments) {
|
||||
checkState(valid, "Encounters may not be used after hear() returns.");
|
||||
if (!valid) {
|
||||
throw new IllegalStateException("Encounters may not be used after hear() returns.");
|
||||
}
|
||||
errors.addMessage(message, arguments);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addError(Throwable t) {
|
||||
checkState(valid, "Encounters may not be used after hear() returns.");
|
||||
if (!valid) {
|
||||
throw new IllegalStateException("Encounters may not be used after hear() returns.");
|
||||
}
|
||||
errors.errorInUserCode(t, "An exception was caught and reported. Message: %s", t.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addError(Message message) {
|
||||
checkState(valid, "Encounters may not be used after hear() returns.");
|
||||
if (!valid) {
|
||||
throw new IllegalStateException("Encounters may not be used after hear() returns.");
|
||||
}
|
||||
errors.addMessage(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Provider<T> getProvider(Key<T> key) {
|
||||
checkState(valid, "Encounters may not be used after hear() returns.");
|
||||
if (!valid) {
|
||||
throw new IllegalStateException("Encounters may not be used after hear() returns.");
|
||||
}
|
||||
return lookups.getProvider(key);
|
||||
}
|
||||
|
||||
|
@ -112,7 +122,9 @@ final class EncounterImpl<T> implements TypeEncounter<T> {
|
|||
|
||||
@Override
|
||||
public <T> MembersInjector<T> getMembersInjector(TypeLiteral<T> typeLiteral) {
|
||||
checkState(valid, "Encounters may not be used after hear() returns.");
|
||||
if (!valid) {
|
||||
throw new IllegalStateException("Encounters may not be used after hear() returns.");
|
||||
}
|
||||
return lookups.getMembersInjector(typeLiteral);
|
||||
}
|
||||
|
||||
|
|
|
@ -17,28 +17,14 @@
|
|||
package org.elasticsearch.common.inject;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import org.elasticsearch.common.inject.internal.Errors;
|
||||
import org.elasticsearch.common.inject.internal.ErrorsException;
|
||||
import org.elasticsearch.common.inject.internal.InternalContext;
|
||||
import org.elasticsearch.common.inject.internal.InternalFactory;
|
||||
import org.elasticsearch.common.inject.internal.PrivateElementsImpl;
|
||||
import org.elasticsearch.common.inject.internal.ProviderInstanceBindingImpl;
|
||||
import org.elasticsearch.common.inject.internal.Scoping;
|
||||
import org.elasticsearch.common.inject.internal.SourceProvider;
|
||||
import org.elasticsearch.common.inject.internal.Stopwatch;
|
||||
import org.elasticsearch.common.inject.spi.Dependency;
|
||||
import org.elasticsearch.common.inject.spi.Element;
|
||||
import org.elasticsearch.common.inject.spi.Elements;
|
||||
import org.elasticsearch.common.inject.spi.InjectionPoint;
|
||||
import org.elasticsearch.common.inject.spi.PrivateElements;
|
||||
import org.elasticsearch.common.inject.spi.TypeListenerBinding;
|
||||
import org.elasticsearch.common.inject.internal.*;
|
||||
import org.elasticsearch.common.inject.spi.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
import static org.elasticsearch.common.inject.Scopes.SINGLETON;
|
||||
|
||||
/**
|
||||
|
@ -125,9 +111,15 @@ class InjectorShell {
|
|||
*/
|
||||
List<InjectorShell> build(Initializer initializer, BindingProcessor bindingProcessor,
|
||||
Stopwatch stopwatch, Errors errors) {
|
||||
checkState(stage != null, "Stage not initialized");
|
||||
checkState(privateElements == null || parent != null, "PrivateElements with no parent");
|
||||
checkState(state != null, "no state. Did you remember to lock() ?");
|
||||
if (stage == null) {
|
||||
throw new IllegalStateException("Stage not initialized");
|
||||
}
|
||||
if (privateElements != null && parent == null) {
|
||||
throw new IllegalStateException("PrivateElements with no parent");
|
||||
}
|
||||
if (state == null) {
|
||||
throw new IllegalStateException("no state. Did you remember to lock() ?");
|
||||
}
|
||||
|
||||
InjectorImpl injector = new InjectorImpl(parent, state, initializer);
|
||||
if (privateElements != null) {
|
||||
|
|
|
@ -24,8 +24,6 @@ import java.lang.annotation.Annotation;
|
|||
import java.lang.reflect.Type;
|
||||
import java.util.Objects;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
|
||||
/**
|
||||
* Binding key consisting of an injection type and an optional annotation.
|
||||
* Matches the type and annotation at a point of injection.
|
||||
|
@ -367,16 +365,20 @@ public class Key<T> {
|
|||
|
||||
private static void ensureRetainedAtRuntime(
|
||||
Class<? extends Annotation> annotationType) {
|
||||
checkArgument(Annotations.isRetainedAtRuntime(annotationType),
|
||||
"%s is not retained at runtime. Please annotate it with @Retention(RUNTIME).",
|
||||
annotationType.getName());
|
||||
if (!Annotations.isRetainedAtRuntime(annotationType)) {
|
||||
throw new IllegalArgumentException(
|
||||
annotationType.getName() + " is not retained at runtime. Please annotate it with @Retention(RUNTIME)."
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private static void ensureIsBindingAnnotation(
|
||||
Class<? extends Annotation> annotationType) {
|
||||
checkArgument(isBindingAnnotation(annotationType),
|
||||
"%s is not a binding annotation. Please annotate it with @BindingAnnotation.",
|
||||
annotationType.getName());
|
||||
if (!isBindingAnnotation(annotationType)) {
|
||||
throw new IllegalArgumentException(
|
||||
annotationType.getName() + " is not a binding annotation. Please annotate it with @BindingAnnotation."
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
static enum NullAnnotationStrategy implements AnnotationStrategy {
|
||||
|
|
|
@ -27,8 +27,6 @@ import org.elasticsearch.common.inject.spi.TypeListener;
|
|||
|
||||
import java.lang.annotation.Annotation;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
|
||||
/**
|
||||
* A module whose configuration information is hidden from its environment by default. Only bindings
|
||||
* that are explicitly exposed will be available to other modules and to the users of the injector.
|
||||
|
@ -93,7 +91,9 @@ public abstract class PrivateModule implements Module {
|
|||
|
||||
@Override
|
||||
public final synchronized void configure(Binder binder) {
|
||||
checkState(this.binder == null, "Re-entry is not allowed.");
|
||||
if (this.binder != null) {
|
||||
throw new IllegalStateException("Re-entry is not allowed.");
|
||||
}
|
||||
|
||||
// Guice treats PrivateModules specially and passes in a PrivateBinder automatically.
|
||||
this.binder = (PrivateBinder) binder.skipSources(PrivateModule.class);
|
||||
|
|
|
@ -23,8 +23,6 @@ import org.elasticsearch.common.inject.spi.Message;
|
|||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
|
||||
/**
|
||||
* Indicates that there was a runtime failure while providing an instance.
|
||||
*
|
||||
|
@ -41,7 +39,9 @@ public final class ProvisionException extends RuntimeException {
|
|||
*/
|
||||
public ProvisionException(Iterable<Message> messages) {
|
||||
this.messages = ImmutableSet.copyOf(messages);
|
||||
checkArgument(!this.messages.isEmpty());
|
||||
if (this.messages.isEmpty()) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
initCause(Errors.getOnlyCause(this.messages));
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,6 @@ import java.util.Arrays;
|
|||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static org.elasticsearch.common.inject.internal.MoreTypes.canonicalize;
|
||||
|
||||
/**
|
||||
|
@ -257,8 +256,9 @@ public class TypeLiteral<T> {
|
|||
* @since 2.0
|
||||
*/
|
||||
public TypeLiteral<?> getSupertype(Class<?> supertype) {
|
||||
checkArgument(supertype.isAssignableFrom(rawType),
|
||||
"%s is not a supertype of %s", supertype, this.type);
|
||||
if (!supertype.isAssignableFrom(rawType)) {
|
||||
throw new IllegalArgumentException(supertype + " is not a supertype of " + type);
|
||||
}
|
||||
return resolve(MoreTypes.getGenericSupertype(type, rawType, supertype));
|
||||
}
|
||||
|
||||
|
@ -269,8 +269,9 @@ public class TypeLiteral<T> {
|
|||
* @since 2.0
|
||||
*/
|
||||
public TypeLiteral<?> getFieldType(Field field) {
|
||||
checkArgument(field.getDeclaringClass().isAssignableFrom(rawType),
|
||||
"%s is not defined by a supertype of %s", field, type);
|
||||
if (!field.getDeclaringClass().isAssignableFrom(rawType)) {
|
||||
throw new IllegalArgumentException(field + " is not defined by a supertype of " + type);
|
||||
}
|
||||
return resolve(field.getGenericType());
|
||||
}
|
||||
|
||||
|
@ -285,14 +286,17 @@ public class TypeLiteral<T> {
|
|||
|
||||
if (methodOrConstructor instanceof Method) {
|
||||
Method method = (Method) methodOrConstructor;
|
||||
checkArgument(method.getDeclaringClass().isAssignableFrom(rawType),
|
||||
"%s is not defined by a supertype of %s", method, type);
|
||||
if (!method.getDeclaringClass().isAssignableFrom(rawType)) {
|
||||
throw new IllegalArgumentException(method + " is not defined by a supertype of " + type);
|
||||
}
|
||||
genericParameterTypes = method.getGenericParameterTypes();
|
||||
|
||||
} else if (methodOrConstructor instanceof Constructor) {
|
||||
Constructor constructor = (Constructor) methodOrConstructor;
|
||||
checkArgument(constructor.getDeclaringClass().isAssignableFrom(rawType),
|
||||
"%s does not construct a supertype of %s", constructor, type);
|
||||
if (!constructor.getDeclaringClass().isAssignableFrom(rawType)) {
|
||||
throw new IllegalArgumentException(constructor + " does not construct a supertype of " + type);
|
||||
}
|
||||
|
||||
genericParameterTypes = constructor.getGenericParameterTypes();
|
||||
|
||||
} else {
|
||||
|
@ -313,14 +317,17 @@ public class TypeLiteral<T> {
|
|||
|
||||
if (methodOrConstructor instanceof Method) {
|
||||
Method method = (Method) methodOrConstructor;
|
||||
checkArgument(method.getDeclaringClass().isAssignableFrom(rawType),
|
||||
"%s is not defined by a supertype of %s", method, type);
|
||||
if (!method.getDeclaringClass().isAssignableFrom(rawType)) {
|
||||
throw new IllegalArgumentException(method + " is not defined by a supertype of " + type);
|
||||
}
|
||||
|
||||
genericExceptionTypes = method.getGenericExceptionTypes();
|
||||
|
||||
} else if (methodOrConstructor instanceof Constructor) {
|
||||
Constructor<?> constructor = (Constructor<?>) methodOrConstructor;
|
||||
checkArgument(constructor.getDeclaringClass().isAssignableFrom(rawType),
|
||||
"%s does not construct a supertype of %s", constructor, type);
|
||||
if (!constructor.getDeclaringClass().isAssignableFrom(rawType)) {
|
||||
throw new IllegalArgumentException(constructor + " does not construct a supertype of " + type);
|
||||
}
|
||||
genericExceptionTypes = constructor.getGenericExceptionTypes();
|
||||
|
||||
} else {
|
||||
|
@ -337,8 +344,10 @@ public class TypeLiteral<T> {
|
|||
* @since 2.0
|
||||
*/
|
||||
public TypeLiteral<?> getReturnType(Method method) {
|
||||
checkArgument(method.getDeclaringClass().isAssignableFrom(rawType),
|
||||
"%s is not defined by a supertype of %s", method, type);
|
||||
if (!method.getDeclaringClass().isAssignableFrom(rawType)) {
|
||||
throw new IllegalArgumentException(method + " is not defined by a supertype of " + type);
|
||||
}
|
||||
|
||||
return resolve(method.getGenericReturnType());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,17 +18,7 @@ package org.elasticsearch.common.inject.assistedinject;
|
|||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Iterables;
|
||||
import org.elasticsearch.common.inject.AbstractModule;
|
||||
import org.elasticsearch.common.inject.Binder;
|
||||
import org.elasticsearch.common.inject.Binding;
|
||||
import org.elasticsearch.common.inject.ConfigurationException;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.inject.Injector;
|
||||
import org.elasticsearch.common.inject.Key;
|
||||
import org.elasticsearch.common.inject.Module;
|
||||
import org.elasticsearch.common.inject.Provider;
|
||||
import org.elasticsearch.common.inject.ProvisionException;
|
||||
import org.elasticsearch.common.inject.TypeLiteral;
|
||||
import org.elasticsearch.common.inject.*;
|
||||
import org.elasticsearch.common.inject.internal.Errors;
|
||||
import org.elasticsearch.common.inject.internal.ErrorsException;
|
||||
import org.elasticsearch.common.inject.spi.Message;
|
||||
|
@ -43,7 +33,6 @@ import java.util.Arrays;
|
|||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
import static org.elasticsearch.common.inject.internal.Annotations.getKey;
|
||||
|
||||
/**
|
||||
|
@ -192,8 +181,9 @@ public final class FactoryProvider2<F> implements InvocationHandler, Provider<F>
|
|||
* Creates a child injector that binds the args, and returns the binding for the method's result.
|
||||
*/
|
||||
public Binding<?> getBindingFromNewInjector(final Method method, final Object[] args) {
|
||||
checkState(injector != null,
|
||||
"Factories.create() factories cannot be used until they're initialized by Guice.");
|
||||
if (injector == null) {
|
||||
throw new IllegalStateException("Factories.create() factories cannot be used until they're initialized by Guice.");
|
||||
}
|
||||
|
||||
final Key<?> returnType = returnTypesByMethod.get(method);
|
||||
|
||||
|
|
|
@ -22,8 +22,6 @@ import java.lang.annotation.Annotation;
|
|||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
|
||||
/**
|
||||
* Models a method or constructor parameter.
|
||||
*
|
||||
|
@ -144,8 +142,9 @@ class Parameter {
|
|||
Annotation bindingAnnotation = null;
|
||||
for (Annotation a : annotations) {
|
||||
if (a.annotationType().getAnnotation(BindingAnnotation.class) != null) {
|
||||
checkArgument(bindingAnnotation == null,
|
||||
"Parameter has multiple binding annotations: %s and %s", bindingAnnotation, a);
|
||||
if (bindingAnnotation != null) {
|
||||
throw new IllegalArgumentException("Parameter has multiple binding annotations: " + bindingAnnotation + " and " + a);
|
||||
}
|
||||
bindingAnnotation = a;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,8 +30,6 @@ import java.util.Map;
|
|||
import java.util.NoSuchElementException;
|
||||
import java.util.Objects;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
|
||||
/**
|
||||
* Static methods for working with types that we aren't publishing in the
|
||||
* public {@code Types} API.
|
||||
|
@ -152,8 +150,11 @@ public class MoreTypes {
|
|||
// Neal isn't either but suspects some pathological case related
|
||||
// to nested classes exists.
|
||||
Type rawType = parameterizedType.getRawType();
|
||||
checkArgument(rawType instanceof Class,
|
||||
"Expected a Class, but <%s> is of type %s", type, type.getClass().getName());
|
||||
if (!(rawType instanceof Class)) {
|
||||
throw new IllegalArgumentException(
|
||||
"Expected a Class, but <" + type +"> is of type " + type.getClass().getName()
|
||||
);
|
||||
}
|
||||
return (Class<?>) rawType;
|
||||
|
||||
} else if (type instanceof GenericArrayType) {
|
||||
|
@ -445,10 +446,13 @@ public class MoreTypes {
|
|||
// require an owner type if the raw type needs it
|
||||
if (rawType instanceof Class<?>) {
|
||||
Class rawTypeAsClass = (Class) rawType;
|
||||
checkArgument(ownerType != null || rawTypeAsClass.getEnclosingClass() == null,
|
||||
"No owner type for enclosed %s", rawType);
|
||||
checkArgument(ownerType == null || rawTypeAsClass.getEnclosingClass() != null,
|
||||
"Owner type for unenclosed %s", rawType);
|
||||
if (ownerType == null && rawTypeAsClass.getEnclosingClass() != null) {
|
||||
throw new IllegalArgumentException("No owner type for enclosed " + rawType);
|
||||
}
|
||||
if (ownerType != null && rawTypeAsClass.getEnclosingClass() == null) {
|
||||
throw new IllegalArgumentException("Owner type for unenclosed " + rawType);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
this.ownerType = ownerType == null ? null : canonicalize(ownerType);
|
||||
|
@ -561,13 +565,18 @@ public class MoreTypes {
|
|||
private final Type lowerBound;
|
||||
|
||||
public WildcardTypeImpl(Type[] upperBounds, Type[] lowerBounds) {
|
||||
checkArgument(lowerBounds.length <= 1, "Must have at most one lower bound.");
|
||||
checkArgument(upperBounds.length == 1, "Must have exactly one upper bound.");
|
||||
|
||||
if (lowerBounds.length > 1) {
|
||||
throw new IllegalArgumentException("Must have at most one lower bound.");
|
||||
}
|
||||
if (upperBounds.length != 1) {
|
||||
throw new IllegalArgumentException("Must have exactly one upper bound.");
|
||||
}
|
||||
if (lowerBounds.length == 1) {
|
||||
Objects.requireNonNull(lowerBounds[0], "lowerBound");
|
||||
checkNotPrimitive(lowerBounds[0], "wildcard bounds");
|
||||
checkArgument(upperBounds[0] == Object.class, "bounded both ways");
|
||||
if (upperBounds[0] != Object.class) {
|
||||
throw new IllegalArgumentException("bounded both ways");
|
||||
}
|
||||
this.lowerBound = canonicalize(lowerBounds[0]);
|
||||
this.upperBound = Object.class;
|
||||
|
||||
|
@ -615,8 +624,9 @@ public class MoreTypes {
|
|||
}
|
||||
|
||||
private static void checkNotPrimitive(Type type, String use) {
|
||||
checkArgument(!(type instanceof Class<?>) || !((Class) type).isPrimitive(),
|
||||
"Primitive types are not allowed in %s: %s", use, type);
|
||||
if (type instanceof Class<?> && ((Class) type).isPrimitive()) {
|
||||
throw new IllegalArgumentException("Primitive types are not allowed in " + use + ": " + type);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -25,16 +25,7 @@ import org.elasticsearch.common.inject.spi.Element;
|
|||
import org.elasticsearch.common.inject.spi.ElementVisitor;
|
||||
import org.elasticsearch.common.inject.spi.PrivateElements;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author jessewilson@google.com (Jesse Wilson)
|
||||
|
@ -88,7 +79,9 @@ public final class PrivateElementsImpl implements PrivateElements {
|
|||
}
|
||||
|
||||
public void initInjector(Injector injector) {
|
||||
checkState(this.injector == null, "injector already initialized");
|
||||
if (this.injector != null) {
|
||||
throw new IllegalStateException("injector already initialized");
|
||||
}
|
||||
this.injector = Objects.requireNonNull(injector, "injector");
|
||||
}
|
||||
|
||||
|
@ -137,7 +130,9 @@ public final class PrivateElementsImpl implements PrivateElements {
|
|||
public Object getExposedSource(Key<?> key) {
|
||||
getExposedKeys(); // ensure exposedKeysToSources is populated
|
||||
Object source = exposedKeysToSources.get(key);
|
||||
checkArgument(source != null, "%s not exposed by %s.", key, this);
|
||||
if (source == null) {
|
||||
throw new IllegalArgumentException(key + " not exposed by " + ".");
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
|
|
|
@ -24,8 +24,6 @@ import java.lang.reflect.AnnotatedElement;
|
|||
import java.lang.reflect.Method;
|
||||
import java.util.Objects;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
|
||||
/**
|
||||
* Matcher implementations. Supports matching classes and methods.
|
||||
*
|
||||
|
@ -103,8 +101,9 @@ public class Matchers {
|
|||
private static void checkForRuntimeRetention(
|
||||
Class<? extends Annotation> annotationType) {
|
||||
Retention retention = annotationType.getAnnotation(Retention.class);
|
||||
checkArgument(retention != null && retention.value() == RetentionPolicy.RUNTIME,
|
||||
"Annotation " + annotationType.getSimpleName() + " is missing RUNTIME retention");
|
||||
if (retention == null || retention.value() != RetentionPolicy.RUNTIME) {
|
||||
throw new IllegalArgumentException("Annotation " + annotationType.getSimpleName() + " is missing RUNTIME retention");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -16,43 +16,17 @@
|
|||
|
||||
package org.elasticsearch.common.inject.spi;
|
||||
|
||||
import org.elasticsearch.common.inject.AbstractModule;
|
||||
import org.elasticsearch.common.inject.Binder;
|
||||
import org.elasticsearch.common.inject.Binding;
|
||||
import org.elasticsearch.common.inject.Key;
|
||||
import org.elasticsearch.common.inject.MembersInjector;
|
||||
import org.elasticsearch.common.inject.Module;
|
||||
import org.elasticsearch.common.inject.PrivateBinder;
|
||||
import org.elasticsearch.common.inject.PrivateModule;
|
||||
import org.elasticsearch.common.inject.Provider;
|
||||
import org.elasticsearch.common.inject.Scope;
|
||||
import org.elasticsearch.common.inject.Stage;
|
||||
import org.elasticsearch.common.inject.TypeLiteral;
|
||||
import org.elasticsearch.common.inject.*;
|
||||
import org.elasticsearch.common.inject.binder.AnnotatedBindingBuilder;
|
||||
import org.elasticsearch.common.inject.binder.AnnotatedConstantBindingBuilder;
|
||||
import org.elasticsearch.common.inject.binder.AnnotatedElementBuilder;
|
||||
import org.elasticsearch.common.inject.internal.AbstractBindingBuilder;
|
||||
import org.elasticsearch.common.inject.internal.BindingBuilder;
|
||||
import org.elasticsearch.common.inject.internal.ConstantBindingBuilderImpl;
|
||||
import org.elasticsearch.common.inject.internal.Errors;
|
||||
import org.elasticsearch.common.inject.internal.ExposureBuilder;
|
||||
import org.elasticsearch.common.inject.internal.PrivateElementsImpl;
|
||||
import org.elasticsearch.common.inject.internal.ProviderMethodsModule;
|
||||
import org.elasticsearch.common.inject.internal.SourceProvider;
|
||||
import org.elasticsearch.common.inject.internal.*;
|
||||
import org.elasticsearch.common.inject.matcher.Matcher;
|
||||
import org.elasticsearch.common.logging.ESLogger;
|
||||
import org.elasticsearch.common.logging.Loggers;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Exposes elements of a module so they can be inspected, validated or {@link
|
||||
|
@ -156,7 +130,9 @@ public final class Elements {
|
|||
*/
|
||||
private RecordingBinder(
|
||||
RecordingBinder prototype, Object source, SourceProvider sourceProvider) {
|
||||
checkArgument(source == null ^ sourceProvider == null);
|
||||
if (!(source == null ^ sourceProvider == null)) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
|
||||
this.stage = prototype.stage;
|
||||
this.modules = prototype.modules;
|
||||
|
|
|
@ -22,8 +22,6 @@ import org.elasticsearch.common.inject.TypeLiteral;
|
|||
|
||||
import java.util.Objects;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
|
||||
/**
|
||||
* A lookup of the members injector for a type. Lookups are created explicitly in a module using
|
||||
* {@link org.elasticsearch.common.inject.Binder#getMembersInjector(Class) getMembersInjector()} statements:
|
||||
|
@ -68,7 +66,9 @@ public final class MembersInjectorLookup<T> implements Element {
|
|||
* @throws IllegalStateException if the delegate is already set
|
||||
*/
|
||||
public void initializeDelegate(MembersInjector<T> delegate) {
|
||||
checkState(this.delegate == null, "delegate already initialized");
|
||||
if (this.delegate != null) {
|
||||
throw new IllegalStateException("delegate already initialized");
|
||||
}
|
||||
this.delegate = Objects.requireNonNull(delegate, "delegate");
|
||||
}
|
||||
|
||||
|
@ -95,8 +95,9 @@ public final class MembersInjectorLookup<T> implements Element {
|
|||
return new MembersInjector<T>() {
|
||||
@Override
|
||||
public void injectMembers(T instance) {
|
||||
checkState(delegate != null,
|
||||
"This MembersInjector cannot be used until the Injector has been created.");
|
||||
if (delegate == null) {
|
||||
throw new IllegalStateException("This MembersInjector cannot be used until the Injector has been created.");
|
||||
}
|
||||
delegate.injectMembers(instance);
|
||||
}
|
||||
|
||||
|
|
|
@ -22,8 +22,6 @@ import org.elasticsearch.common.inject.Provider;
|
|||
|
||||
import java.util.Objects;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
|
||||
/**
|
||||
* A lookup of the provider for a type. Lookups are created explicitly in a module using
|
||||
* {@link org.elasticsearch.common.inject.Binder#getProvider(Class) getProvider()} statements:
|
||||
|
@ -46,8 +44,9 @@ public final class ProviderLookup<T> implements Element {
|
|||
|
||||
@Override
|
||||
public T get() {
|
||||
checkState(lookup.delegate != null,
|
||||
"This Provider cannot be used until the Injector has been created.");
|
||||
if (lookup.delegate == null) {
|
||||
throw new IllegalStateException( "This Provider cannot be used until the Injector has been created.");
|
||||
}
|
||||
return lookup.delegate.get();
|
||||
}
|
||||
|
||||
|
@ -89,7 +88,9 @@ public final class ProviderLookup<T> implements Element {
|
|||
* @throws IllegalStateException if the delegate is already set
|
||||
*/
|
||||
public void initializeDelegate(Provider<T> delegate) {
|
||||
checkState(this.delegate == null, "delegate already initialized");
|
||||
if (this.delegate != null) {
|
||||
throw new IllegalStateException("delegate already initialized");
|
||||
}
|
||||
this.delegate = Objects.requireNonNull(delegate, "delegate");
|
||||
}
|
||||
|
||||
|
|
|
@ -18,9 +18,6 @@
|
|||
*/
|
||||
package org.elasticsearch.common.unit;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import org.apache.lucene.search.FuzzyQuery;
|
||||
import org.apache.lucene.util.automaton.LevenshteinAutomata;
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
|
@ -46,7 +43,9 @@ public final class Fuzziness implements ToXContent {
|
|||
private final String fuzziness;
|
||||
|
||||
private Fuzziness(int fuzziness) {
|
||||
Preconditions.checkArgument(fuzziness >= 0 && fuzziness <= 2, "Valid edit distances are [0, 1, 2] but was [" + fuzziness + "]");
|
||||
if (fuzziness != 0 && fuzziness != 1 && fuzziness != 2) {
|
||||
throw new IllegalArgumentException("Valid edit distances are [0, 1, 2] but was [" + fuzziness + "]");
|
||||
}
|
||||
this.fuzziness = Integer.toString(fuzziness);
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
|
||||
package org.elasticsearch.common.unit;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import org.elasticsearch.ElasticsearchParseException;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
|
@ -46,7 +45,9 @@ public class SizeValue implements Streamable {
|
|||
}
|
||||
|
||||
public SizeValue(long size, SizeUnit sizeUnit) {
|
||||
Preconditions.checkArgument(size >= 0, "size in SizeValue may not be negative");
|
||||
if (size < 0) {
|
||||
throw new IllegalArgumentException("size in SizeValue may not be negative");
|
||||
}
|
||||
this.size = size;
|
||||
this.sizeUnit = sizeUnit;
|
||||
}
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
|
||||
package org.elasticsearch.common.util;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import org.apache.lucene.util.ArrayUtil;
|
||||
import org.apache.lucene.util.RamUsageEstimator;
|
||||
import org.elasticsearch.cache.recycler.PageCacheRecycler;
|
||||
|
@ -42,8 +41,12 @@ abstract class AbstractBigArray extends AbstractArray {
|
|||
protected AbstractBigArray(int pageSize, BigArrays bigArrays, boolean clearOnResize) {
|
||||
super(bigArrays, clearOnResize);
|
||||
this.recycler = bigArrays.recycler;
|
||||
Preconditions.checkArgument(pageSize >= 128, "pageSize must be >= 128");
|
||||
Preconditions.checkArgument((pageSize & (pageSize - 1)) == 0, "pageSize must be a power of two");
|
||||
if (pageSize < 128) {
|
||||
throw new IllegalArgumentException("pageSize must be >= 128");
|
||||
}
|
||||
if ((pageSize & (pageSize - 1)) != 0) {
|
||||
throw new IllegalArgumentException("pageSize must be a power of two");
|
||||
}
|
||||
this.pageShift = Integer.numberOfTrailingZeros(pageSize);
|
||||
this.pageMask = pageSize - 1;
|
||||
size = 0;
|
||||
|
@ -56,7 +59,9 @@ abstract class AbstractBigArray extends AbstractArray {
|
|||
|
||||
final int numPages(long capacity) {
|
||||
final long numPages = (capacity + pageMask) >>> pageShift;
|
||||
Preconditions.checkArgument(numPages <= Integer.MAX_VALUE, "pageSize=" + (pageMask + 1) + " is too small for such as capacity: " + capacity);
|
||||
if (numPages > Integer.MAX_VALUE) {
|
||||
throw new IllegalArgumentException("pageSize=" + (pageMask + 1) + " is too small for such as capacity: " + capacity);
|
||||
}
|
||||
return (int) numPages;
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
package org.elasticsearch.common.util;
|
||||
|
||||
import com.carrotsearch.hppc.BitMixer;
|
||||
import com.google.common.base.Preconditions;
|
||||
import org.elasticsearch.common.lease.Releasable;
|
||||
|
||||
/**
|
||||
|
@ -48,8 +47,12 @@ abstract class AbstractPagedHashMap implements Releasable {
|
|||
long mask;
|
||||
|
||||
AbstractPagedHashMap(long capacity, float maxLoadFactor, BigArrays bigArrays) {
|
||||
Preconditions.checkArgument(capacity >= 0, "capacity must be >= 0");
|
||||
Preconditions.checkArgument(maxLoadFactor > 0 && maxLoadFactor < 1, "maxLoadFactor must be > 0 and < 1");
|
||||
if (capacity < 0) {
|
||||
throw new IllegalArgumentException("capacity must be >= 0");
|
||||
}
|
||||
if (maxLoadFactor <= 0 || maxLoadFactor >= 1) {
|
||||
throw new IllegalArgumentException("maxLoadFactor must be > 0 and < 1");
|
||||
}
|
||||
this.bigArrays = bigArrays;
|
||||
this.maxLoadFactor = maxLoadFactor;
|
||||
long buckets = 1L + (long) (capacity / maxLoadFactor);
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
|
||||
package org.elasticsearch.common.util;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import org.apache.lucene.util.ArrayUtil;
|
||||
import org.apache.lucene.util.BytesRef;
|
||||
import org.apache.lucene.util.RamUsageEstimator;
|
||||
|
@ -55,9 +54,15 @@ public class BigArrays {
|
|||
/** Return the next size to grow to that is >= <code>minTargetSize</code>.
|
||||
* Inspired from {@link ArrayUtil#oversize(int, int)} and adapted to play nicely with paging. */
|
||||
public static long overSize(long minTargetSize, int pageSize, int bytesPerElement) {
|
||||
Preconditions.checkArgument(minTargetSize >= 0, "minTargetSize must be >= 0");
|
||||
Preconditions.checkArgument(pageSize >= 0, "pageSize must be > 0");
|
||||
Preconditions.checkArgument(bytesPerElement > 0, "bytesPerElement must be > 0");
|
||||
if (minTargetSize < 0) {
|
||||
throw new IllegalArgumentException("minTargetSize must be >= 0");
|
||||
}
|
||||
if (pageSize < 0) {
|
||||
throw new IllegalArgumentException("pageSize must be > 0");
|
||||
}
|
||||
if (bytesPerElement <= 0) {
|
||||
throw new IllegalArgumentException("bytesPerElement must be > 0");
|
||||
}
|
||||
|
||||
long newSize;
|
||||
if (minTargetSize < pageSize) {
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
|
||||
package org.elasticsearch.common.util;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import org.apache.lucene.util.ArrayUtil;
|
||||
import org.apache.lucene.util.BytesRef;
|
||||
import org.apache.lucene.util.RamUsageEstimator;
|
||||
|
@ -110,7 +109,9 @@ final class BigByteArray extends AbstractBigArray implements ByteArray {
|
|||
|
||||
@Override
|
||||
public void fill(long fromIndex, long toIndex, byte value) {
|
||||
Preconditions.checkArgument(fromIndex <= toIndex);
|
||||
if (fromIndex > toIndex) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
final int fromPage = pageIndex(fromIndex);
|
||||
final int toPage = pageIndex(toIndex - 1);
|
||||
if (fromPage == toPage) {
|
||||
|
|
|
@ -19,8 +19,6 @@
|
|||
|
||||
package org.elasticsearch.common.util;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
import org.apache.lucene.util.ArrayUtil;
|
||||
import org.apache.lucene.util.RamUsageEstimator;
|
||||
|
||||
|
@ -95,7 +93,9 @@ final class BigDoubleArray extends AbstractBigArray implements DoubleArray {
|
|||
|
||||
@Override
|
||||
public void fill(long fromIndex, long toIndex, double value) {
|
||||
Preconditions.checkArgument(fromIndex <= toIndex);
|
||||
if (fromIndex > toIndex) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
final long longBits = Double.doubleToRawLongBits(value);
|
||||
final int fromPage = pageIndex(fromIndex);
|
||||
final int toPage = pageIndex(toIndex - 1);
|
||||
|
|
|
@ -19,8 +19,6 @@
|
|||
|
||||
package org.elasticsearch.common.util;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
import org.apache.lucene.util.ArrayUtil;
|
||||
import org.apache.lucene.util.RamUsageEstimator;
|
||||
|
||||
|
@ -95,7 +93,9 @@ final class BigFloatArray extends AbstractBigArray implements FloatArray {
|
|||
|
||||
@Override
|
||||
public void fill(long fromIndex, long toIndex, float value) {
|
||||
Preconditions.checkArgument(fromIndex <= toIndex);
|
||||
if (fromIndex > toIndex) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
final int intBits = Float.floatToRawIntBits(value);
|
||||
final int fromPage = pageIndex(fromIndex);
|
||||
final int toPage = pageIndex(toIndex - 1);
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
|
||||
package org.elasticsearch.common.util;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import org.apache.lucene.util.ArrayUtil;
|
||||
import org.apache.lucene.util.RamUsageEstimator;
|
||||
|
||||
|
@ -71,7 +70,9 @@ final class BigIntArray extends AbstractBigArray implements IntArray {
|
|||
|
||||
@Override
|
||||
public void fill(long fromIndex, long toIndex, int value) {
|
||||
Preconditions.checkArgument(fromIndex <= toIndex);
|
||||
if (fromIndex > toIndex) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
final int fromPage = pageIndex(fromIndex);
|
||||
final int toPage = pageIndex(toIndex - 1);
|
||||
if (fromPage == toPage) {
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
|
||||
package org.elasticsearch.common.util;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import org.apache.lucene.util.ArrayUtil;
|
||||
import org.apache.lucene.util.RamUsageEstimator;
|
||||
|
||||
|
@ -93,7 +92,9 @@ final class BigLongArray extends AbstractBigArray implements LongArray {
|
|||
|
||||
@Override
|
||||
public void fill(long fromIndex, long toIndex, long value) {
|
||||
Preconditions.checkArgument(fromIndex <= toIndex);
|
||||
if (fromIndex > toIndex) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
if (fromIndex == toIndex) {
|
||||
return; // empty range
|
||||
}
|
||||
|
|
|
@ -23,24 +23,10 @@ import com.carrotsearch.hppc.DoubleArrayList;
|
|||
import com.carrotsearch.hppc.FloatArrayList;
|
||||
import com.carrotsearch.hppc.LongArrayList;
|
||||
import com.carrotsearch.hppc.ObjectArrayList;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.Iterators;
|
||||
import org.apache.lucene.util.BytesRef;
|
||||
import org.apache.lucene.util.BytesRefArray;
|
||||
import org.apache.lucene.util.BytesRefBuilder;
|
||||
import org.apache.lucene.util.InPlaceMergeSorter;
|
||||
import org.apache.lucene.util.IntroSorter;
|
||||
import org.apache.lucene.util.*;
|
||||
|
||||
import java.util.AbstractList;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.RandomAccess;
|
||||
import java.util.*;
|
||||
|
||||
/** Collections-related utility methods. */
|
||||
public enum CollectionUtils {
|
||||
|
@ -297,8 +283,12 @@ public enum CollectionUtils {
|
|||
private final int distance;
|
||||
|
||||
public RotatedList(List<T> list, int distance) {
|
||||
Preconditions.checkArgument(distance >= 0 && distance < list.size());
|
||||
Preconditions.checkArgument(list instanceof RandomAccess);
|
||||
if (distance < 0 || distance >= list.size()) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
if (!(list instanceof RandomAccess)) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
this.in = list;
|
||||
this.distance = distance;
|
||||
}
|
||||
|
|
|
@ -18,28 +18,18 @@
|
|||
*/
|
||||
package org.elasticsearch.gateway;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
import org.apache.lucene.codecs.CodecUtil;
|
||||
import org.apache.lucene.index.CorruptIndexException;
|
||||
import org.apache.lucene.index.IndexFormatTooNewException;
|
||||
import org.apache.lucene.index.IndexFormatTooOldException;
|
||||
import org.apache.lucene.store.Directory;
|
||||
import org.apache.lucene.store.IOContext;
|
||||
import org.apache.lucene.store.IndexInput;
|
||||
import org.apache.lucene.store.OutputStreamIndexOutput;
|
||||
import org.apache.lucene.store.SimpleFSDirectory;
|
||||
import org.apache.lucene.store.*;
|
||||
import org.apache.lucene.util.IOUtils;
|
||||
import org.elasticsearch.ExceptionsHelper;
|
||||
import org.elasticsearch.common.bytes.BytesArray;
|
||||
import org.elasticsearch.common.logging.ESLogger;
|
||||
import org.elasticsearch.common.lucene.store.IndexOutputOutputStream;
|
||||
import org.elasticsearch.common.lucene.store.InputStreamIndexInput;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentHelper;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.common.xcontent.*;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
|
@ -99,8 +89,12 @@ public abstract class MetaDataStateFormat<T> {
|
|||
* @throws IOException if an IOException occurs
|
||||
*/
|
||||
public final void write(final T state, final long version, final Path... locations) throws IOException {
|
||||
Preconditions.checkArgument(locations != null, "Locations must not be null");
|
||||
Preconditions.checkArgument(locations.length > 0, "One or more locations required");
|
||||
if (locations == null) {
|
||||
throw new IllegalArgumentException("Locations must not be null");
|
||||
}
|
||||
if (locations.length <= 0) {
|
||||
throw new IllegalArgumentException("One or more locations required");
|
||||
}
|
||||
final long maxStateId = findMaxStateId(prefix, locations)+1;
|
||||
assert maxStateId >= 0 : "maxStateId must be positive but was: [" + maxStateId + "]";
|
||||
final String fileName = prefix + maxStateId + STATE_FILE_EXTENSION;
|
||||
|
|
|
@ -19,8 +19,6 @@
|
|||
|
||||
package org.elasticsearch.index.fielddata.plain;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
import org.apache.lucene.index.BinaryDocValues;
|
||||
import org.apache.lucene.index.DocValues;
|
||||
import org.apache.lucene.index.LeafReaderContext;
|
||||
|
@ -52,7 +50,9 @@ public class BinaryDVNumericIndexFieldData extends DocValuesIndexFieldData imple
|
|||
|
||||
public BinaryDVNumericIndexFieldData(Index index, Names fieldNames, NumericType numericType, FieldDataType fieldDataType) {
|
||||
super(index, fieldNames, fieldDataType);
|
||||
Preconditions.checkArgument(numericType != null, "numericType must be non-null");
|
||||
if (numericType == null) {
|
||||
throw new IllegalArgumentException("numericType must be non-null");
|
||||
}
|
||||
this.numericType = numericType;
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
|
||||
package org.elasticsearch.index.fielddata.plain;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import org.apache.lucene.index.*;
|
||||
import org.apache.lucene.util.*;
|
||||
import org.apache.lucene.util.BitSet;
|
||||
|
@ -73,7 +72,9 @@ public class PackedArrayIndexFieldData extends AbstractIndexFieldData<AtomicNume
|
|||
CircuitBreakerService breakerService) {
|
||||
super(index, indexSettings, fieldNames, fieldDataType, cache);
|
||||
Objects.requireNonNull(numericType);
|
||||
Preconditions.checkArgument(EnumSet.of(NumericType.BOOLEAN, NumericType.BYTE, NumericType.SHORT, NumericType.INT, NumericType.LONG).contains(numericType), getClass().getSimpleName() + " only supports integer types, not " + numericType);
|
||||
if (!EnumSet.of(NumericType.BOOLEAN, NumericType.BYTE, NumericType.SHORT, NumericType.INT, NumericType.LONG).contains(numericType)) {
|
||||
throw new IllegalArgumentException(getClass().getSimpleName() + " only supports integer types, not " + numericType);
|
||||
}
|
||||
this.numericType = numericType;
|
||||
this.breakerService = breakerService;
|
||||
}
|
||||
|
|
|
@ -19,24 +19,12 @@
|
|||
|
||||
package org.elasticsearch.index.fielddata.plain;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
import org.apache.lucene.index.DocValues;
|
||||
import org.apache.lucene.index.FieldInfo;
|
||||
import org.apache.lucene.index.LeafReader;
|
||||
import org.apache.lucene.index.LeafReaderContext;
|
||||
import org.apache.lucene.index.NumericDocValues;
|
||||
import org.apache.lucene.index.SortedNumericDocValues;
|
||||
import org.apache.lucene.index.*;
|
||||
import org.apache.lucene.util.Accountable;
|
||||
import org.apache.lucene.util.NumericUtils;
|
||||
import org.elasticsearch.index.Index;
|
||||
import org.elasticsearch.index.fielddata.AtomicNumericFieldData;
|
||||
import org.elasticsearch.index.fielddata.FieldData;
|
||||
import org.elasticsearch.index.fielddata.FieldDataType;
|
||||
import org.elasticsearch.index.fielddata.*;
|
||||
import org.elasticsearch.index.fielddata.IndexFieldData.XFieldComparatorSource.Nested;
|
||||
import org.elasticsearch.index.fielddata.IndexNumericFieldData;
|
||||
import org.elasticsearch.index.fielddata.NumericDoubleValues;
|
||||
import org.elasticsearch.index.fielddata.SortedNumericDoubleValues;
|
||||
import org.elasticsearch.index.fielddata.fieldcomparator.DoubleValuesComparatorSource;
|
||||
import org.elasticsearch.index.fielddata.fieldcomparator.FloatValuesComparatorSource;
|
||||
import org.elasticsearch.index.fielddata.fieldcomparator.LongValuesComparatorSource;
|
||||
|
@ -56,7 +44,9 @@ public class SortedNumericDVIndexFieldData extends DocValuesIndexFieldData imple
|
|||
|
||||
public SortedNumericDVIndexFieldData(Index index, Names fieldNames, NumericType numericType, FieldDataType fieldDataType) {
|
||||
super(index, fieldNames, fieldDataType);
|
||||
Preconditions.checkArgument(numericType != null, "numericType must be non-null");
|
||||
if (numericType == null) {
|
||||
throw new IllegalArgumentException("numericType must be non-null");
|
||||
}
|
||||
this.numericType = numericType;
|
||||
}
|
||||
|
||||
|
|
|
@ -20,8 +20,6 @@
|
|||
package org.elasticsearch.search.aggregations.metrics.cardinality;
|
||||
|
||||
import com.carrotsearch.hppc.BitMixer;
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
import org.apache.lucene.index.LeafReaderContext;
|
||||
import org.apache.lucene.index.RandomAccessOrds;
|
||||
import org.apache.lucene.index.SortedNumericDocValues;
|
||||
|
@ -234,7 +232,9 @@ public class CardinalityAggregator extends NumericMetricsAggregator.SingleValue
|
|||
private ObjectArray<FixedBitSet> visitedOrds;
|
||||
|
||||
OrdinalsCollector(HyperLogLogPlusPlus counts, RandomAccessOrds values, BigArrays bigArrays) {
|
||||
Preconditions.checkArgument(values.getValueCount() <= Integer.MAX_VALUE);
|
||||
if (values.getValueCount() > Integer.MAX_VALUE) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
maxOrd = (int) values.getValueCount();
|
||||
this.bigArrays = bigArrays;
|
||||
this.counts = counts;
|
||||
|
|
|
@ -19,12 +19,10 @@
|
|||
|
||||
package org.elasticsearch.search.aggregations.metrics.cardinality;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import org.apache.lucene.util.BytesRef;
|
||||
import org.apache.lucene.util.LongBitSet;
|
||||
import org.apache.lucene.util.RamUsageEstimator;
|
||||
import org.apache.lucene.util.packed.PackedInts;
|
||||
import org.elasticsearch.ElasticsearchException;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||
import org.elasticsearch.common.lease.Releasable;
|
||||
|
@ -37,7 +35,6 @@ import org.elasticsearch.common.util.IntArray;
|
|||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Hyperloglog++ counter, implemented based on pseudo code from
|
||||
|
@ -162,8 +159,12 @@ public final class HyperLogLogPlusPlus implements Releasable {
|
|||
private final double alphaMM;
|
||||
|
||||
public HyperLogLogPlusPlus(int precision, BigArrays bigArrays, long initialBucketCount) {
|
||||
Preconditions.checkArgument(precision >= 4, "precision must be >= 4");
|
||||
Preconditions.checkArgument(precision <= 18, "precision must be <= 18");
|
||||
if (precision < 4) {
|
||||
throw new IllegalArgumentException("precision must be >= 4");
|
||||
}
|
||||
if (precision > 18) {
|
||||
throw new IllegalArgumentException("precision must be <= 18");
|
||||
}
|
||||
p = precision;
|
||||
m = 1 << p;
|
||||
this.bigArrays = bigArrays;
|
||||
|
@ -198,7 +199,9 @@ public final class HyperLogLogPlusPlus implements Releasable {
|
|||
}
|
||||
|
||||
public void merge(long thisBucket, HyperLogLogPlusPlus other, long otherBucket) {
|
||||
Preconditions.checkArgument(p == other.p);
|
||||
if (p != other.p) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
ensureCapacity(thisBucket + 1);
|
||||
if (other.algorithm.get(otherBucket) == LINEAR_COUNTING) {
|
||||
final IntArray values = other.hashSet.values(otherBucket);
|
||||
|
|
|
@ -97,9 +97,7 @@ com.google.common.base.Strings
|
|||
com.google.common.base.Throwables
|
||||
com.google.common.collect.Maps
|
||||
com.google.common.collect.Sets
|
||||
com.google.common.base.Preconditions#checkNotNull(java.lang.Object)
|
||||
com.google.common.base.Preconditions#checkNotNull(java.lang.Object, java.lang.Object)
|
||||
com.google.common.base.Preconditions#checkNotNull(java.lang.Object, java.lang.String, java.lang.Object[])
|
||||
com.google.common.base.Preconditions
|
||||
com.google.common.collect.ImmutableSortedSet
|
||||
com.google.common.collect.Queues
|
||||
com.google.common.util.concurrent.ListenableFuture
|
||||
|
|
Loading…
Reference in New Issue