Merge branch 'master' into feature/query-refactoring
Conflicts: core/src/main/java/org/elasticsearch/index/query/HasChildQueryBuilder.java core/src/main/java/org/elasticsearch/index/query/HasChildQueryParser.java core/src/main/java/org/elasticsearch/index/query/HasParentQueryBuilder.java core/src/main/java/org/elasticsearch/index/query/HasParentQueryParser.java core/src/main/java/org/elasticsearch/index/query/functionscore/FunctionScoreQueryBuilder.java core/src/main/java/org/elasticsearch/index/query/functionscore/FunctionScoreQueryParser.java core/src/main/java/org/elasticsearch/index/query/functionscore/factor/FactorParser.java core/src/test/java/org/elasticsearch/ExceptionSerializationTests.java core/src/test/java/org/elasticsearch/benchmark/search/child/ChildSearchBenchmark.java core/src/test/java/org/elasticsearch/benchmark/search/child/ChildSearchShortCircuitBenchmark.java core/src/test/java/org/elasticsearch/index/query/SimpleIndexQueryParserTests.java core/src/test/java/org/elasticsearch/percolator/PercolatorIT.java core/src/test/java/org/elasticsearch/search/child/ChildQuerySearchIT.java docs/reference/query-dsl/has-parent-query.asciidoc
This commit is contained in:
commit
73f7df510e
|
@ -58,28 +58,28 @@ public class CustomFieldQuery extends FieldQuery {
|
|||
}
|
||||
|
||||
@Override
|
||||
void flatten(Query sourceQuery, IndexReader reader, Collection<Query> flatQueries) throws IOException {
|
||||
void flatten(Query sourceQuery, IndexReader reader, Collection<Query> flatQueries, float boost) throws IOException {
|
||||
if (sourceQuery instanceof SpanTermQuery) {
|
||||
super.flatten(new TermQuery(((SpanTermQuery) sourceQuery).getTerm()), reader, flatQueries);
|
||||
super.flatten(new TermQuery(((SpanTermQuery) sourceQuery).getTerm()), reader, flatQueries, boost);
|
||||
} else if (sourceQuery instanceof ConstantScoreQuery) {
|
||||
flatten(((ConstantScoreQuery) sourceQuery).getQuery(), reader, flatQueries);
|
||||
flatten(((ConstantScoreQuery) sourceQuery).getQuery(), reader, flatQueries, boost);
|
||||
} else if (sourceQuery instanceof FunctionScoreQuery) {
|
||||
flatten(((FunctionScoreQuery) sourceQuery).getSubQuery(), reader, flatQueries);
|
||||
flatten(((FunctionScoreQuery) sourceQuery).getSubQuery(), reader, flatQueries, boost);
|
||||
} else if (sourceQuery instanceof FilteredQuery) {
|
||||
flatten(((FilteredQuery) sourceQuery).getQuery(), reader, flatQueries);
|
||||
flatten(((FilteredQuery) sourceQuery).getQuery(), reader, flatQueries, boost);
|
||||
flatten(((FilteredQuery) sourceQuery).getFilter(), reader, flatQueries);
|
||||
} else if (sourceQuery instanceof MultiPhrasePrefixQuery) {
|
||||
flatten(sourceQuery.rewrite(reader), reader, flatQueries);
|
||||
flatten(sourceQuery.rewrite(reader), reader, flatQueries, boost);
|
||||
} else if (sourceQuery instanceof FiltersFunctionScoreQuery) {
|
||||
flatten(((FiltersFunctionScoreQuery) sourceQuery).getSubQuery(), reader, flatQueries);
|
||||
flatten(((FiltersFunctionScoreQuery) sourceQuery).getSubQuery(), reader, flatQueries, boost);
|
||||
} else if (sourceQuery instanceof MultiPhraseQuery) {
|
||||
MultiPhraseQuery q = ((MultiPhraseQuery) sourceQuery);
|
||||
convertMultiPhraseQuery(0, new int[q.getTermArrays().size()], q, q.getTermArrays(), q.getPositions(), reader, flatQueries);
|
||||
} else if (sourceQuery instanceof BlendedTermQuery) {
|
||||
final BlendedTermQuery blendedTermQuery = (BlendedTermQuery) sourceQuery;
|
||||
flatten(blendedTermQuery.rewrite(reader), reader, flatQueries);
|
||||
flatten(blendedTermQuery.rewrite(reader), reader, flatQueries, boost);
|
||||
} else {
|
||||
super.flatten(sourceQuery, reader, flatQueries);
|
||||
super.flatten(sourceQuery, reader, flatQueries, boost);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -93,7 +93,7 @@ public class CustomFieldQuery extends FieldQuery {
|
|||
if (numTerms > 16) {
|
||||
for (Term[] currentPosTerm : terms) {
|
||||
for (Term term : currentPosTerm) {
|
||||
super.flatten(new TermQuery(term), reader, flatQueries);
|
||||
super.flatten(new TermQuery(term), reader, flatQueries, orig.getBoost());
|
||||
}
|
||||
}
|
||||
return;
|
||||
|
@ -111,7 +111,7 @@ public class CustomFieldQuery extends FieldQuery {
|
|||
}
|
||||
PhraseQuery query = queryBuilder.build();
|
||||
query.setBoost(orig.getBoost());
|
||||
this.flatten(query, reader, flatQueries);
|
||||
this.flatten(query, reader, flatQueries, orig.getBoost());
|
||||
} else {
|
||||
Term[] t = terms.get(currentPos);
|
||||
for (int i = 0; i < t.length; i++) {
|
||||
|
@ -127,7 +127,7 @@ public class CustomFieldQuery extends FieldQuery {
|
|||
return;
|
||||
}
|
||||
if (sourceFilter instanceof QueryWrapperFilter) {
|
||||
flatten(((QueryWrapperFilter) sourceFilter).getQuery(), reader, flatQueries);
|
||||
flatten(((QueryWrapperFilter) sourceFilter).getQuery(), reader, flatQueries, 1.0F);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,12 +19,13 @@
|
|||
|
||||
package org.elasticsearch.action;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import org.elasticsearch.action.support.PlainListenableActionFuture;
|
||||
import org.elasticsearch.client.ElasticsearchClient;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.threadpool.ThreadPool;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
@ -36,7 +37,7 @@ public abstract class ActionRequestBuilder<Request extends ActionRequest, Respon
|
|||
protected final ElasticsearchClient client;
|
||||
|
||||
protected ActionRequestBuilder(ElasticsearchClient client, Action<Request, Response, RequestBuilder> action, Request request) {
|
||||
Preconditions.checkNotNull(action, "action must not be null");
|
||||
Objects.requireNonNull(action, "action must not be null");
|
||||
this.action = action;
|
||||
this.request = request;
|
||||
this.client = client;
|
||||
|
|
|
@ -36,11 +36,10 @@ import org.elasticsearch.common.settings.Settings;
|
|||
import org.elasticsearch.threadpool.ThreadPool;
|
||||
import org.elasticsearch.transport.TransportService;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.google.common.collect.Sets.newHashSet;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class TransportClusterSearchShardsAction extends TransportMasterNodeReadAction<ClusterSearchShardsRequest, ClusterSearchShardsResponse> {
|
||||
|
@ -72,7 +71,7 @@ public class TransportClusterSearchShardsAction extends TransportMasterNodeReadA
|
|||
ClusterState clusterState = clusterService.state();
|
||||
String[] concreteIndices = indexNameExpressionResolver.concreteIndices(clusterState, request);
|
||||
Map<String, Set<String>> routingMap = indexNameExpressionResolver.resolveSearchRouting(state, request.routing(), request.indices());
|
||||
Set<String> nodeIds = newHashSet();
|
||||
Set<String> nodeIds = new HashSet<>();
|
||||
GroupShardsIterator groupShardsIterator = clusterService.operationRouting().searchShards(clusterState, concreteIndices, routingMap, request.preference());
|
||||
ShardRouting shard;
|
||||
ClusterSearchShardsGroup[] groupResponses = new ClusterSearchShardsGroup[groupShardsIterator.size()];
|
||||
|
|
|
@ -33,12 +33,11 @@ import org.elasticsearch.common.xcontent.XContentFactory;
|
|||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.google.common.collect.Sets.newHashSet;
|
||||
|
||||
/**
|
||||
* Status of a snapshot
|
||||
*/
|
||||
|
@ -103,7 +102,7 @@ public class SnapshotStatus implements ToXContent, Streamable {
|
|||
|
||||
ImmutableMap.Builder<String, SnapshotIndexStatus> indicesStatus = ImmutableMap.builder();
|
||||
|
||||
Set<String> indices = newHashSet();
|
||||
Set<String> indices = new HashSet<>();
|
||||
for (SnapshotIndexShardStatus shard : shards) {
|
||||
indices.add(shard.getIndex());
|
||||
}
|
||||
|
|
|
@ -44,12 +44,11 @@ import java.io.IOException;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.google.common.collect.Sets.newHashSet;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class TransportSnapshotsStatusAction extends TransportMasterNodeAction<SnapshotsStatusRequest, SnapshotsStatusResponse> {
|
||||
|
@ -94,7 +93,7 @@ public class TransportSnapshotsStatusAction extends TransportMasterNodeAction<Sn
|
|||
return;
|
||||
}
|
||||
|
||||
Set<String> nodesIds = newHashSet();
|
||||
Set<String> nodesIds = new HashSet<>();
|
||||
for (SnapshotsInProgress.Entry entry : currentSnapshots) {
|
||||
for (SnapshotsInProgress.ShardSnapshotStatus status : entry.shards().values()) {
|
||||
if (status.nodeId() != null) {
|
||||
|
@ -140,7 +139,7 @@ public class TransportSnapshotsStatusAction extends TransportMasterNodeAction<Sn
|
|||
TransportNodesSnapshotsStatus.NodesSnapshotStatus nodeSnapshotStatuses) throws IOException {
|
||||
// First process snapshot that are currently processed
|
||||
List<SnapshotStatus> builder = new ArrayList<>();
|
||||
Set<SnapshotId> currentSnapshotIds = newHashSet();
|
||||
Set<SnapshotId> currentSnapshotIds = new HashSet<>();
|
||||
if (!currentSnapshots.isEmpty()) {
|
||||
Map<String, TransportNodesSnapshotsStatus.NodeSnapshotStatus> nodeSnapshotStatusMap;
|
||||
if (nodeSnapshotStatuses != null) {
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
|
||||
package org.elasticsearch.action.admin.indices.alias;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions;
|
||||
import org.elasticsearch.action.support.ActionFilters;
|
||||
|
@ -38,7 +37,11 @@ import org.elasticsearch.rest.action.admin.indices.alias.delete.AliasesNotFoundE
|
|||
import org.elasticsearch.threadpool.ThreadPool;
|
||||
import org.elasticsearch.transport.TransportService;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Add/remove aliases action
|
||||
|
@ -68,7 +71,7 @@ public class TransportIndicesAliasesAction extends TransportMasterNodeAction<Ind
|
|||
|
||||
@Override
|
||||
protected ClusterBlockException checkBlock(IndicesAliasesRequest request, ClusterState state) {
|
||||
Set<String> indices = Sets.newHashSet();
|
||||
Set<String> indices = new HashSet<>();
|
||||
for (AliasActions aliasAction : request.aliasActions()) {
|
||||
for (String index : aliasAction.indices()) {
|
||||
indices.add(index);
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
|
||||
package org.elasticsearch.action.admin.indices.create;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import org.elasticsearch.action.admin.indices.alias.Alias;
|
||||
import org.elasticsearch.cluster.ack.ClusterStateUpdateRequest;
|
||||
import org.elasticsearch.cluster.block.ClusterBlock;
|
||||
|
@ -28,6 +27,7 @@ import org.elasticsearch.common.settings.Settings;
|
|||
import org.elasticsearch.transport.TransportMessage;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -47,11 +47,11 @@ public class CreateIndexClusterStateUpdateRequest extends ClusterStateUpdateRequ
|
|||
|
||||
private final Map<String, String> mappings = new HashMap<>();
|
||||
|
||||
private final Set<Alias> aliases = Sets.newHashSet();
|
||||
private final Set<Alias> aliases = new HashSet<>();
|
||||
|
||||
private final Map<String, IndexMetaData.Custom> customs = new HashMap<>();
|
||||
|
||||
private final Set<ClusterBlock> blocks = Sets.newHashSet();
|
||||
private final Set<ClusterBlock> blocks = new HashSet<>();
|
||||
|
||||
|
||||
CreateIndexClusterStateUpdateRequest(TransportMessage originalMessage, String cause, String index, boolean updateAllTypes) {
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
package org.elasticsearch.action.admin.indices.create;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import com.google.common.collect.Sets;
|
||||
import org.elasticsearch.ElasticsearchGenerationException;
|
||||
import org.elasticsearch.ElasticsearchParseException;
|
||||
import org.elasticsearch.action.ActionRequest;
|
||||
|
@ -45,6 +44,7 @@ import org.elasticsearch.common.xcontent.XContentType;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -72,7 +72,7 @@ public class CreateIndexRequest extends AcknowledgedRequest<CreateIndexRequest>
|
|||
|
||||
private final Map<String, String> mappings = new HashMap<>();
|
||||
|
||||
private final Set<Alias> aliases = Sets.newHashSet();
|
||||
private final Set<Alias> aliases = new HashSet<>();
|
||||
|
||||
private final Map<String, IndexMetaData.Custom> customs = new HashMap<>();
|
||||
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
|
||||
package org.elasticsearch.action.admin.indices.segments;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import org.apache.lucene.util.Accountable;
|
||||
import org.elasticsearch.action.ShardOperationFailedException;
|
||||
import org.elasticsearch.action.support.broadcast.BroadcastResponse;
|
||||
|
@ -35,6 +34,7 @@ import java.io.IOException;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
@ -60,7 +60,7 @@ public class IndicesSegmentResponse extends BroadcastResponse implements ToXCont
|
|||
}
|
||||
Map<String, IndexSegments> indicesSegments = new HashMap<>();
|
||||
|
||||
Set<String> indices = Sets.newHashSet();
|
||||
Set<String> indices = new HashSet<>();
|
||||
for (ShardSegments shard : shards) {
|
||||
indices.add(shard.getShardRouting().getIndex());
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
package org.elasticsearch.action.admin.indices.stats;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Sets;
|
||||
import org.elasticsearch.action.ShardOperationFailedException;
|
||||
import org.elasticsearch.action.support.broadcast.BroadcastResponse;
|
||||
import org.elasticsearch.cluster.routing.ShardRouting;
|
||||
|
@ -34,6 +33,7 @@ import org.elasticsearch.common.xcontent.XContentFactory;
|
|||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
@ -87,7 +87,7 @@ public class IndicesStatsResponse extends BroadcastResponse implements ToXConten
|
|||
}
|
||||
Map<String, IndexStats> indicesStats = new HashMap<>();
|
||||
|
||||
Set<String> indices = Sets.newHashSet();
|
||||
Set<String> indices = new HashSet<>();
|
||||
for (ShardStats shard : shards) {
|
||||
indices.add(shard.getShardRouting().getIndex());
|
||||
}
|
||||
|
|
|
@ -42,10 +42,10 @@ import org.elasticsearch.common.xcontent.support.XContentMapValues;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.google.common.collect.Sets.newHashSet;
|
||||
import static org.elasticsearch.action.ValidateActions.addValidationError;
|
||||
import static org.elasticsearch.common.settings.Settings.Builder.EMPTY_SETTINGS;
|
||||
import static org.elasticsearch.common.settings.Settings.readSettingsFromStream;
|
||||
|
@ -70,7 +70,7 @@ public class PutIndexTemplateRequest extends MasterNodeRequest<PutIndexTemplateR
|
|||
|
||||
private Map<String, String> mappings = new HashMap<>();
|
||||
|
||||
private final Set<Alias> aliases = newHashSet();
|
||||
private final Set<Alias> aliases = new HashSet<>();
|
||||
|
||||
private Map<String, IndexMetaData.Custom> customs = new HashMap<>();
|
||||
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
|
||||
package org.elasticsearch.action.admin.indices.upgrade.get;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import org.elasticsearch.action.ShardOperationFailedException;
|
||||
import org.elasticsearch.action.support.broadcast.BroadcastResponse;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
|
@ -31,6 +30,7 @@ import org.elasticsearch.common.xcontent.XContentBuilderString;
|
|||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
@ -54,7 +54,7 @@ public class UpgradeStatusResponse extends BroadcastResponse implements ToXConte
|
|||
}
|
||||
Map<String, IndexUpgradeStatus> indicesUpgradeStats = new HashMap<>();
|
||||
|
||||
Set<String> indices = Sets.newHashSet();
|
||||
Set<String> indices = new HashSet<>();
|
||||
for (ShardUpgradeStatus shard : shards) {
|
||||
indices.add(shard.getIndex());
|
||||
}
|
||||
|
|
|
@ -46,12 +46,11 @@ import org.elasticsearch.transport.TransportService;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.google.common.collect.Sets.newHashSet;
|
||||
|
||||
/**
|
||||
* Upgrade index/indices action.
|
||||
*/
|
||||
|
@ -158,7 +157,7 @@ public class TransportUpgradeAction extends TransportBroadcastByNodeAction<Upgra
|
|||
* Finds all indices that have not all primaries available
|
||||
*/
|
||||
private Set<String> indicesWithMissingPrimaries(ClusterState clusterState, String[] concreteIndices) {
|
||||
Set<String> indices = newHashSet();
|
||||
Set<String> indices = new HashSet<>();
|
||||
RoutingTable routingTable = clusterState.routingTable();
|
||||
for (String index : concreteIndices) {
|
||||
IndexRoutingTable indexRoutingTable = routingTable.index(index);
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
|
||||
package org.elasticsearch.action.termvectors;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import org.elasticsearch.ElasticsearchException;
|
||||
import org.elasticsearch.ElasticsearchParseException;
|
||||
import org.elasticsearch.action.ActionRequestValidationException;
|
||||
|
@ -33,6 +32,7 @@ import org.elasticsearch.common.bytes.BytesReference;
|
|||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||
import org.elasticsearch.common.lucene.uid.Versions;
|
||||
import org.elasticsearch.common.util.set.Sets;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.index.VersionType;
|
||||
|
|
|
@ -26,6 +26,7 @@ import org.elasticsearch.common.logging.ESLogger;
|
|||
import org.elasticsearch.common.logging.Loggers;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.nio.file.FileVisitResult;
|
||||
|
@ -70,21 +71,43 @@ public class JarHell {
|
|||
}
|
||||
|
||||
/**
|
||||
* Checks the current classloader for duplicate classes
|
||||
* Checks the current classpath for duplicate classes
|
||||
* @throws IllegalStateException if jar hell was found
|
||||
*/
|
||||
public static void checkJarHell() throws Exception {
|
||||
ClassLoader loader = JarHell.class.getClassLoader();
|
||||
if (loader instanceof URLClassLoader == false) {
|
||||
return;
|
||||
}
|
||||
ESLogger logger = Loggers.getLogger(JarHell.class);
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("java.class.path: {}", System.getProperty("java.class.path"));
|
||||
logger.debug("sun.boot.class.path: {}", System.getProperty("sun.boot.class.path"));
|
||||
logger.debug("classloader urls: {}", Arrays.toString(((URLClassLoader)loader).getURLs()));
|
||||
if (loader instanceof URLClassLoader ) {
|
||||
logger.debug("classloader urls: {}", Arrays.toString(((URLClassLoader)loader).getURLs()));
|
||||
}
|
||||
}
|
||||
checkJarHell(((URLClassLoader) loader).getURLs());
|
||||
checkJarHell(parseClassPath());
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the classpath into a set of URLs
|
||||
*/
|
||||
@SuppressForbidden(reason = "resolves against CWD because that is how classpaths work")
|
||||
public static URL[] parseClassPath() {
|
||||
String elements[] = System.getProperty("java.class.path").split(System.getProperty("path.separator"));
|
||||
URL urlElements[] = new URL[elements.length];
|
||||
for (int i = 0; i < elements.length; i++) {
|
||||
String element = elements[i];
|
||||
// empty classpath element behaves like CWD.
|
||||
if (element.isEmpty()) {
|
||||
element = System.getProperty("user.dir");
|
||||
}
|
||||
try {
|
||||
urlElements[i] = PathUtils.get(element).toUri().toURL();
|
||||
} catch (MalformedURLException e) {
|
||||
// should not happen, as we use the filesystem API
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
return urlElements;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -24,7 +24,6 @@ import org.elasticsearch.env.Environment;
|
|||
|
||||
import java.io.*;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.nio.file.AccessMode;
|
||||
import java.nio.file.FileAlreadyExistsException;
|
||||
import java.nio.file.Files;
|
||||
|
@ -121,8 +120,8 @@ final class Security {
|
|||
private static final Map<Pattern,String> SPECIAL_JARS;
|
||||
static {
|
||||
Map<Pattern,String> m = new IdentityHashMap<>();
|
||||
m.put(Pattern.compile(".*lucene-core-.*\\.jar$"), "es.security.jar.lucene.core");
|
||||
m.put(Pattern.compile(".*securemock-.*\\.jar$"), "es.security.jar.elasticsearch.securemock");
|
||||
m.put(Pattern.compile(".*lucene-core-.*\\.jar$"), "es.security.jar.lucene.core");
|
||||
m.put(Pattern.compile(".*securemock-.*\\.jar$"), "es.security.jar.elasticsearch.securemock");
|
||||
SPECIAL_JARS = Collections.unmodifiableMap(m);
|
||||
}
|
||||
|
||||
|
@ -133,27 +132,21 @@ final class Security {
|
|||
*/
|
||||
@SuppressForbidden(reason = "proper use of URL")
|
||||
static void setCodebaseProperties() {
|
||||
ClassLoader loader = Security.class.getClassLoader();
|
||||
if (loader instanceof URLClassLoader) {
|
||||
for (URL url : ((URLClassLoader)loader).getURLs()) {
|
||||
for (Map.Entry<Pattern,String> e : SPECIAL_JARS.entrySet()) {
|
||||
if (e.getKey().matcher(url.getPath()).matches()) {
|
||||
String prop = e.getValue();
|
||||
if (System.getProperty(prop) != null) {
|
||||
throw new IllegalStateException("property: " + prop + " is unexpectedly set: " + System.getProperty(prop));
|
||||
}
|
||||
System.setProperty(prop, url.toString());
|
||||
for (URL url : JarHell.parseClassPath()) {
|
||||
for (Map.Entry<Pattern,String> e : SPECIAL_JARS.entrySet()) {
|
||||
if (e.getKey().matcher(url.getPath()).matches()) {
|
||||
String prop = e.getValue();
|
||||
if (System.getProperty(prop) != null) {
|
||||
throw new IllegalStateException("property: " + prop + " is unexpectedly set: " + System.getProperty(prop));
|
||||
}
|
||||
System.setProperty(prop, url.toString());
|
||||
}
|
||||
}
|
||||
for (String prop : SPECIAL_JARS.values()) {
|
||||
if (System.getProperty(prop) == null) {
|
||||
System.setProperty(prop, "file:/dev/null"); // no chance to be interpreted as "all"
|
||||
}
|
||||
}
|
||||
for (String prop : SPECIAL_JARS.values()) {
|
||||
if (System.getProperty(prop) == null) {
|
||||
System.setProperty(prop, "file:/dev/null"); // no chance to be interpreted as "all"
|
||||
}
|
||||
} else {
|
||||
// we could try to parse the classpath or something, but screw it for now.
|
||||
throw new UnsupportedOperationException("Unsupported system classloader type: " + loader.getClass());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
package org.elasticsearch.client.transport;
|
||||
|
||||
import com.carrotsearch.hppc.cursors.ObjectCursor;
|
||||
import com.google.common.collect.Sets;
|
||||
import org.elasticsearch.ExceptionsHelper;
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
|
@ -396,7 +395,7 @@ public class TransportClientNodesService extends AbstractComponent {
|
|||
protected void doSample() {
|
||||
// the nodes we are going to ping include the core listed nodes that were added
|
||||
// and the last round of discovered nodes
|
||||
Set<DiscoveryNode> nodesToPing = Sets.newHashSet();
|
||||
Set<DiscoveryNode> nodesToPing = new HashSet<>();
|
||||
for (DiscoveryNode node : listedNodes) {
|
||||
nodesToPing.add(node);
|
||||
}
|
||||
|
|
|
@ -90,6 +90,7 @@ import org.elasticsearch.indices.recovery.RecoverySettings;
|
|||
import org.elasticsearch.indices.store.IndicesStore;
|
||||
import org.elasticsearch.indices.ttl.IndicesTTLService;
|
||||
import org.elasticsearch.search.SearchService;
|
||||
import org.elasticsearch.search.internal.DefaultSearchContext;
|
||||
import org.elasticsearch.threadpool.ThreadPool;
|
||||
import org.elasticsearch.transport.TransportService;
|
||||
|
||||
|
@ -275,6 +276,7 @@ public class ClusterModule extends AbstractModule {
|
|||
registerIndexDynamicSetting(IndicesRequestCache.INDEX_CACHE_REQUEST_ENABLED, Validator.BOOLEAN);
|
||||
registerIndexDynamicSetting(IndicesRequestCache.DEPRECATED_INDEX_CACHE_REQUEST_ENABLED, Validator.BOOLEAN);
|
||||
registerIndexDynamicSetting(UnassignedInfo.INDEX_DELAYED_NODE_LEFT_TIMEOUT_SETTING, Validator.TIME);
|
||||
registerIndexDynamicSetting(DefaultSearchContext.MAX_RESULT_WINDOW, Validator.POSITIVE_INTEGER);
|
||||
}
|
||||
|
||||
public void registerIndexDynamicSetting(String setting, Validator validator) {
|
||||
|
|
|
@ -21,7 +21,6 @@ package org.elasticsearch.cluster.block;
|
|||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Sets;
|
||||
import org.elasticsearch.cluster.AbstractDiffable;
|
||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
import org.elasticsearch.cluster.metadata.MetaDataIndexStateService;
|
||||
|
@ -31,6 +30,7 @@ import org.elasticsearch.rest.RestStatus;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -270,7 +270,7 @@ public class ClusterBlocks extends AbstractDiffable<ClusterBlocks> {
|
|||
|
||||
public static class Builder {
|
||||
|
||||
private Set<ClusterBlock> global = Sets.newHashSet();
|
||||
private Set<ClusterBlock> global = new HashSet<>();
|
||||
|
||||
private Map<String, Set<ClusterBlock>> indices = new HashMap<>();
|
||||
|
||||
|
@ -281,7 +281,7 @@ public class ClusterBlocks extends AbstractDiffable<ClusterBlocks> {
|
|||
global.addAll(blocks.global());
|
||||
for (Map.Entry<String, ImmutableSet<ClusterBlock>> entry : blocks.indices().entrySet()) {
|
||||
if (!indices.containsKey(entry.getKey())) {
|
||||
indices.put(entry.getKey(), Sets.<ClusterBlock>newHashSet());
|
||||
indices.put(entry.getKey(), new HashSet<>());
|
||||
}
|
||||
indices.get(entry.getKey()).addAll(entry.getValue());
|
||||
}
|
||||
|
@ -319,7 +319,7 @@ public class ClusterBlocks extends AbstractDiffable<ClusterBlocks> {
|
|||
|
||||
public Builder addIndexBlock(String index, ClusterBlock block) {
|
||||
if (!indices.containsKey(index)) {
|
||||
indices.put(index, Sets.<ClusterBlock>newHashSet());
|
||||
indices.put(index, new HashSet<>());
|
||||
}
|
||||
indices.get(index).add(block);
|
||||
return this;
|
||||
|
|
|
@ -20,7 +20,6 @@ package org.elasticsearch.cluster.metadata;
|
|||
|
||||
import com.carrotsearch.hppc.cursors.ObjectCursor;
|
||||
import com.carrotsearch.hppc.cursors.ObjectObjectCursor;
|
||||
import com.google.common.collect.Sets;
|
||||
import org.elasticsearch.cluster.AbstractDiffable;
|
||||
import org.elasticsearch.common.collect.ImmutableOpenMap;
|
||||
import org.elasticsearch.common.collect.MapBuilder;
|
||||
|
@ -29,6 +28,7 @@ import org.elasticsearch.common.io.stream.StreamInput;
|
|||
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.settings.loader.SettingsLoader;
|
||||
import org.elasticsearch.common.util.set.Sets;
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
package org.elasticsearch.cluster.metadata;
|
||||
|
||||
import com.carrotsearch.hppc.cursors.ObjectCursor;
|
||||
import com.google.common.collect.Sets;
|
||||
import org.elasticsearch.action.admin.indices.alias.Alias;
|
||||
import org.elasticsearch.action.support.master.MasterNodeRequest;
|
||||
import org.elasticsearch.cluster.ClusterService;
|
||||
|
@ -39,6 +38,7 @@ import org.elasticsearch.indices.InvalidIndexTemplateException;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
@ -76,7 +76,7 @@ public class MetaDataIndexTemplateService extends AbstractComponent {
|
|||
|
||||
@Override
|
||||
public ClusterState execute(ClusterState currentState) {
|
||||
Set<String> templateNames = Sets.newHashSet();
|
||||
Set<String> templateNames = new HashSet<>();
|
||||
for (ObjectCursor<String> cursor : currentState.metaData().templates().keys()) {
|
||||
String templateName = cursor.value;
|
||||
if (Regex.simpleMatch(request.name, templateName)) {
|
||||
|
|
|
@ -20,8 +20,6 @@
|
|||
package org.elasticsearch.cluster.metadata;
|
||||
|
||||
import com.carrotsearch.hppc.cursors.ObjectCursor;
|
||||
import com.google.common.collect.Sets;
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingClusterStateUpdateRequest;
|
||||
import org.elasticsearch.cluster.AckedClusterStateUpdateTask;
|
||||
|
@ -49,6 +47,7 @@ import java.util.ArrayList;
|
|||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
@ -182,7 +181,7 @@ public class MetaDataMappingService extends AbstractComponent {
|
|||
// we need to create the index here, and add the current mapping to it, so we can merge
|
||||
indexService = indicesService.createIndex(indexMetaData.index(), indexMetaData.settings(), currentState.nodes().localNode().id());
|
||||
removeIndex = true;
|
||||
Set<String> typesToIntroduce = Sets.newHashSet();
|
||||
Set<String> typesToIntroduce = new HashSet<>();
|
||||
for (MappingTask task : tasks) {
|
||||
if (task instanceof UpdateTask) {
|
||||
typesToIntroduce.add(((UpdateTask) task).type);
|
||||
|
@ -223,7 +222,7 @@ public class MetaDataMappingService extends AbstractComponent {
|
|||
boolean dirty = false;
|
||||
String index = indexService.index().name();
|
||||
// keep track of what we already refreshed, no need to refresh it again...
|
||||
Set<String> processedRefreshes = Sets.newHashSet();
|
||||
Set<String> processedRefreshes = new HashSet<>();
|
||||
for (MappingTask task : tasks) {
|
||||
if (task instanceof RefreshTask) {
|
||||
RefreshTask refreshTask = (RefreshTask) task;
|
||||
|
|
|
@ -19,13 +19,16 @@
|
|||
|
||||
package org.elasticsearch.cluster.metadata;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsClusterStateUpdateRequest;
|
||||
import org.elasticsearch.action.admin.indices.upgrade.post.UpgradeSettingsClusterStateUpdateRequest;
|
||||
import org.elasticsearch.action.support.IndicesOptions;
|
||||
import org.elasticsearch.cluster.*;
|
||||
import org.elasticsearch.cluster.AckedClusterStateUpdateTask;
|
||||
import org.elasticsearch.cluster.ClusterChangedEvent;
|
||||
import org.elasticsearch.cluster.ClusterService;
|
||||
import org.elasticsearch.cluster.ClusterState;
|
||||
import org.elasticsearch.cluster.ClusterStateListener;
|
||||
import org.elasticsearch.cluster.ack.ClusterStateUpdateResponse;
|
||||
import org.elasticsearch.cluster.block.ClusterBlocks;
|
||||
import org.elasticsearch.cluster.routing.RoutingTable;
|
||||
|
@ -41,7 +44,13 @@ import org.elasticsearch.common.settings.Settings;
|
|||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.index.settings.IndexDynamicSettings;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.elasticsearch.common.settings.Settings.settingsBuilder;
|
||||
|
||||
|
@ -185,8 +194,8 @@ public class MetaDataUpdateSettingsService extends AbstractComponent implements
|
|||
|
||||
final Settings closeSettings = updatedSettingsBuilder.build();
|
||||
|
||||
final Set<String> removedSettings = Sets.newHashSet();
|
||||
final Set<String> errors = Sets.newHashSet();
|
||||
final Set<String> removedSettings = new HashSet<>();
|
||||
final Set<String> errors = new HashSet<>();
|
||||
for (Map.Entry<String, String> setting : updatedSettingsBuilder.internalMap().entrySet()) {
|
||||
if (!dynamicSettings.hasDynamicSetting(setting.getKey())) {
|
||||
removedSettings.add(setting.getKey());
|
||||
|
@ -225,8 +234,8 @@ public class MetaDataUpdateSettingsService extends AbstractComponent implements
|
|||
|
||||
// allow to change any settings to a close index, and only allow dynamic settings to be changed
|
||||
// on an open index
|
||||
Set<String> openIndices = Sets.newHashSet();
|
||||
Set<String> closeIndices = Sets.newHashSet();
|
||||
Set<String> openIndices = new HashSet<>();
|
||||
Set<String> closeIndices = new HashSet<>();
|
||||
for (String index : actualIndices) {
|
||||
if (currentState.metaData().index(index).state() == IndexMetaData.State.OPEN) {
|
||||
openIndices.add(index);
|
||||
|
|
|
@ -22,7 +22,6 @@ package org.elasticsearch.cluster.routing;
|
|||
import com.carrotsearch.hppc.IntSet;
|
||||
import com.carrotsearch.hppc.cursors.IntCursor;
|
||||
import com.carrotsearch.hppc.cursors.IntObjectCursor;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.common.collect.UnmodifiableIterator;
|
||||
import org.apache.lucene.util.CollectionUtil;
|
||||
import org.elasticsearch.cluster.AbstractDiffable;
|
||||
|
@ -37,6 +36,7 @@ import java.io.IOException;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
@ -137,7 +137,7 @@ public class IndexRoutingTable extends AbstractDiffable<IndexRoutingTable> imple
|
|||
|
||||
// check the number of shards
|
||||
if (indexMetaData.numberOfShards() != shards().size()) {
|
||||
Set<Integer> expected = Sets.newHashSet();
|
||||
Set<Integer> expected = new HashSet<>();
|
||||
for (int i = 0; i < indexMetaData.numberOfShards(); i++) {
|
||||
expected.add(i);
|
||||
}
|
||||
|
@ -176,7 +176,7 @@ public class IndexRoutingTable extends AbstractDiffable<IndexRoutingTable> imple
|
|||
* @return number of distinct nodes this index has at least one shard allocated on
|
||||
*/
|
||||
public int numberOfNodesShardsAreAllocatedOn(String... excludedNodes) {
|
||||
Set<String> nodes = Sets.newHashSet();
|
||||
Set<String> nodes = new HashSet<>();
|
||||
for (IndexShardRoutingTable shardRoutingTable : this) {
|
||||
for (ShardRouting shardRouting : shardRoutingTable) {
|
||||
if (shardRouting.assignedToNode()) {
|
||||
|
|
|
@ -20,12 +20,12 @@
|
|||
package org.elasticsearch.cluster.routing;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Sets;
|
||||
import org.elasticsearch.cluster.node.DiscoveryNode;
|
||||
import org.elasticsearch.cluster.node.DiscoveryNodes;
|
||||
import org.elasticsearch.common.collect.MapBuilder;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||
import org.elasticsearch.common.util.set.Sets;
|
||||
import org.elasticsearch.index.shard.ShardId;
|
||||
|
||||
import java.io.IOException;
|
||||
|
|
|
@ -35,14 +35,13 @@ import java.util.ArrayList;
|
|||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import static com.google.common.collect.Sets.newHashSet;
|
||||
|
||||
/**
|
||||
* {@link RoutingNodes} represents a copy the routing information contained in
|
||||
* the {@link ClusterState cluster state}.
|
||||
|
@ -704,7 +703,7 @@ public class RoutingNodes implements Iterable<RoutingNode> {
|
|||
int inactivePrimaryCount = 0;
|
||||
int inactiveShardCount = 0;
|
||||
int relocating = 0;
|
||||
final Set<ShardId> seenShards = newHashSet();
|
||||
final Set<ShardId> seenShards = new HashSet<>();
|
||||
Map<String, Integer> indicesAndShards = new HashMap<>();
|
||||
for (RoutingNode node : routingNodes) {
|
||||
for (ShardRouting shard : node) {
|
||||
|
|
|
@ -188,7 +188,7 @@ public class AwarenessAllocationDecider extends AllocationDecider {
|
|||
if (assignedShard.relocating()) {
|
||||
RoutingNode relocationNode = allocation.routingNodes().node(assignedShard.relocatingNodeId());
|
||||
shardPerAttribute.addTo(relocationNode.node().attributes().get(awarenessAttribute), 1);
|
||||
} else if (assignedShard.started()) {
|
||||
} else if (assignedShard.started() || assignedShard.initializing()) {
|
||||
RoutingNode routingNode = allocation.routingNodes().node(assignedShard.currentNodeId());
|
||||
shardPerAttribute.addTo(routingNode.node().attributes().get(awarenessAttribute), 1);
|
||||
}
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
|
||||
package org.elasticsearch.cluster.routing.allocation.decider;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import org.elasticsearch.ElasticsearchParseException;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.cluster.ClusterInfo;
|
||||
|
@ -36,6 +35,7 @@ import org.elasticsearch.common.settings.Settings;
|
|||
import org.elasticsearch.common.unit.ByteSizeValue;
|
||||
import org.elasticsearch.common.unit.RatioValue;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.common.util.set.Sets;
|
||||
import org.elasticsearch.node.settings.NodeSettingsService;
|
||||
|
||||
import java.util.Map;
|
||||
|
|
|
@ -19,11 +19,16 @@
|
|||
|
||||
package org.elasticsearch.common.geo.builders;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import com.spatial4j.core.exception.InvalidShapeException;
|
||||
import com.spatial4j.core.shape.Shape;
|
||||
import com.vividsolutions.jts.geom.*;
|
||||
import com.vividsolutions.jts.geom.Coordinate;
|
||||
import com.vividsolutions.jts.geom.Geometry;
|
||||
import com.vividsolutions.jts.geom.GeometryFactory;
|
||||
import com.vividsolutions.jts.geom.LinearRing;
|
||||
import com.vividsolutions.jts.geom.MultiPolygon;
|
||||
import com.vividsolutions.jts.geom.Polygon;
|
||||
import org.elasticsearch.common.collect.Tuple;
|
||||
import org.elasticsearch.common.util.set.Sets;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
|
||||
import java.io.IOException;
|
||||
|
|
|
@ -25,8 +25,8 @@ import org.elasticsearch.common.inject.spi.TypeConverter;
|
|||
import org.elasticsearch.common.inject.spi.TypeListener;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.util.Objects;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
|
||||
/**
|
||||
|
@ -56,7 +56,7 @@ public abstract class AbstractModule implements Module {
|
|||
public final synchronized void configure(Binder builder) {
|
||||
checkState(this.binder == null, "Re-entry is not allowed.");
|
||||
|
||||
this.binder = checkNotNull(builder, "builder");
|
||||
this.binder = Objects.requireNonNull(builder, "builder");
|
||||
try {
|
||||
configure();
|
||||
} finally {
|
||||
|
|
|
@ -33,8 +33,7 @@ import java.util.HashMap;
|
|||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @author jessewilson@google.com (Jesse Wilson)
|
||||
|
@ -54,7 +53,7 @@ class InheritingState implements State {
|
|||
private final Object lock;
|
||||
|
||||
InheritingState(State parent) {
|
||||
this.parent = checkNotNull(parent, "parent");
|
||||
this.parent = Objects.requireNonNull(parent, "parent");
|
||||
this.lock = (parent == State.NONE) ? this : parent.lock();
|
||||
}
|
||||
|
||||
|
|
|
@ -23,11 +23,10 @@ import org.elasticsearch.common.inject.spi.InjectionPoint;
|
|||
import java.util.ArrayList;
|
||||
import java.util.IdentityHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* Manages and injects instances at injector-creation time. This is made more complicated by
|
||||
* instances that request other instances while they're being injected. We overcome this by using
|
||||
|
@ -60,7 +59,7 @@ class Initializer {
|
|||
*/
|
||||
public <T> Initializable<T> requestInjection(InjectorImpl injector, T instance, Object source,
|
||||
Set<InjectionPoint> injectionPoints) {
|
||||
checkNotNull(source);
|
||||
Objects.requireNonNull(source);
|
||||
|
||||
// short circuit if the object has no injections
|
||||
if (instance == null
|
||||
|
@ -118,8 +117,8 @@ class Initializer {
|
|||
|
||||
public InjectableReference(InjectorImpl injector, T instance, Object source) {
|
||||
this.injector = injector;
|
||||
this.instance = checkNotNull(instance, "instance");
|
||||
this.source = checkNotNull(source, "source");
|
||||
this.instance = Objects.requireNonNull(instance, "instance");
|
||||
this.source = Objects.requireNonNull(source, "source");
|
||||
}
|
||||
|
||||
public void validate(Errors errors) throws ErrorsException {
|
||||
|
|
|
@ -35,9 +35,9 @@ import org.elasticsearch.common.inject.spi.TypeListenerBinding;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
import static org.elasticsearch.common.inject.Scopes.SINGLETON;
|
||||
|
||||
|
@ -257,7 +257,7 @@ class InjectorShell {
|
|||
final Stage stage;
|
||||
|
||||
private RootModule(Stage stage) {
|
||||
this.stage = checkNotNull(stage, "stage");
|
||||
this.stage = Objects.requireNonNull(stage, "stage");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -19,12 +19,12 @@
|
|||
|
||||
package org.elasticsearch.common.inject;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import org.elasticsearch.common.inject.matcher.Matcher;
|
||||
import org.elasticsearch.common.inject.name.Names;
|
||||
import org.elasticsearch.common.inject.spi.Message;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
@ -69,7 +69,7 @@ public class Injectors {
|
|||
* @return a set of objects returned from this injector
|
||||
*/
|
||||
public static <T> Set<T> getInstancesOf(Injector injector, Class<T> baseClass) {
|
||||
Set<T> answer = Sets.newHashSet();
|
||||
Set<T> answer = new HashSet<>();
|
||||
Set<Entry<Key<?>, Binding<?>>> entries = injector.getBindings().entrySet();
|
||||
for (Entry<Key<?>, Binding<?>> entry : entries) {
|
||||
Key<?> key = entry.getKey();
|
||||
|
@ -93,7 +93,7 @@ public class Injectors {
|
|||
* @return a set of objects returned from this injector
|
||||
*/
|
||||
public static <T> Set<T> getInstancesOf(Injector injector, Matcher<Class> matcher) {
|
||||
Set<T> answer = Sets.newHashSet();
|
||||
Set<T> answer = new HashSet<>();
|
||||
Set<Entry<Key<?>, Binding<?>>> entries = injector.getBindings().entrySet();
|
||||
for (Entry<Key<?>, Binding<?>> entry : entries) {
|
||||
Key<?> key = entry.getKey();
|
||||
|
@ -114,7 +114,7 @@ public class Injectors {
|
|||
* @return a set of objects returned from this injector
|
||||
*/
|
||||
public static <T> Set<Provider<T>> getProvidersOf(Injector injector, Matcher<Class> matcher) {
|
||||
Set<Provider<T>> answer = Sets.newHashSet();
|
||||
Set<Provider<T>> answer = new HashSet<>();
|
||||
Set<Entry<Key<?>, Binding<?>>> entries = injector.getBindings().entrySet();
|
||||
for (Entry<Key<?>, Binding<?>> entry : entries) {
|
||||
Key<?> key = entry.getKey();
|
||||
|
@ -135,7 +135,7 @@ public class Injectors {
|
|||
* @return a set of objects returned from this injector
|
||||
*/
|
||||
public static <T> Set<Provider<T>> getProvidersOf(Injector injector, Class<T> baseClass) {
|
||||
Set<Provider<T>> answer = Sets.newHashSet();
|
||||
Set<Provider<T>> answer = new HashSet<>();
|
||||
Set<Entry<Key<?>, Binding<?>>> entries = injector.getBindings().entrySet();
|
||||
for (Entry<Key<?>, Binding<?>> entry : entries) {
|
||||
Key<?> key = entry.getKey();
|
||||
|
@ -186,7 +186,7 @@ public class Injectors {
|
|||
* @return a set of objects returned from this injector
|
||||
*/
|
||||
public static Set<Binding<?>> getBindingsOf(Injector injector, Matcher<Class> matcher) {
|
||||
Set<Binding<?>> answer = Sets.newHashSet();
|
||||
Set<Binding<?>> answer = new HashSet<>();
|
||||
Set<Entry<Key<?>, Binding<?>>> entries = injector.getBindings().entrySet();
|
||||
for (Entry<Key<?>, Binding<?>> entry : entries) {
|
||||
Key<?> key = entry.getKey();
|
||||
|
@ -205,7 +205,7 @@ public class Injectors {
|
|||
* @return a set of objects returned from this injector
|
||||
*/
|
||||
public static Set<Binding<?>> getBindingsOf(Injector injector, Class<?> baseClass) {
|
||||
Set<Binding<?>> answer = Sets.newHashSet();
|
||||
Set<Binding<?>> answer = new HashSet<>();
|
||||
Set<Entry<Key<?>, Binding<?>>> entries = injector.getBindings().entrySet();
|
||||
for (Entry<Key<?>, Binding<?>> entry : entries) {
|
||||
Key<?> key = entry.getKey();
|
||||
|
|
|
@ -19,7 +19,7 @@ package org.elasticsearch.common.inject;
|
|||
import org.elasticsearch.common.inject.internal.*;
|
||||
import org.elasticsearch.common.inject.spi.Dependency;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @author crazybob@google.com (Bob Lee)
|
||||
|
@ -35,8 +35,8 @@ class InternalFactoryToProviderAdapter<T> implements InternalFactory<T> {
|
|||
|
||||
public InternalFactoryToProviderAdapter(
|
||||
Initializable<Provider<? extends T>> initializable, Object source) {
|
||||
this.initializable = checkNotNull(initializable, "provider");
|
||||
this.source = checkNotNull(source, "source");
|
||||
this.initializable = Objects.requireNonNull(initializable, "provider");
|
||||
this.source = Objects.requireNonNull(source, "source");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -22,9 +22,9 @@ import org.elasticsearch.common.inject.internal.ToStringBuilder;
|
|||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Objects;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* Binding key consisting of an injection type and an optional annotation.
|
||||
|
@ -343,7 +343,7 @@ public class Key<T> {
|
|||
* Gets the strategy for an annotation.
|
||||
*/
|
||||
static AnnotationStrategy strategyFor(Annotation annotation) {
|
||||
checkNotNull(annotation, "annotation");
|
||||
Objects.requireNonNull(annotation, "annotation");
|
||||
Class<? extends Annotation> annotationType = annotation.annotationType();
|
||||
ensureRetainedAtRuntime(annotationType);
|
||||
ensureIsBindingAnnotation(annotationType);
|
||||
|
@ -359,7 +359,7 @@ public class Key<T> {
|
|||
* Gets the strategy for an annotation type.
|
||||
*/
|
||||
static AnnotationStrategy strategyFor(Class<? extends Annotation> annotationType) {
|
||||
checkNotNull(annotationType, "annotation type");
|
||||
Objects.requireNonNull(annotationType, "annotation type");
|
||||
ensureRetainedAtRuntime(annotationType);
|
||||
ensureIsBindingAnnotation(annotationType);
|
||||
return new AnnotationTypeStrategy(annotationType, null);
|
||||
|
@ -414,7 +414,7 @@ public class Key<T> {
|
|||
final Annotation annotation;
|
||||
|
||||
AnnotationInstanceStrategy(Annotation annotation) {
|
||||
this.annotation = checkNotNull(annotation, "annotation");
|
||||
this.annotation = Objects.requireNonNull(annotation, "annotation");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -467,7 +467,7 @@ public class Key<T> {
|
|||
|
||||
AnnotationTypeStrategy(Class<? extends Annotation> annotationType,
|
||||
Annotation annotation) {
|
||||
this.annotationType = checkNotNull(annotationType, "annotation type");
|
||||
this.annotationType = Objects.requireNonNull(annotationType, "annotation type");
|
||||
this.annotation = annotation;
|
||||
}
|
||||
|
||||
|
|
|
@ -21,8 +21,7 @@ import org.elasticsearch.common.inject.internal.Errors;
|
|||
import org.elasticsearch.common.inject.spi.ScopeBinding;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Handles {@link Binder#bindScope} commands.
|
||||
|
@ -52,11 +51,11 @@ class ScopeBindingProcessor extends AbstractProcessor {
|
|||
// Go ahead and bind anyway so we don't get collateral errors.
|
||||
}
|
||||
|
||||
Scope existing = injector.state.getScope(checkNotNull(annotationType, "annotation type"));
|
||||
Scope existing = injector.state.getScope(Objects.requireNonNull(annotationType, "annotation type"));
|
||||
if (existing != null) {
|
||||
errors.duplicateScopes(existing, annotationType, scope);
|
||||
} else {
|
||||
injector.state.putAnnotation(annotationType, checkNotNull(scope, "scope"));
|
||||
injector.state.putAnnotation(annotationType, Objects.requireNonNull(scope, "scope"));
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
|
@ -21,11 +21,10 @@ import org.elasticsearch.common.inject.util.Types;
|
|||
|
||||
import java.lang.reflect.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static org.elasticsearch.common.inject.internal.MoreTypes.canonicalize;
|
||||
|
||||
/**
|
||||
|
@ -85,7 +84,7 @@ public class TypeLiteral<T> {
|
|||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
TypeLiteral(Type type) {
|
||||
this.type = canonicalize(checkNotNull(type, "type"));
|
||||
this.type = canonicalize(Objects.requireNonNull(type, "type"));
|
||||
this.rawType = (Class<? super T>) MoreTypes.getRawType(this.type);
|
||||
this.hashCode = MoreTypes.hashCode(this.type);
|
||||
}
|
||||
|
|
|
@ -16,8 +16,7 @@
|
|||
|
||||
package org.elasticsearch.common.inject;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
|
@ -34,7 +33,7 @@ final class WeakKeySet {
|
|||
* keys whose class names are equal but class loaders are different. This shouldn't be an issue
|
||||
* in practice.
|
||||
*/
|
||||
private Set<String> backingSet = Sets.newHashSet();
|
||||
private Set<String> backingSet = new HashSet<>();
|
||||
|
||||
public boolean add(Key<?> key) {
|
||||
return backingSet.add(key.toString());
|
||||
|
|
|
@ -24,8 +24,7 @@ import org.elasticsearch.common.inject.spi.InstanceBinding;
|
|||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.util.List;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Bind a value or constant.
|
||||
|
@ -73,7 +72,7 @@ public abstract class AbstractBindingBuilder<T> {
|
|||
* Sets the binding to a copy with the specified annotation on the bound key
|
||||
*/
|
||||
protected BindingImpl<T> annotatedWithInternal(Class<? extends Annotation> annotationType) {
|
||||
checkNotNull(annotationType, "annotationType");
|
||||
Objects.requireNonNull(annotationType, "annotationType");
|
||||
checkNotAnnotated();
|
||||
return setBinding(binding.withKey(
|
||||
Key.get(this.binding.getKey().getTypeLiteral(), annotationType)));
|
||||
|
@ -83,20 +82,20 @@ public abstract class AbstractBindingBuilder<T> {
|
|||
* Sets the binding to a copy with the specified annotation on the bound key
|
||||
*/
|
||||
protected BindingImpl<T> annotatedWithInternal(Annotation annotation) {
|
||||
checkNotNull(annotation, "annotation");
|
||||
Objects.requireNonNull(annotation, "annotation");
|
||||
checkNotAnnotated();
|
||||
return setBinding(binding.withKey(
|
||||
Key.get(this.binding.getKey().getTypeLiteral(), annotation)));
|
||||
}
|
||||
|
||||
public void in(final Class<? extends Annotation> scopeAnnotation) {
|
||||
checkNotNull(scopeAnnotation, "scopeAnnotation");
|
||||
Objects.requireNonNull(scopeAnnotation, "scopeAnnotation");
|
||||
checkNotScoped();
|
||||
setBinding(getBinding().withScoping(Scoping.forAnnotation(scopeAnnotation)));
|
||||
}
|
||||
|
||||
public void in(final Scope scope) {
|
||||
checkNotNull(scope, "scope");
|
||||
Objects.requireNonNull(scope, "scope");
|
||||
checkNotScoped();
|
||||
setBinding(getBinding().withScoping(Scoping.forInstance(scope)));
|
||||
}
|
||||
|
|
|
@ -25,10 +25,9 @@ import org.elasticsearch.common.inject.spi.Message;
|
|||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* Bind a non-constant key.
|
||||
*
|
||||
|
@ -65,7 +64,7 @@ public class BindingBuilder<T> extends AbstractBindingBuilder<T>
|
|||
|
||||
@Override
|
||||
public BindingBuilder<T> to(Key<? extends T> linkedKey) {
|
||||
checkNotNull(linkedKey, "linkedKey");
|
||||
Objects.requireNonNull(linkedKey, "linkedKey");
|
||||
checkNotTargetted();
|
||||
BindingImpl<T> base = getBinding();
|
||||
setBinding(new LinkedBindingImpl<>(
|
||||
|
@ -100,7 +99,7 @@ public class BindingBuilder<T> extends AbstractBindingBuilder<T>
|
|||
|
||||
@Override
|
||||
public BindingBuilder<T> toProvider(Provider<? extends T> provider) {
|
||||
checkNotNull(provider, "provider");
|
||||
Objects.requireNonNull(provider, "provider");
|
||||
checkNotTargetted();
|
||||
|
||||
// lookup the injection points, adding any errors to the binder's errors list
|
||||
|
@ -127,7 +126,7 @@ public class BindingBuilder<T> extends AbstractBindingBuilder<T>
|
|||
|
||||
@Override
|
||||
public BindingBuilder<T> toProvider(Key<? extends Provider<? extends T>> providerKey) {
|
||||
checkNotNull(providerKey, "providerKey");
|
||||
Objects.requireNonNull(providerKey, "providerKey");
|
||||
checkNotTargetted();
|
||||
|
||||
BindingImpl<T> base = getBinding();
|
||||
|
|
|
@ -21,6 +21,7 @@ import org.elasticsearch.common.inject.Key;
|
|||
import org.elasticsearch.common.inject.binder.AnnotatedElementBuilder;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* For private binder's expose() method.
|
||||
|
@ -44,14 +45,14 @@ public class ExposureBuilder<T> implements AnnotatedElementBuilder {
|
|||
|
||||
@Override
|
||||
public void annotatedWith(Class<? extends Annotation> annotationType) {
|
||||
com.google.common.base.Preconditions.checkNotNull(annotationType, "annotationType");
|
||||
Objects.requireNonNull(annotationType, "annotationType");
|
||||
checkNotAnnotated();
|
||||
key = Key.get(key.getTypeLiteral(), annotationType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void annotatedWith(Annotation annotation) {
|
||||
com.google.common.base.Preconditions.checkNotNull(annotation, "annotation");
|
||||
Objects.requireNonNull(annotation, "annotation");
|
||||
checkNotAnnotated();
|
||||
key = Key.get(key.getTypeLiteral(), annotation);
|
||||
}
|
||||
|
|
|
@ -22,8 +22,7 @@ import java.io.IOException;
|
|||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Utility for joining pieces of text separated by a delimiter. It can handle
|
||||
|
@ -97,7 +96,7 @@ public final class Join {
|
|||
*/
|
||||
public static String join(
|
||||
String delimiter, @Nullable Object firstToken, Object... otherTokens) {
|
||||
checkNotNull(otherTokens);
|
||||
Objects.requireNonNull(otherTokens);
|
||||
return join(delimiter, CollectionUtils.asArrayList(firstToken, otherTokens));
|
||||
}
|
||||
|
||||
|
@ -207,7 +206,7 @@ public final class Join {
|
|||
*/
|
||||
public static <T extends Appendable> T join(T appendable, String delimiter,
|
||||
@Nullable Object firstToken, Object... otherTokens) {
|
||||
checkNotNull(otherTokens);
|
||||
Objects.requireNonNull(otherTokens);
|
||||
return join(appendable, delimiter, CollectionUtils.asArrayList(firstToken, otherTokens));
|
||||
}
|
||||
|
||||
|
@ -232,8 +231,8 @@ public final class Join {
|
|||
|
||||
/* This method is the workhorse of the class */
|
||||
|
||||
checkNotNull(appendable);
|
||||
checkNotNull(delimiter);
|
||||
Objects.requireNonNull(appendable);
|
||||
Objects.requireNonNull(delimiter);
|
||||
if (tokens.hasNext()) {
|
||||
try {
|
||||
appendOneToken(appendable, tokens.next());
|
||||
|
@ -268,9 +267,9 @@ public final class Join {
|
|||
*/
|
||||
public static <T extends Appendable> T join(T appendable,
|
||||
String keyValueSeparator, String entryDelimiter, Map<?, ?> map) {
|
||||
checkNotNull(appendable);
|
||||
checkNotNull(keyValueSeparator);
|
||||
checkNotNull(entryDelimiter);
|
||||
Objects.requireNonNull(appendable);
|
||||
Objects.requireNonNull(keyValueSeparator);
|
||||
Objects.requireNonNull(entryDelimiter);
|
||||
Iterator<? extends Map.Entry<?, ?>> entries = map.entrySet().iterator();
|
||||
if (entries.hasNext()) {
|
||||
try {
|
||||
|
|
|
@ -20,7 +20,7 @@ import org.elasticsearch.common.inject.TypeLiteral;
|
|||
import org.elasticsearch.common.inject.matcher.Matcher;
|
||||
import org.elasticsearch.common.inject.spi.TypeConverter;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @author crazybob@google.com (Bob Lee)
|
||||
|
@ -33,8 +33,8 @@ public final class MatcherAndConverter {
|
|||
|
||||
public MatcherAndConverter(Matcher<? super TypeLiteral<?>> typeMatcher,
|
||||
TypeConverter typeConverter, Object source) {
|
||||
this.typeMatcher = checkNotNull(typeMatcher, "type matcher");
|
||||
this.typeConverter = checkNotNull(typeConverter, "converter");
|
||||
this.typeMatcher = Objects.requireNonNull(typeMatcher, "type matcher");
|
||||
this.typeConverter = Objects.requireNonNull(typeConverter, "converter");
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
|
|
|
@ -31,7 +31,6 @@ import java.util.NoSuchElementException;
|
|||
import java.util.Objects;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* Static methods for working with types that we aren't publishing in the
|
||||
|
@ -316,7 +315,7 @@ public class MoreTypes {
|
|||
* Returns {@code Field.class}, {@code Method.class} or {@code Constructor.class}.
|
||||
*/
|
||||
public static Class<? extends Member> memberType(Member member) {
|
||||
checkNotNull(member, "member");
|
||||
Objects.requireNonNull(member, "member");
|
||||
|
||||
if (member instanceof MemberImpl) {
|
||||
return ((MemberImpl) member).memberType;
|
||||
|
@ -355,7 +354,7 @@ public class MoreTypes {
|
|||
}
|
||||
|
||||
public static String memberKey(Member member) {
|
||||
checkNotNull(member, "member");
|
||||
Objects.requireNonNull(member, "member");
|
||||
|
||||
return "<NO_MEMBER_KEY>";
|
||||
}
|
||||
|
@ -456,7 +455,7 @@ public class MoreTypes {
|
|||
this.rawType = canonicalize(rawType);
|
||||
this.typeArguments = typeArguments.clone();
|
||||
for (int t = 0; t < this.typeArguments.length; t++) {
|
||||
checkNotNull(this.typeArguments[t], "type parameter");
|
||||
Objects.requireNonNull(this.typeArguments[t], "type parameter");
|
||||
checkNotPrimitive(this.typeArguments[t], "type parameters");
|
||||
this.typeArguments[t] = canonicalize(this.typeArguments[t]);
|
||||
}
|
||||
|
@ -566,14 +565,14 @@ public class MoreTypes {
|
|||
checkArgument(upperBounds.length == 1, "Must have exactly one upper bound.");
|
||||
|
||||
if (lowerBounds.length == 1) {
|
||||
checkNotNull(lowerBounds[0], "lowerBound");
|
||||
Objects.requireNonNull(lowerBounds[0], "lowerBound");
|
||||
checkNotPrimitive(lowerBounds[0], "wildcard bounds");
|
||||
checkArgument(upperBounds[0] == Object.class, "bounded both ways");
|
||||
this.lowerBound = canonicalize(lowerBounds[0]);
|
||||
this.upperBound = Object.class;
|
||||
|
||||
} else {
|
||||
checkNotNull(upperBounds[0], "upperBound");
|
||||
Objects.requireNonNull(upperBounds[0], "upperBound");
|
||||
checkNotPrimitive(upperBounds[0], "wildcard bounds");
|
||||
this.lowerBound = null;
|
||||
this.upperBound = canonicalize(upperBounds[0]);
|
||||
|
|
|
@ -30,10 +30,10 @@ 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.checkNotNull;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
|
||||
/**
|
||||
|
@ -64,7 +64,7 @@ public final class PrivateElementsImpl implements PrivateElements {
|
|||
private Injector injector;
|
||||
|
||||
public PrivateElementsImpl(Object source) {
|
||||
this.source = checkNotNull(source, "source");
|
||||
this.source = Objects.requireNonNull(source, "source");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -89,7 +89,7 @@ public final class PrivateElementsImpl implements PrivateElements {
|
|||
|
||||
public void initInjector(Injector injector) {
|
||||
checkState(this.injector == null, "injector already initialized");
|
||||
this.injector = checkNotNull(injector, "injector");
|
||||
this.injector = Objects.requireNonNull(injector, "injector");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -32,8 +32,7 @@ import java.lang.reflect.Member;
|
|||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Creates bindings to methods annotated with {@literal @}{@link Provides}. Use the scope and
|
||||
|
@ -47,7 +46,7 @@ public final class ProviderMethodsModule implements Module {
|
|||
private final TypeLiteral<?> typeLiteral;
|
||||
|
||||
private ProviderMethodsModule(Object delegate) {
|
||||
this.delegate = checkNotNull(delegate, "delegate");
|
||||
this.delegate = Objects.requireNonNull(delegate, "delegate");
|
||||
this.typeLiteral = TypeLiteral.get(this.delegate.getClass());
|
||||
}
|
||||
|
||||
|
|
|
@ -22,9 +22,9 @@ import java.lang.annotation.Retention;
|
|||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.reflect.AnnotatedElement;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Objects;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* Matcher implementations. Supports matching classes and methods.
|
||||
|
@ -73,7 +73,7 @@ public class Matchers {
|
|||
final Matcher<? super T> delegate;
|
||||
|
||||
private Not(Matcher<? super T> delegate) {
|
||||
this.delegate = checkNotNull(delegate, "delegate");
|
||||
this.delegate = Objects.requireNonNull(delegate, "delegate");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -121,7 +121,7 @@ public class Matchers {
|
|||
private final Class<? extends Annotation> annotationType;
|
||||
|
||||
public AnnotatedWithType(Class<? extends Annotation> annotationType) {
|
||||
this.annotationType = checkNotNull(annotationType, "annotation type");
|
||||
this.annotationType = Objects.requireNonNull(annotationType, "annotation type");
|
||||
checkForRuntimeRetention(annotationType);
|
||||
}
|
||||
|
||||
|
@ -163,7 +163,7 @@ public class Matchers {
|
|||
private final Annotation annotation;
|
||||
|
||||
public AnnotatedWith(Annotation annotation) {
|
||||
this.annotation = checkNotNull(annotation, "annotation");
|
||||
this.annotation = Objects.requireNonNull(annotation, "annotation");
|
||||
checkForRuntimeRetention(annotation.annotationType());
|
||||
}
|
||||
|
||||
|
@ -205,7 +205,7 @@ public class Matchers {
|
|||
private final Class<?> superclass;
|
||||
|
||||
public SubclassesOf(Class<?> superclass) {
|
||||
this.superclass = checkNotNull(superclass, "superclass");
|
||||
this.superclass = Objects.requireNonNull(superclass, "superclass");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -244,7 +244,7 @@ public class Matchers {
|
|||
private final Object value;
|
||||
|
||||
public Only(Object value) {
|
||||
this.value = checkNotNull(value, "value");
|
||||
this.value = Objects.requireNonNull(value, "value");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -283,7 +283,7 @@ public class Matchers {
|
|||
private final Object value;
|
||||
|
||||
public IdenticalTo(Object value) {
|
||||
this.value = checkNotNull(value, "value");
|
||||
this.value = Objects.requireNonNull(value, "value");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -323,7 +323,7 @@ public class Matchers {
|
|||
private final String packageName;
|
||||
|
||||
public InPackage(Package targetPackage) {
|
||||
this.targetPackage = checkNotNull(targetPackage, "package");
|
||||
this.targetPackage = Objects.requireNonNull(targetPackage, "package");
|
||||
this.packageName = targetPackage.getName();
|
||||
}
|
||||
|
||||
|
@ -410,7 +410,7 @@ public class Matchers {
|
|||
private final Matcher<? super Class<?>> returnType;
|
||||
|
||||
public Returns(Matcher<? super Class<?>> returnType) {
|
||||
this.returnType = checkNotNull(returnType, "return type matcher");
|
||||
this.returnType = Objects.requireNonNull(returnType, "return type matcher");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -39,6 +39,7 @@ import java.util.ArrayList;
|
|||
import java.util.Collections;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
|
@ -208,10 +209,10 @@ public abstract class Multibinder<T> {
|
|||
|
||||
private RealMultibinder(Binder binder, TypeLiteral<T> elementType,
|
||||
String setName, Key<Set<T>> setKey) {
|
||||
this.binder = checkNotNull(binder, "binder");
|
||||
this.elementType = checkNotNull(elementType, "elementType");
|
||||
this.setName = checkNotNull(setName, "setName");
|
||||
this.setKey = checkNotNull(setKey, "setKey");
|
||||
this.binder = Objects.requireNonNull(binder, "binder");
|
||||
this.elementType = Objects.requireNonNull(elementType, "elementType");
|
||||
this.setName = Objects.requireNonNull(setName, "setName");
|
||||
this.setKey = Objects.requireNonNull(setKey, "setKey");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -18,15 +18,14 @@ package org.elasticsearch.common.inject.name;
|
|||
|
||||
import java.io.Serializable;
|
||||
import java.lang.annotation.Annotation;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import java.util.Objects;
|
||||
|
||||
class NamedImpl implements Named, Serializable {
|
||||
|
||||
private final String value;
|
||||
|
||||
public NamedImpl(String value) {
|
||||
this.value = checkNotNull(value, "name");
|
||||
this.value = Objects.requireNonNull(value, "name");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
|
||||
package org.elasticsearch.common.inject.spi;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import org.elasticsearch.common.inject.AbstractModule;
|
||||
import org.elasticsearch.common.inject.Binder;
|
||||
import org.elasticsearch.common.inject.Binding;
|
||||
|
@ -49,6 +48,7 @@ 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;
|
||||
|
||||
|
@ -141,7 +141,7 @@ public final class Elements {
|
|||
|
||||
private RecordingBinder(Stage stage) {
|
||||
this.stage = stage;
|
||||
this.modules = Sets.newHashSet();
|
||||
this.modules = new HashSet<>();
|
||||
this.elements = new ArrayList<>();
|
||||
this.source = null;
|
||||
this.sourceProvider = new SourceProvider().plusSkippedClasses(
|
||||
|
@ -172,7 +172,7 @@ public final class Elements {
|
|||
*/
|
||||
private RecordingBinder(RecordingBinder parent, PrivateElementsImpl privateElements) {
|
||||
this.stage = parent.stage;
|
||||
this.modules = Sets.newHashSet();
|
||||
this.modules = new HashSet<>();
|
||||
this.elements = privateElements.getElementsMutable();
|
||||
this.source = parent.source;
|
||||
this.sourceProvider = parent.sourceProvider;
|
||||
|
|
|
@ -20,10 +20,9 @@ import org.elasticsearch.common.inject.Binder;
|
|||
import org.elasticsearch.common.inject.ConfigurationException;
|
||||
import org.elasticsearch.common.inject.TypeLiteral;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* A request to inject the instance fields and methods of an instance. Requests are created
|
||||
* explicitly in a module using {@link org.elasticsearch.common.inject.Binder#requestInjection(Object)
|
||||
|
@ -41,9 +40,9 @@ public final class InjectionRequest<T> implements Element {
|
|||
private final T instance;
|
||||
|
||||
public InjectionRequest(Object source, TypeLiteral<T> type, T instance) {
|
||||
this.source = checkNotNull(source, "source");
|
||||
this.type = checkNotNull(type, "type");
|
||||
this.instance = checkNotNull(instance, "instance");
|
||||
this.source = Objects.requireNonNull(source, "source");
|
||||
this.type = Objects.requireNonNull(type, "type");
|
||||
this.instance = Objects.requireNonNull(instance, "instance");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -20,7 +20,8 @@ import org.elasticsearch.common.inject.Binder;
|
|||
import org.elasticsearch.common.inject.MembersInjector;
|
||||
import org.elasticsearch.common.inject.TypeLiteral;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import java.util.Objects;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
|
||||
/**
|
||||
|
@ -40,8 +41,8 @@ public final class MembersInjectorLookup<T> implements Element {
|
|||
private MembersInjector<T> delegate;
|
||||
|
||||
public MembersInjectorLookup(Object source, TypeLiteral<T> type) {
|
||||
this.source = checkNotNull(source, "source");
|
||||
this.type = checkNotNull(type, "type");
|
||||
this.source = Objects.requireNonNull(source, "source");
|
||||
this.type = Objects.requireNonNull(type, "type");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -68,7 +69,7 @@ public final class MembersInjectorLookup<T> implements Element {
|
|||
*/
|
||||
public void initializeDelegate(MembersInjector<T> delegate) {
|
||||
checkState(this.delegate == null, "delegate already initialized");
|
||||
this.delegate = checkNotNull(delegate, "delegate");
|
||||
this.delegate = Objects.requireNonNull(delegate, "delegate");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -27,8 +27,6 @@ import java.util.Collections;
|
|||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* An error message and the context in which it occurred. Messages are usually created internally by
|
||||
* Guice and its extensions. Messages can be created explicitly in a module using {@link
|
||||
|
@ -52,7 +50,7 @@ public final class Message implements Serializable, Element {
|
|||
*/
|
||||
public Message(List<Object> sources, String message, Throwable cause) {
|
||||
this.sources = Collections.unmodifiableList(sources);
|
||||
this.message = checkNotNull(message, "message");
|
||||
this.message = Objects.requireNonNull(message, "message");
|
||||
this.cause = cause;
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,8 @@ import org.elasticsearch.common.inject.Binder;
|
|||
import org.elasticsearch.common.inject.Key;
|
||||
import org.elasticsearch.common.inject.Provider;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import java.util.Objects;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
|
||||
/**
|
||||
|
@ -64,8 +65,8 @@ public final class ProviderLookup<T> implements Element {
|
|||
private Provider<T> delegate;
|
||||
|
||||
public ProviderLookup(Object source, Key<T> key) {
|
||||
this.source = checkNotNull(source, "source");
|
||||
this.key = checkNotNull(key, "key");
|
||||
this.source = Objects.requireNonNull(source, "source");
|
||||
this.key = Objects.requireNonNull(key, "key");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -89,7 +90,7 @@ public final class ProviderLookup<T> implements Element {
|
|||
*/
|
||||
public void initializeDelegate(Provider<T> delegate) {
|
||||
checkState(this.delegate == null, "delegate already initialized");
|
||||
this.delegate = checkNotNull(delegate, "delegate");
|
||||
this.delegate = Objects.requireNonNull(delegate, "delegate");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -20,8 +20,7 @@ import org.elasticsearch.common.inject.Binder;
|
|||
import org.elasticsearch.common.inject.Scope;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Registration of a scope annotation with the scope that implements it. Instances are created
|
||||
|
@ -40,9 +39,9 @@ public final class ScopeBinding implements Element {
|
|||
private final Scope scope;
|
||||
|
||||
ScopeBinding(Object source, Class<? extends Annotation> annotationType, Scope scope) {
|
||||
this.source = checkNotNull(source, "source");
|
||||
this.annotationType = checkNotNull(annotationType, "annotationType");
|
||||
this.scope = checkNotNull(scope, "scope");
|
||||
this.source = Objects.requireNonNull(source, "source");
|
||||
this.annotationType = Objects.requireNonNull(annotationType, "annotationType");
|
||||
this.scope = Objects.requireNonNull(scope, "scope");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -19,10 +19,9 @@ package org.elasticsearch.common.inject.spi;
|
|||
import org.elasticsearch.common.inject.Binder;
|
||||
import org.elasticsearch.common.inject.ConfigurationException;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* A request to inject the static fields and methods of a type. Requests are created
|
||||
* explicitly in a module using {@link org.elasticsearch.common.inject.Binder#requestStaticInjection(Class[])
|
||||
|
@ -38,8 +37,8 @@ public final class StaticInjectionRequest implements Element {
|
|||
private final Class<?> type;
|
||||
|
||||
StaticInjectionRequest(Object source, Class<?> type) {
|
||||
this.source = checkNotNull(source, "source");
|
||||
this.type = checkNotNull(type, "type");
|
||||
this.source = Objects.requireNonNull(source, "source");
|
||||
this.type = Objects.requireNonNull(type, "type");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -20,7 +20,7 @@ import org.elasticsearch.common.inject.Binder;
|
|||
import org.elasticsearch.common.inject.TypeLiteral;
|
||||
import org.elasticsearch.common.inject.matcher.Matcher;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Registration of type converters for matching target types. Instances are created
|
||||
|
@ -39,9 +39,9 @@ public final class TypeConverterBinding implements Element {
|
|||
|
||||
TypeConverterBinding(Object source, Matcher<? super TypeLiteral<?>> typeMatcher,
|
||||
TypeConverter typeConverter) {
|
||||
this.source = checkNotNull(source, "source");
|
||||
this.typeMatcher = checkNotNull(typeMatcher, "typeMatcher");
|
||||
this.typeConverter = checkNotNull(typeConverter, "typeConverter");
|
||||
this.source = Objects.requireNonNull(source, "source");
|
||||
this.typeMatcher = Objects.requireNonNull(typeMatcher, "typeMatcher");
|
||||
this.typeConverter = Objects.requireNonNull(typeConverter, "typeConverter");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
package org.elasticsearch.common.inject.util;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Sets;
|
||||
import org.elasticsearch.common.inject.AbstractModule;
|
||||
import org.elasticsearch.common.inject.Binder;
|
||||
import org.elasticsearch.common.inject.Binding;
|
||||
|
@ -36,6 +35,7 @@ import java.lang.annotation.Annotation;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
@ -151,8 +151,8 @@ public final class Modules {
|
|||
final List<Element> elements = Elements.getElements(baseModules);
|
||||
final List<Element> overrideElements = Elements.getElements(overrides);
|
||||
|
||||
final Set<Key> overriddenKeys = Sets.newHashSet();
|
||||
final Set<Class<? extends Annotation>> overridesScopeAnnotations = Sets.newHashSet();
|
||||
final Set<Key> overriddenKeys = new HashSet<>();
|
||||
final Set<Class<? extends Annotation>> overridesScopeAnnotations = new HashSet<>();
|
||||
|
||||
// execute the overrides module, keeping track of which keys and scopes are bound
|
||||
new ModuleWriter(binder()) {
|
||||
|
@ -201,7 +201,7 @@ public final class Modules {
|
|||
PrivateBinder privateBinder = binder.withSource(privateElements.getSource())
|
||||
.newPrivateBinder();
|
||||
|
||||
Set<Key<?>> skippedExposes = Sets.newHashSet();
|
||||
Set<Key<?>> skippedExposes = new HashSet<>();
|
||||
|
||||
for (Key<?> key : privateElements.getExposedKeys()) {
|
||||
if (overriddenKeys.remove(key)) {
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
package org.elasticsearch.common.io;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import com.google.common.base.Preconditions;
|
||||
import org.elasticsearch.common.util.Callback;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
|
@ -33,6 +32,7 @@ import java.io.StringWriter;
|
|||
import java.io.Writer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Simple utility methods for file and stream copying.
|
||||
|
@ -66,8 +66,8 @@ public abstract class Streams {
|
|||
* @throws IOException in case of I/O errors
|
||||
*/
|
||||
public static long copy(InputStream in, OutputStream out, byte[] buffer) throws IOException {
|
||||
Preconditions.checkNotNull(in, "No InputStream specified");
|
||||
Preconditions.checkNotNull(out, "No OutputStream specified");
|
||||
Objects.requireNonNull(in, "No InputStream specified");
|
||||
Objects.requireNonNull(out, "No OutputStream specified");
|
||||
try {
|
||||
long byteCount = 0;
|
||||
int bytesRead;
|
||||
|
@ -100,8 +100,8 @@ public abstract class Streams {
|
|||
* @throws IOException in case of I/O errors
|
||||
*/
|
||||
public static void copy(byte[] in, OutputStream out) throws IOException {
|
||||
Preconditions.checkNotNull(in, "No input byte array specified");
|
||||
Preconditions.checkNotNull(out, "No OutputStream specified");
|
||||
Objects.requireNonNull(in, "No input byte array specified");
|
||||
Objects.requireNonNull(out, "No OutputStream specified");
|
||||
try {
|
||||
out.write(in);
|
||||
} finally {
|
||||
|
@ -128,8 +128,8 @@ public abstract class Streams {
|
|||
* @throws IOException in case of I/O errors
|
||||
*/
|
||||
public static int copy(Reader in, Writer out) throws IOException {
|
||||
Preconditions.checkNotNull(in, "No Reader specified");
|
||||
Preconditions.checkNotNull(out, "No Writer specified");
|
||||
Objects.requireNonNull(in, "No Reader specified");
|
||||
Objects.requireNonNull(out, "No Writer specified");
|
||||
try {
|
||||
int byteCount = 0;
|
||||
char[] buffer = new char[BUFFER_SIZE];
|
||||
|
@ -163,8 +163,8 @@ public abstract class Streams {
|
|||
* @throws IOException in case of I/O errors
|
||||
*/
|
||||
public static void copy(String in, Writer out) throws IOException {
|
||||
Preconditions.checkNotNull(in, "No input String specified");
|
||||
Preconditions.checkNotNull(out, "No Writer specified");
|
||||
Objects.requireNonNull(in, "No input String specified");
|
||||
Objects.requireNonNull(out, "No Writer specified");
|
||||
try {
|
||||
out.write(in);
|
||||
} finally {
|
||||
|
|
|
@ -24,10 +24,9 @@ import org.joda.time.DateTimeZone;
|
|||
import org.joda.time.MutableDateTime;
|
||||
import org.joda.time.format.DateTimeFormatter;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* A parser for date/time formatted text with optional date math.
|
||||
*
|
||||
|
@ -40,7 +39,7 @@ public class DateMathParser {
|
|||
private final FormatDateTimeFormatter dateTimeFormatter;
|
||||
|
||||
public DateMathParser(FormatDateTimeFormatter dateTimeFormatter) {
|
||||
checkNotNull(dateTimeFormatter);
|
||||
Objects.requireNonNull(dateTimeFormatter);
|
||||
this.dateTimeFormatter = dateTimeFormatter;
|
||||
}
|
||||
|
||||
|
|
|
@ -25,12 +25,11 @@ import org.elasticsearch.common.io.FastStringReader;
|
|||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.google.common.collect.Sets.newHashSet;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
@ -136,7 +135,7 @@ public class AllEntries extends Reader {
|
|||
}
|
||||
|
||||
public Set<String> fields() {
|
||||
Set<String> fields = newHashSet();
|
||||
Set<String> fields = new HashSet<>();
|
||||
for (Entry entry : entries) {
|
||||
fields.add(entry.name());
|
||||
}
|
||||
|
|
|
@ -64,6 +64,9 @@ public final class AllTermQuery extends Query {
|
|||
|
||||
@Override
|
||||
public Query rewrite(IndexReader reader) throws IOException {
|
||||
if (getBoost() != 1f) {
|
||||
return super.rewrite(reader);
|
||||
}
|
||||
boolean fieldExists = false;
|
||||
boolean hasPayloads = false;
|
||||
for (LeafReaderContext context : reader.leaves()) {
|
||||
|
@ -98,7 +101,7 @@ public final class AllTermQuery extends Query {
|
|||
final CollectionStatistics collectionStats = searcher.collectionStatistics(term.field());
|
||||
final TermStatistics termStats = searcher.termStatistics(term, termStates);
|
||||
final Similarity similarity = searcher.getSimilarity(needsScores);
|
||||
final SimWeight stats = similarity.computeWeight(getBoost(), collectionStats, termStats);
|
||||
final SimWeight stats = similarity.computeWeight(collectionStats, termStats);
|
||||
return new Weight(this) {
|
||||
|
||||
@Override
|
||||
|
|
|
@ -120,6 +120,9 @@ public class MultiPhrasePrefixQuery extends Query {
|
|||
|
||||
@Override
|
||||
public Query rewrite(IndexReader reader) throws IOException {
|
||||
if (getBoost() != 1.0F) {
|
||||
return super.rewrite(reader);
|
||||
}
|
||||
if (termArrays.isEmpty()) {
|
||||
return new MatchNoDocsQuery();
|
||||
}
|
||||
|
|
|
@ -1,70 +0,0 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.common.lucene.search.function;
|
||||
|
||||
import org.apache.lucene.index.LeafReaderContext;
|
||||
import org.apache.lucene.search.Explanation;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Deprecated
|
||||
public class BoostScoreFunction extends ScoreFunction {
|
||||
|
||||
public static final String BOOST_WEIGHT_ERROR_MESSAGE = "'boost_factor' and 'weight' cannot be used together. Use 'weight'.";
|
||||
|
||||
private final float boost;
|
||||
|
||||
public BoostScoreFunction(float boost) {
|
||||
super(CombineFunction.MULT);
|
||||
this.boost = boost;
|
||||
}
|
||||
|
||||
public float getBoost() {
|
||||
return boost;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LeafScoreFunction getLeafScoreFunction(LeafReaderContext ctx) {
|
||||
return new LeafScoreFunction() {
|
||||
|
||||
@Override
|
||||
public double score(int docId, float subQueryScore) {
|
||||
return boost;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Explanation explainScore(int docId, Explanation subQueryScore) {
|
||||
return Explanation.match(boost, "static boost factor", Explanation.match(boost, "boostFactor"));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean needsScores() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "boost[" + boost + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -24,8 +24,8 @@ import org.apache.lucene.search.Explanation;
|
|||
public enum CombineFunction {
|
||||
MULT {
|
||||
@Override
|
||||
public float combine(double queryBoost, double queryScore, double funcScore, double maxBoost) {
|
||||
return toFloat(queryBoost * queryScore * Math.min(funcScore, maxBoost));
|
||||
public float combine(double queryScore, double funcScore, double maxBoost) {
|
||||
return toFloat(queryScore * Math.min(funcScore, maxBoost));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -34,21 +34,20 @@ public enum CombineFunction {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Explanation explain(float queryBoost, Explanation queryExpl, Explanation funcExpl, float maxBoost) {
|
||||
float score = queryBoost * Math.min(funcExpl.getValue(), maxBoost) * queryExpl.getValue();
|
||||
public Explanation explain(Explanation queryExpl, Explanation funcExpl, float maxBoost) {
|
||||
Explanation boostExpl = Explanation.match(maxBoost, "maxBoost");
|
||||
Explanation minExpl = Explanation.match(
|
||||
Math.min(funcExpl.getValue(), maxBoost),
|
||||
"min of:",
|
||||
funcExpl, boostExpl);
|
||||
return Explanation.match(score, "function score, product of:",
|
||||
queryExpl, minExpl, Explanation.match(queryBoost, "queryBoost"));
|
||||
return Explanation.match(queryExpl.getValue() * minExpl.getValue(),
|
||||
"function score, product of:", queryExpl, minExpl);
|
||||
}
|
||||
},
|
||||
REPLACE {
|
||||
@Override
|
||||
public float combine(double queryBoost, double queryScore, double funcScore, double maxBoost) {
|
||||
return toFloat(queryBoost * Math.min(funcScore, maxBoost));
|
||||
public float combine(double queryScore, double funcScore, double maxBoost) {
|
||||
return toFloat(Math.min(funcScore, maxBoost));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -57,22 +56,19 @@ public enum CombineFunction {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Explanation explain(float queryBoost, Explanation queryExpl, Explanation funcExpl, float maxBoost) {
|
||||
float score = queryBoost * Math.min(funcExpl.getValue(), maxBoost);
|
||||
public Explanation explain(Explanation queryExpl, Explanation funcExpl, float maxBoost) {
|
||||
Explanation boostExpl = Explanation.match(maxBoost, "maxBoost");
|
||||
Explanation minExpl = Explanation.match(
|
||||
return Explanation.match(
|
||||
Math.min(funcExpl.getValue(), maxBoost),
|
||||
"min of:",
|
||||
funcExpl, boostExpl);
|
||||
return Explanation.match(score, "function score, product of:",
|
||||
minExpl, Explanation.match(queryBoost, "queryBoost"));
|
||||
}
|
||||
|
||||
},
|
||||
SUM {
|
||||
@Override
|
||||
public float combine(double queryBoost, double queryScore, double funcScore, double maxBoost) {
|
||||
return toFloat(queryBoost * (queryScore + Math.min(funcScore, maxBoost)));
|
||||
public float combine(double queryScore, double funcScore, double maxBoost) {
|
||||
return toFloat(queryScore + Math.min(funcScore, maxBoost));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -81,21 +77,18 @@ public enum CombineFunction {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Explanation explain(float queryBoost, Explanation queryExpl, Explanation funcExpl, float maxBoost) {
|
||||
float score = queryBoost * (Math.min(funcExpl.getValue(), maxBoost) + queryExpl.getValue());
|
||||
public Explanation explain(Explanation queryExpl, Explanation funcExpl, float maxBoost) {
|
||||
Explanation minExpl = Explanation.match(Math.min(funcExpl.getValue(), maxBoost), "min of:",
|
||||
funcExpl, Explanation.match(maxBoost, "maxBoost"));
|
||||
Explanation sumExpl = Explanation.match(Math.min(funcExpl.getValue(), maxBoost) + queryExpl.getValue(), "sum of",
|
||||
return Explanation.match(Math.min(funcExpl.getValue(), maxBoost) + queryExpl.getValue(), "sum of",
|
||||
queryExpl, minExpl);
|
||||
return Explanation.match(score, "function score, product of:",
|
||||
sumExpl, Explanation.match(queryBoost, "queryBoost"));
|
||||
}
|
||||
|
||||
},
|
||||
AVG {
|
||||
@Override
|
||||
public float combine(double queryBoost, double queryScore, double funcScore, double maxBoost) {
|
||||
return toFloat((queryBoost * (Math.min(funcScore, maxBoost) + queryScore) / 2.0));
|
||||
public float combine(double queryScore, double funcScore, double maxBoost) {
|
||||
return toFloat((Math.min(funcScore, maxBoost) + queryScore) / 2.0);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -104,22 +97,19 @@ public enum CombineFunction {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Explanation explain(float queryBoost, Explanation queryExpl, Explanation funcExpl, float maxBoost) {
|
||||
float score = toFloat(queryBoost * (queryExpl.getValue() + Math.min(funcExpl.getValue(), maxBoost)) / 2.0);
|
||||
public Explanation explain(Explanation queryExpl, Explanation funcExpl, float maxBoost) {
|
||||
Explanation minExpl = Explanation.match(Math.min(funcExpl.getValue(), maxBoost), "min of:",
|
||||
funcExpl, Explanation.match(maxBoost, "maxBoost"));
|
||||
Explanation avgExpl = Explanation.match(
|
||||
return Explanation.match(
|
||||
toFloat((Math.min(funcExpl.getValue(), maxBoost) + queryExpl.getValue()) / 2.0), "avg of",
|
||||
queryExpl, minExpl);
|
||||
return Explanation.match(score, "function score, product of:",
|
||||
avgExpl, Explanation.match(queryBoost, "queryBoost"));
|
||||
}
|
||||
|
||||
},
|
||||
MIN {
|
||||
@Override
|
||||
public float combine(double queryBoost, double queryScore, double funcScore, double maxBoost) {
|
||||
return toFloat(queryBoost * Math.min(queryScore, Math.min(funcScore, maxBoost)));
|
||||
public float combine(double queryScore, double funcScore, double maxBoost) {
|
||||
return toFloat(Math.min(queryScore, Math.min(funcScore, maxBoost)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -128,23 +118,20 @@ public enum CombineFunction {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Explanation explain(float queryBoost, Explanation queryExpl, Explanation funcExpl, float maxBoost) {
|
||||
float score = toFloat(queryBoost * Math.min(queryExpl.getValue(), Math.min(funcExpl.getValue(), maxBoost)));
|
||||
public Explanation explain(Explanation queryExpl, Explanation funcExpl, float maxBoost) {
|
||||
Explanation innerMinExpl = Explanation.match(
|
||||
Math.min(funcExpl.getValue(), maxBoost), "min of:",
|
||||
funcExpl, Explanation.match(maxBoost, "maxBoost"));
|
||||
Explanation outerMinExpl = Explanation.match(
|
||||
return Explanation.match(
|
||||
Math.min(Math.min(funcExpl.getValue(), maxBoost), queryExpl.getValue()), "min of",
|
||||
queryExpl, innerMinExpl);
|
||||
return Explanation.match(score, "function score, product of:",
|
||||
outerMinExpl, Explanation.match(queryBoost, "queryBoost"));
|
||||
}
|
||||
|
||||
},
|
||||
MAX {
|
||||
@Override
|
||||
public float combine(double queryBoost, double queryScore, double funcScore, double maxBoost) {
|
||||
return toFloat(queryBoost * (Math.max(queryScore, Math.min(funcScore, maxBoost))));
|
||||
public float combine(double queryScore, double funcScore, double maxBoost) {
|
||||
return toFloat(Math.max(queryScore, Math.min(funcScore, maxBoost)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -153,21 +140,18 @@ public enum CombineFunction {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Explanation explain(float queryBoost, Explanation queryExpl, Explanation funcExpl, float maxBoost) {
|
||||
float score = toFloat(queryBoost * Math.max(queryExpl.getValue(), Math.min(funcExpl.getValue(), maxBoost)));
|
||||
public Explanation explain(Explanation queryExpl, Explanation funcExpl, float maxBoost) {
|
||||
Explanation innerMinExpl = Explanation.match(
|
||||
Math.min(funcExpl.getValue(), maxBoost), "min of:",
|
||||
funcExpl, Explanation.match(maxBoost, "maxBoost"));
|
||||
Explanation outerMaxExpl = Explanation.match(
|
||||
return Explanation.match(
|
||||
Math.max(Math.min(funcExpl.getValue(), maxBoost), queryExpl.getValue()), "max of:",
|
||||
queryExpl, innerMinExpl);
|
||||
return Explanation.match(score, "function score, product of:",
|
||||
outerMaxExpl, Explanation.match(queryBoost, "queryBoost"));
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
public abstract float combine(double queryBoost, double queryScore, double funcScore, double maxBoost);
|
||||
public abstract float combine(double queryScore, double funcScore, double maxBoost);
|
||||
|
||||
public abstract String getName();
|
||||
|
||||
|
@ -181,5 +165,5 @@ public enum CombineFunction {
|
|||
return Double.compare(floatVersion, input) == 0 || input == 0.0d ? 0 : 1.d - (floatVersion) / input;
|
||||
}
|
||||
|
||||
public abstract Explanation explain(float queryBoost, Explanation queryExpl, Explanation funcExpl, float maxBoost);
|
||||
public abstract Explanation explain(Explanation queryExpl, Explanation funcExpl, float maxBoost);
|
||||
}
|
||||
|
|
|
@ -21,13 +21,11 @@ package org.elasticsearch.common.lucene.search.function;
|
|||
|
||||
import org.apache.lucene.search.Scorer;
|
||||
import org.apache.lucene.search.Weight;
|
||||
import org.apache.lucene.util.BytesRef;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
abstract class CustomBoostFactorScorer extends Scorer {
|
||||
|
||||
final float subQueryBoost;
|
||||
final Scorer scorer;
|
||||
final float maxBoost;
|
||||
final CombineFunction scoreCombiner;
|
||||
|
@ -43,7 +41,6 @@ abstract class CustomBoostFactorScorer extends Scorer {
|
|||
} else {
|
||||
nextDoc = new MinScoreNextDoc();
|
||||
}
|
||||
this.subQueryBoost = w.getQuery().getBoost();
|
||||
this.scorer = scorer;
|
||||
this.maxBoost = maxBoost;
|
||||
this.scoreCombiner = scoreCombiner;
|
||||
|
|
|
@ -114,6 +114,9 @@ public class FiltersFunctionScoreQuery extends Query {
|
|||
|
||||
@Override
|
||||
public Query rewrite(IndexReader reader) throws IOException {
|
||||
if (getBoost() != 1.0F) {
|
||||
return super.rewrite(reader);
|
||||
}
|
||||
Query newQ = subQuery.rewrite(reader);
|
||||
if (newQ == subQuery)
|
||||
return this;
|
||||
|
@ -158,14 +161,12 @@ public class FiltersFunctionScoreQuery extends Query {
|
|||
|
||||
@Override
|
||||
public float getValueForNormalization() throws IOException {
|
||||
float sum = subQueryWeight.getValueForNormalization();
|
||||
sum *= getBoost() * getBoost();
|
||||
return sum;
|
||||
return subQueryWeight.getValueForNormalization();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void normalize(float norm, float topLevelBoost) {
|
||||
subQueryWeight.normalize(norm, topLevelBoost * getBoost());
|
||||
public void normalize(float norm, float boost) {
|
||||
subQueryWeight.normalize(norm, boost);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -219,10 +220,7 @@ public class FiltersFunctionScoreQuery extends Query {
|
|||
}
|
||||
}
|
||||
if (filterExplanations.size() == 0) {
|
||||
float sc = getBoost() * subQueryExpl.getValue();
|
||||
return Explanation.match(sc, "function score, no filter match, product of:",
|
||||
subQueryExpl,
|
||||
Explanation.match(getBoost(), "queryBoost"));
|
||||
return subQueryExpl;
|
||||
}
|
||||
|
||||
// Second: Compute the factor that would have been computed by the
|
||||
|
@ -266,7 +264,7 @@ public class FiltersFunctionScoreQuery extends Query {
|
|||
CombineFunction.toFloat(factor),
|
||||
"function score, score mode [" + scoreMode.toString().toLowerCase(Locale.ROOT) + "]",
|
||||
filterExplanations);
|
||||
return combineFunction.explain(getBoost(), subQueryExpl, factorExplanation, maxBoost);
|
||||
return combineFunction.explain(subQueryExpl, factorExplanation, maxBoost);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -348,7 +346,7 @@ public class FiltersFunctionScoreQuery extends Query {
|
|||
}
|
||||
}
|
||||
}
|
||||
return scoreCombiner.combine(subQueryBoost, subQueryScore, factor, maxBoost);
|
||||
return scoreCombiner.combine(subQueryScore, factor, maxBoost);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -76,6 +76,9 @@ public class FunctionScoreQuery extends Query {
|
|||
|
||||
@Override
|
||||
public Query rewrite(IndexReader reader) throws IOException {
|
||||
if (getBoost() != 1.0F) {
|
||||
return super.rewrite(reader);
|
||||
}
|
||||
Query newQ = subQuery.rewrite(reader);
|
||||
if (newQ == subQuery) {
|
||||
return this;
|
||||
|
@ -117,14 +120,12 @@ public class FunctionScoreQuery extends Query {
|
|||
|
||||
@Override
|
||||
public float getValueForNormalization() throws IOException {
|
||||
float sum = subQueryWeight.getValueForNormalization();
|
||||
sum *= getBoost() * getBoost();
|
||||
return sum;
|
||||
return subQueryWeight.getValueForNormalization();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void normalize(float norm, float topLevelBoost) {
|
||||
subQueryWeight.normalize(norm, topLevelBoost * getBoost());
|
||||
public void normalize(float norm, float boost) {
|
||||
subQueryWeight.normalize(norm, boost);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -148,7 +149,7 @@ public class FunctionScoreQuery extends Query {
|
|||
}
|
||||
if (function != null) {
|
||||
Explanation functionExplanation = function.getLeafScoreFunction(context).explainScore(doc, subQueryExpl);
|
||||
return combineFunction.explain(getBoost(), subQueryExpl, functionExplanation, maxBoost);
|
||||
return combineFunction.explain(subQueryExpl, functionExplanation, maxBoost);
|
||||
} else {
|
||||
return subQueryExpl;
|
||||
}
|
||||
|
@ -174,9 +175,9 @@ public class FunctionScoreQuery extends Query {
|
|||
// are needed
|
||||
float score = needsScores ? scorer.score() : 0f;
|
||||
if (function == null) {
|
||||
return subQueryBoost * score;
|
||||
return score;
|
||||
} else {
|
||||
return scoreCombiner.combine(subQueryBoost, score,
|
||||
return scoreCombiner.combine(score,
|
||||
function.score(scorer.docID(), score), maxBoost);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,9 +35,6 @@ public class WeightFactorFunction extends ScoreFunction {
|
|||
|
||||
public WeightFactorFunction(float weight, ScoreFunction scoreFunction) {
|
||||
super(CombineFunction.MULT);
|
||||
if (scoreFunction instanceof BoostScoreFunction) {
|
||||
throw new IllegalArgumentException(BoostScoreFunction.BOOST_WEIGHT_ERROR_MESSAGE);
|
||||
}
|
||||
if (scoreFunction == null) {
|
||||
this.scoreFunction = SCORE_ONE;
|
||||
} else {
|
||||
|
|
|
@ -19,10 +19,10 @@
|
|||
|
||||
package org.elasticsearch.common.property;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import org.elasticsearch.common.Strings;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Objects;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -61,8 +61,8 @@ public class PropertyPlaceholder {
|
|||
*/
|
||||
public PropertyPlaceholder(String placeholderPrefix, String placeholderSuffix,
|
||||
boolean ignoreUnresolvablePlaceholders) {
|
||||
Preconditions.checkNotNull(placeholderPrefix, "Argument 'placeholderPrefix' must not be null.");
|
||||
Preconditions.checkNotNull(placeholderSuffix, "Argument 'placeholderSuffix' must not be null.");
|
||||
Objects.requireNonNull(placeholderPrefix, "Argument 'placeholderPrefix' must not be null.");
|
||||
Objects.requireNonNull(placeholderSuffix, "Argument 'placeholderSuffix' must not be null.");
|
||||
this.placeholderPrefix = placeholderPrefix;
|
||||
this.placeholderSuffix = placeholderSuffix;
|
||||
this.ignoreUnresolvablePlaceholders = ignoreUnresolvablePlaceholders;
|
||||
|
@ -77,7 +77,7 @@ public class PropertyPlaceholder {
|
|||
* @return the supplied value with placeholders replaced inline.
|
||||
*/
|
||||
public String replacePlaceholders(String value, PlaceholderResolver placeholderResolver) {
|
||||
Preconditions.checkNotNull(value, "Argument 'value' must not be null.");
|
||||
Objects.requireNonNull(value, "Argument 'value' must not be null.");
|
||||
return parseStringValue(value, placeholderResolver, new HashSet<String>());
|
||||
}
|
||||
|
||||
|
|
|
@ -20,8 +20,8 @@
|
|||
package org.elasticsearch.common.recycler;
|
||||
|
||||
import com.carrotsearch.hppc.BitMixer;
|
||||
import com.google.common.collect.Queues;
|
||||
import org.elasticsearch.ElasticsearchException;
|
||||
|
||||
import java.util.ArrayDeque;
|
||||
|
||||
public enum Recyclers {
|
||||
;
|
||||
|
@ -44,7 +44,7 @@ public enum Recyclers {
|
|||
* Return a recycler based on a deque.
|
||||
*/
|
||||
public static <T> Recycler<T> deque(Recycler.C<T> c, int limit) {
|
||||
return new DequeRecycler<>(c, Queues.<T>newArrayDeque(), limit);
|
||||
return new DequeRecycler<>(c, new ArrayDeque<>(), limit);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
package org.elasticsearch.common.util;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.common.primitives.Ints;
|
||||
import org.apache.lucene.index.CheckIndex;
|
||||
import org.apache.lucene.index.IndexWriter;
|
||||
|
@ -38,13 +37,25 @@ import org.elasticsearch.env.NodeEnvironment;
|
|||
import org.elasticsearch.env.ShardLock;
|
||||
import org.elasticsearch.gateway.MetaDataStateFormat;
|
||||
import org.elasticsearch.index.Index;
|
||||
import org.elasticsearch.index.shard.*;
|
||||
import org.elasticsearch.index.shard.ShardId;
|
||||
import org.elasticsearch.index.shard.ShardPath;
|
||||
import org.elasticsearch.index.shard.ShardStateMetaData;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintStream;
|
||||
import java.nio.file.*;
|
||||
import java.nio.file.DirectoryStream;
|
||||
import java.nio.file.FileStore;
|
||||
import java.nio.file.FileVisitResult;
|
||||
import java.nio.file.FileVisitor;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
*/
|
||||
|
@ -343,7 +354,7 @@ public class MultiDataPathUpgrader {
|
|||
}
|
||||
|
||||
private static Set<ShardId> findAllShardIds(Path... locations) throws IOException {
|
||||
final Set<ShardId> shardIds = Sets.newHashSet();
|
||||
final Set<ShardId> shardIds = new HashSet<>();
|
||||
for (final Path location : locations) {
|
||||
if (Files.isDirectory(location)) {
|
||||
shardIds.addAll(findAllShardsForIndex(location));
|
||||
|
|
|
@ -22,11 +22,10 @@ package org.elasticsearch.common.util.concurrent;
|
|||
import org.elasticsearch.common.Nullable;
|
||||
import org.elasticsearch.transport.Transports;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.concurrent.locks.AbstractQueuedSynchronizer;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* An abstract implementation of the {@link com.google.common.util.concurrent.ListenableFuture} interface. This
|
||||
* class is preferable to {@link java.util.concurrent.FutureTask} for two
|
||||
|
@ -178,7 +177,7 @@ public abstract class BaseFuture<V> implements Future<V> {
|
|||
* @throws Error if the throwable was an {@link Error}.
|
||||
*/
|
||||
protected boolean setException(Throwable throwable) {
|
||||
boolean result = sync.setException(checkNotNull(throwable));
|
||||
boolean result = sync.setException(Objects.requireNonNull(throwable));
|
||||
if (result) {
|
||||
done();
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
package org.elasticsearch.common.util.concurrent;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Deque;
|
||||
import java.util.Queue;
|
||||
import java.util.Set;
|
||||
|
@ -29,7 +30,6 @@ import java.util.concurrent.ConcurrentLinkedQueue;
|
|||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.concurrent.LinkedTransferQueue;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -67,7 +67,7 @@ public abstract class ConcurrentCollections {
|
|||
}
|
||||
|
||||
public static <V> Set<V> newConcurrentSet() {
|
||||
return Sets.newSetFromMap(ConcurrentCollections.<V, Boolean>newConcurrentMap());
|
||||
return Collections.newSetFromMap(ConcurrentCollections.<V, Boolean>newConcurrentMap());
|
||||
}
|
||||
|
||||
public static <T> Queue<T> newQueue() {
|
||||
|
|
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.common.util.set;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public final class Sets {
|
||||
private Sets() {
|
||||
}
|
||||
|
||||
public static <T> HashSet<T> newHashSet(Iterator<T> iterator) {
|
||||
Objects.requireNonNull(iterator);
|
||||
HashSet<T> set = new HashSet<>();
|
||||
while (iterator.hasNext()) {
|
||||
set.add(iterator.next());
|
||||
}
|
||||
return set;
|
||||
}
|
||||
|
||||
public static <T> HashSet<T> newHashSet(Iterable<T> iterable) {
|
||||
Objects.requireNonNull(iterable);
|
||||
return iterable instanceof Collection ? new HashSet<>((Collection)iterable) : newHashSet(iterable.iterator());
|
||||
}
|
||||
|
||||
public static <T> HashSet<T> newHashSet(T... elements) {
|
||||
Objects.requireNonNull(elements);
|
||||
HashSet<T> set = new HashSet<>(elements.length);
|
||||
Collections.addAll(set, elements);
|
||||
return set;
|
||||
}
|
||||
|
||||
public static <T> Set<T> newConcurrentHashSet() {
|
||||
return Collections.newSetFromMap(new ConcurrentHashMap<>());
|
||||
}
|
||||
|
||||
public static <T> boolean haveEmptyIntersection(Set<T> left, Set<T> right) {
|
||||
Objects.requireNonNull(left);
|
||||
Objects.requireNonNull(right);
|
||||
return !left.stream().anyMatch(k -> right.contains(k));
|
||||
}
|
||||
|
||||
public static <T> Set<T> difference(Set<T> left, Set<T> right) {
|
||||
Objects.requireNonNull(left);
|
||||
Objects.requireNonNull(right);
|
||||
return left.stream().filter(k -> !right.contains(k)).collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
public static <T> Set<T> union(Set<T> left, Set<T> right) {
|
||||
Objects.requireNonNull(left);
|
||||
Objects.requireNonNull(right);
|
||||
Set<T> union = new HashSet<>(left);
|
||||
union.addAll(right);
|
||||
return union;
|
||||
}
|
||||
}
|
|
@ -20,13 +20,19 @@
|
|||
package org.elasticsearch.discovery.local;
|
||||
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.cluster.*;
|
||||
import org.elasticsearch.cluster.ClusterChangedEvent;
|
||||
import org.elasticsearch.cluster.ClusterName;
|
||||
import org.elasticsearch.cluster.ClusterService;
|
||||
import org.elasticsearch.cluster.ClusterState;
|
||||
import org.elasticsearch.cluster.ClusterStateNonMasterUpdateTask;
|
||||
import org.elasticsearch.cluster.Diff;
|
||||
import org.elasticsearch.cluster.IncompatibleClusterStateVersionException;
|
||||
import org.elasticsearch.cluster.ProcessedClusterStateNonMasterUpdateTask;
|
||||
import org.elasticsearch.cluster.block.ClusterBlocks;
|
||||
import org.elasticsearch.cluster.node.DiscoveryNode;
|
||||
import org.elasticsearch.cluster.node.DiscoveryNodeService;
|
||||
import org.elasticsearch.cluster.node.DiscoveryNodes;
|
||||
import org.elasticsearch.cluster.routing.RoutingService;
|
||||
import org.elasticsearch.cluster.routing.allocation.AllocationService;
|
||||
import org.elasticsearch.cluster.routing.allocation.RoutingAllocation;
|
||||
import org.elasticsearch.common.component.AbstractLifecycleComponent;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
|
@ -36,7 +42,12 @@ import org.elasticsearch.common.io.stream.StreamInput;
|
|||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.common.util.concurrent.ConcurrentCollections;
|
||||
import org.elasticsearch.discovery.*;
|
||||
import org.elasticsearch.discovery.AckClusterStatePublishResponseHandler;
|
||||
import org.elasticsearch.discovery.BlockingClusterStatePublishResponseHandler;
|
||||
import org.elasticsearch.discovery.Discovery;
|
||||
import org.elasticsearch.discovery.DiscoveryService;
|
||||
import org.elasticsearch.discovery.DiscoverySettings;
|
||||
import org.elasticsearch.discovery.InitialStateDiscoveryListener;
|
||||
import org.elasticsearch.node.service.NodeService;
|
||||
import org.elasticsearch.transport.TransportService;
|
||||
|
||||
|
@ -48,7 +59,6 @@ import java.util.concurrent.ConcurrentMap;
|
|||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import static com.google.common.collect.Sets.newHashSet;
|
||||
import static org.elasticsearch.cluster.ClusterState.Builder;
|
||||
|
||||
/**
|
||||
|
@ -227,7 +237,7 @@ public class LocalDiscovery extends AbstractLifecycleComponent<Discovery> implem
|
|||
firstMaster.master = true;
|
||||
}
|
||||
|
||||
final Set<String> newMembers = newHashSet();
|
||||
final Set<String> newMembers = new HashSet<>();
|
||||
for (LocalDiscovery discovery : clusterGroup.members()) {
|
||||
newMembers.add(discovery.localNode.id());
|
||||
}
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
|
||||
package org.elasticsearch.discovery.zen;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import org.elasticsearch.ExceptionsHelper;
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.cluster.ClusterChangedEvent;
|
||||
|
@ -73,6 +72,7 @@ import org.elasticsearch.transport.TransportService;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Queue;
|
||||
|
@ -948,9 +948,9 @@ public class ZenDiscovery extends AbstractLifecycleComponent<Discovery> implemen
|
|||
}
|
||||
|
||||
// nodes discovered during pinging
|
||||
Set<DiscoveryNode> activeNodes = Sets.newHashSet();
|
||||
Set<DiscoveryNode> activeNodes = new HashSet<>();
|
||||
// nodes discovered who has previously been part of the cluster and do not ping for the very first time
|
||||
Set<DiscoveryNode> joinedOnceActiveNodes = Sets.newHashSet();
|
||||
Set<DiscoveryNode> joinedOnceActiveNodes = new HashSet<>();
|
||||
if (localNode.masterNode()) {
|
||||
activeNodes.add(localNode);
|
||||
long joinsCounter = clusterJoinsCounter.get();
|
||||
|
|
|
@ -20,12 +20,15 @@
|
|||
package org.elasticsearch.env;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
import com.google.common.primitives.Ints;
|
||||
import org.apache.lucene.index.IndexWriter;
|
||||
import org.apache.lucene.index.SegmentInfos;
|
||||
import org.apache.lucene.store.*;
|
||||
import org.apache.lucene.store.Directory;
|
||||
import org.apache.lucene.store.FSDirectory;
|
||||
import org.apache.lucene.store.Lock;
|
||||
import org.apache.lucene.store.LockObtainFailedException;
|
||||
import org.apache.lucene.store.NativeFSLockFactory;
|
||||
import org.apache.lucene.store.SimpleFSDirectory;
|
||||
import org.apache.lucene.util.IOUtils;
|
||||
import org.elasticsearch.ElasticsearchException;
|
||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
|
@ -34,7 +37,6 @@ import org.elasticsearch.common.SuppressForbidden;
|
|||
import org.elasticsearch.common.component.AbstractComponent;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.io.FileSystemUtils;
|
||||
import org.elasticsearch.common.io.PathUtils;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.index.Index;
|
||||
|
@ -46,8 +48,21 @@ import org.elasticsearch.monitor.fs.FsProbe;
|
|||
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.*;
|
||||
import java.util.*;
|
||||
import java.nio.file.AtomicMoveNotSupportedException;
|
||||
import java.nio.file.DirectoryStream;
|
||||
import java.nio.file.FileStore;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.Semaphore;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
@ -643,7 +658,7 @@ public class NodeEnvironment extends AbstractComponent implements Closeable {
|
|||
throw new IllegalStateException("node is not configured to store local location");
|
||||
}
|
||||
assert assertEnvIsLocked();
|
||||
Set<String> indices = Sets.newHashSet();
|
||||
Set<String> indices = new HashSet<>();
|
||||
for (NodePath nodePath : nodePaths) {
|
||||
Path indicesLocation = nodePath.indicesPath;
|
||||
if (Files.isDirectory(indicesLocation)) {
|
||||
|
@ -673,7 +688,7 @@ public class NodeEnvironment extends AbstractComponent implements Closeable {
|
|||
throw new IllegalStateException("node is not configured to store local location");
|
||||
}
|
||||
assert assertEnvIsLocked();
|
||||
final Set<ShardId> shardIds = Sets.newHashSet();
|
||||
final Set<ShardId> shardIds = new HashSet<>();
|
||||
String indexName = index.name();
|
||||
for (final NodePath nodePath : nodePaths) {
|
||||
Path location = nodePath.indicesPath;
|
||||
|
|
|
@ -19,13 +19,14 @@
|
|||
|
||||
package org.elasticsearch.http;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import org.elasticsearch.common.inject.AbstractModule;
|
||||
import org.elasticsearch.common.logging.ESLogger;
|
||||
import org.elasticsearch.common.logging.Loggers;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.http.netty.NettyHttpServerTransport;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
@ -50,8 +51,8 @@ public class HttpServerModule extends AbstractModule {
|
|||
}
|
||||
|
||||
public void setHttpServerTransport(Class<? extends HttpServerTransport> httpServerTransport, String source) {
|
||||
Preconditions.checkNotNull(httpServerTransport, "Configured http server transport may not be null");
|
||||
Preconditions.checkNotNull(source, "Plugin, that changes transport may not be null");
|
||||
Objects.requireNonNull(httpServerTransport, "Configured http server transport may not be null");
|
||||
Objects.requireNonNull(source, "Plugin, that changes transport may not be null");
|
||||
logger.info("Using [{}] as http transport, overridden by [{}]", httpServerTransportClass.getName(), source);
|
||||
this.httpServerTransportClass = httpServerTransport;
|
||||
}
|
||||
|
|
|
@ -19,8 +19,6 @@
|
|||
|
||||
package org.elasticsearch.index.engine;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
import org.apache.lucene.index.DirectoryReader;
|
||||
import org.apache.lucene.index.FilterLeafReader;
|
||||
import org.apache.lucene.index.IndexCommit;
|
||||
|
@ -71,6 +69,7 @@ import java.util.Comparator;
|
|||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.locks.Condition;
|
||||
|
@ -100,8 +99,8 @@ public abstract class Engine implements Closeable {
|
|||
protected volatile Throwable failedEngine = null;
|
||||
|
||||
protected Engine(EngineConfig engineConfig) {
|
||||
Preconditions.checkNotNull(engineConfig.getStore(), "Store must be provided to the engine");
|
||||
Preconditions.checkNotNull(engineConfig.getDeletionPolicy(), "Snapshot deletion policy must be provided to the engine");
|
||||
Objects.requireNonNull(engineConfig.getStore(), "Store must be provided to the engine");
|
||||
Objects.requireNonNull(engineConfig.getDeletionPolicy(), "Snapshot deletion policy must be provided to the engine");
|
||||
|
||||
this.engineConfig = engineConfig;
|
||||
this.shardId = engineConfig.getShardId();
|
||||
|
|
|
@ -72,7 +72,7 @@ public class PackedArrayIndexFieldData extends AbstractIndexFieldData<AtomicNume
|
|||
FieldDataType fieldDataType, IndexFieldDataCache cache, NumericType numericType,
|
||||
CircuitBreakerService breakerService) {
|
||||
super(index, indexSettings, fieldNames, fieldDataType, cache);
|
||||
Preconditions.checkNotNull(numericType);
|
||||
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);
|
||||
this.numericType = numericType;
|
||||
this.breakerService = breakerService;
|
||||
|
|
|
@ -19,25 +19,15 @@
|
|||
|
||||
package org.elasticsearch.index.fielddata.plain;
|
||||
|
||||
import com.carrotsearch.hppc.ObjectObjectHashMap;
|
||||
import com.carrotsearch.hppc.cursors.ObjectObjectCursor;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.ImmutableSortedSet;
|
||||
|
||||
import org.apache.lucene.index.*;
|
||||
import org.apache.lucene.index.MultiDocValues.OrdinalMap;
|
||||
import org.apache.lucene.search.DocIdSetIterator;
|
||||
import org.apache.lucene.util.Accountable;
|
||||
import org.apache.lucene.util.BytesRef;
|
||||
import org.apache.lucene.util.LongValues;
|
||||
import org.apache.lucene.util.PagedBytes;
|
||||
import org.apache.lucene.util.packed.PackedInts;
|
||||
import org.apache.lucene.util.packed.PackedLongValues;
|
||||
import org.elasticsearch.ElasticsearchException;
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.common.Nullable;
|
||||
import org.elasticsearch.common.breaker.CircuitBreaker;
|
||||
import org.elasticsearch.common.collect.ImmutableOpenMap;
|
||||
import org.elasticsearch.common.lease.Releasable;
|
||||
import org.elasticsearch.common.lease.Releasables;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
|
@ -46,15 +36,11 @@ import org.elasticsearch.index.Index;
|
|||
import org.elasticsearch.index.fielddata.*;
|
||||
import org.elasticsearch.index.fielddata.IndexFieldData.XFieldComparatorSource.Nested;
|
||||
import org.elasticsearch.index.fielddata.fieldcomparator.BytesRefFieldComparatorSource;
|
||||
import org.elasticsearch.index.fielddata.ordinals.Ordinals;
|
||||
import org.elasticsearch.index.fielddata.ordinals.OrdinalsBuilder;
|
||||
import org.elasticsearch.index.mapper.DocumentMapper;
|
||||
import org.elasticsearch.index.mapper.DocumentTypeListener;
|
||||
import org.elasticsearch.index.mapper.MappedFieldType;
|
||||
import org.elasticsearch.index.mapper.MappedFieldType.Names;
|
||||
import org.elasticsearch.index.mapper.MapperService;
|
||||
import org.elasticsearch.index.mapper.internal.ParentFieldMapper;
|
||||
import org.elasticsearch.index.mapper.internal.UidFieldMapper;
|
||||
import org.elasticsearch.index.settings.IndexSettings;
|
||||
import org.elasticsearch.indices.breaker.CircuitBreakerService;
|
||||
import org.elasticsearch.search.MultiValueMode;
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
|
||||
package org.elasticsearch.index.get;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import org.apache.lucene.index.Term;
|
||||
import org.elasticsearch.ElasticsearchException;
|
||||
import org.elasticsearch.common.Nullable;
|
||||
|
@ -28,6 +27,7 @@ import org.elasticsearch.common.collect.Tuple;
|
|||
import org.elasticsearch.common.lucene.uid.Versions;
|
||||
import org.elasticsearch.common.metrics.CounterMetric;
|
||||
import org.elasticsearch.common.metrics.MeanMetric;
|
||||
import org.elasticsearch.common.util.set.Sets;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentHelper;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
|
|
|
@ -42,6 +42,7 @@ public class IndexingStats implements Streamable, ToXContent {
|
|||
private long indexCount;
|
||||
private long indexTimeInMillis;
|
||||
private long indexCurrent;
|
||||
private long indexFailedCount;
|
||||
|
||||
private long deleteCount;
|
||||
private long deleteTimeInMillis;
|
||||
|
@ -56,10 +57,11 @@ public class IndexingStats implements Streamable, ToXContent {
|
|||
|
||||
}
|
||||
|
||||
public Stats(long indexCount, long indexTimeInMillis, long indexCurrent, long deleteCount, long deleteTimeInMillis, long deleteCurrent, long noopUpdateCount, boolean isThrottled, long throttleTimeInMillis) {
|
||||
public Stats(long indexCount, long indexTimeInMillis, long indexCurrent, long indexFailedCount, long deleteCount, long deleteTimeInMillis, long deleteCurrent, long noopUpdateCount, boolean isThrottled, long throttleTimeInMillis) {
|
||||
this.indexCount = indexCount;
|
||||
this.indexTimeInMillis = indexTimeInMillis;
|
||||
this.indexCurrent = indexCurrent;
|
||||
this.indexFailedCount = indexFailedCount;
|
||||
this.deleteCount = deleteCount;
|
||||
this.deleteTimeInMillis = deleteTimeInMillis;
|
||||
this.deleteCurrent = deleteCurrent;
|
||||
|
@ -72,6 +74,7 @@ public class IndexingStats implements Streamable, ToXContent {
|
|||
indexCount += stats.indexCount;
|
||||
indexTimeInMillis += stats.indexTimeInMillis;
|
||||
indexCurrent += stats.indexCurrent;
|
||||
indexFailedCount += stats.indexFailedCount;
|
||||
|
||||
deleteCount += stats.deleteCount;
|
||||
deleteTimeInMillis += stats.deleteTimeInMillis;
|
||||
|
@ -88,6 +91,10 @@ public class IndexingStats implements Streamable, ToXContent {
|
|||
return indexCount;
|
||||
}
|
||||
|
||||
public long getIndexFailedCount() {
|
||||
return indexFailedCount;
|
||||
}
|
||||
|
||||
public TimeValue getIndexTime() {
|
||||
return new TimeValue(indexTimeInMillis);
|
||||
}
|
||||
|
@ -156,6 +163,10 @@ public class IndexingStats implements Streamable, ToXContent {
|
|||
indexTimeInMillis = in.readVLong();
|
||||
indexCurrent = in.readVLong();
|
||||
|
||||
if(in.getVersion().onOrAfter(Version.V_2_1_0)){
|
||||
indexFailedCount = in.readVLong();
|
||||
}
|
||||
|
||||
deleteCount = in.readVLong();
|
||||
deleteTimeInMillis = in.readVLong();
|
||||
deleteCurrent = in.readVLong();
|
||||
|
@ -170,6 +181,10 @@ public class IndexingStats implements Streamable, ToXContent {
|
|||
out.writeVLong(indexTimeInMillis);
|
||||
out.writeVLong(indexCurrent);
|
||||
|
||||
if(out.getVersion().onOrAfter(Version.V_2_1_0)) {
|
||||
out.writeVLong(indexFailedCount);
|
||||
}
|
||||
|
||||
out.writeVLong(deleteCount);
|
||||
out.writeVLong(deleteTimeInMillis);
|
||||
out.writeVLong(deleteCurrent);
|
||||
|
@ -184,6 +199,7 @@ public class IndexingStats implements Streamable, ToXContent {
|
|||
builder.field(Fields.INDEX_TOTAL, indexCount);
|
||||
builder.timeValueField(Fields.INDEX_TIME_IN_MILLIS, Fields.INDEX_TIME, indexTimeInMillis);
|
||||
builder.field(Fields.INDEX_CURRENT, indexCurrent);
|
||||
builder.field(Fields.INDEX_FAILED, indexFailedCount);
|
||||
|
||||
builder.field(Fields.DELETE_TOTAL, deleteCount);
|
||||
builder.timeValueField(Fields.DELETE_TIME_IN_MILLIS, Fields.DELETE_TIME, deleteTimeInMillis);
|
||||
|
@ -268,6 +284,7 @@ public class IndexingStats implements Streamable, ToXContent {
|
|||
static final XContentBuilderString INDEX_TIME = new XContentBuilderString("index_time");
|
||||
static final XContentBuilderString INDEX_TIME_IN_MILLIS = new XContentBuilderString("index_time_in_millis");
|
||||
static final XContentBuilderString INDEX_CURRENT = new XContentBuilderString("index_current");
|
||||
static final XContentBuilderString INDEX_FAILED = new XContentBuilderString("index_failed");
|
||||
static final XContentBuilderString DELETE_TOTAL = new XContentBuilderString("delete_total");
|
||||
static final XContentBuilderString DELETE_TIME = new XContentBuilderString("delete_time");
|
||||
static final XContentBuilderString DELETE_TIME_IN_MILLIS = new XContentBuilderString("delete_time_in_millis");
|
||||
|
|
|
@ -178,6 +178,8 @@ public class ShardIndexingService extends AbstractIndexShardComponent {
|
|||
public void postIndex(Engine.Index index, Throwable ex) {
|
||||
totalStats.indexCurrent.dec();
|
||||
typeStats(index.type()).indexCurrent.dec();
|
||||
totalStats.indexFailed.inc();
|
||||
typeStats(index.type()).indexFailed.inc();
|
||||
for (IndexingOperationListener listener : listeners) {
|
||||
try {
|
||||
listener.postIndex(index, ex);
|
||||
|
@ -277,6 +279,7 @@ public class ShardIndexingService extends AbstractIndexShardComponent {
|
|||
public final MeanMetric indexMetric = new MeanMetric();
|
||||
public final MeanMetric deleteMetric = new MeanMetric();
|
||||
public final CounterMetric indexCurrent = new CounterMetric();
|
||||
public final CounterMetric indexFailed = new CounterMetric();
|
||||
public final CounterMetric deleteCurrent = new CounterMetric();
|
||||
public final CounterMetric noopUpdates = new CounterMetric();
|
||||
public final CounterMetric throttleTimeMillisMetric = new CounterMetric();
|
||||
|
@ -293,7 +296,7 @@ public class ShardIndexingService extends AbstractIndexShardComponent {
|
|||
}
|
||||
}
|
||||
return new IndexingStats.Stats(
|
||||
indexMetric.count(), TimeUnit.NANOSECONDS.toMillis(indexMetric.sum()), indexCurrent.count(),
|
||||
indexMetric.count(), TimeUnit.NANOSECONDS.toMillis(indexMetric.sum()), indexCurrent.count(), indexFailed.count(),
|
||||
deleteMetric.count(), TimeUnit.NANOSECONDS.toMillis(deleteMetric.sum()), deleteCurrent.count(),
|
||||
noopUpdates.count(), isThrottled, TimeUnit.MILLISECONDS.toMillis(throttleTimeMillisMetric.count() + TimeValue.nsecToMSec(currentThrottleNS)));
|
||||
}
|
||||
|
|
|
@ -21,7 +21,6 @@ package org.elasticsearch.index.mapper;
|
|||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Collections2;
|
||||
import com.google.common.collect.Sets;
|
||||
import org.apache.lucene.analysis.Analyzer;
|
||||
import org.elasticsearch.common.collect.CopyOnWriteHashMap;
|
||||
import org.elasticsearch.common.regex.Regex;
|
||||
|
@ -30,6 +29,7 @@ import org.elasticsearch.index.analysis.FieldNameAnalyzer;
|
|||
|
||||
import java.util.AbstractMap;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
@ -92,7 +92,7 @@ public final class DocumentFieldMappers implements Iterable<FieldMapper> {
|
|||
}
|
||||
|
||||
public Collection<String> simpleMatchToFullName(String pattern) {
|
||||
Set<String> fields = Sets.newHashSet();
|
||||
Set<String> fields = new HashSet<>();
|
||||
for (FieldMapper fieldMapper : this) {
|
||||
if (Regex.simpleMatch(pattern, fieldMapper.fieldType().names().fullName())) {
|
||||
fields.add(fieldMapper.fieldType().names().fullName());
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
|
||||
package org.elasticsearch.index.mapper;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import org.apache.lucene.index.LeafReaderContext;
|
||||
import org.apache.lucene.search.DocIdSet;
|
||||
|
@ -68,6 +67,7 @@ import java.util.HashMap;
|
|||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
|
||||
/**
|
||||
|
@ -142,7 +142,7 @@ public class DocumentMapper implements ToXContent {
|
|||
}
|
||||
|
||||
public DocumentMapper build(MapperService mapperService, DocumentMapperParser docMapperParser) {
|
||||
Preconditions.checkNotNull(rootObjectMapper, "Mapper builder must have the root object mapper set");
|
||||
Objects.requireNonNull(rootObjectMapper, "Mapper builder must have the root object mapper set");
|
||||
return new DocumentMapper(mapperService, indexSettings, docMapperParser, rootObjectMapper, meta, rootMappers, sourceTransforms, mapperService.mappingLock);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,8 +19,6 @@
|
|||
|
||||
package org.elasticsearch.index.mapper;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
import org.apache.lucene.document.Field;
|
||||
import org.apache.lucene.index.IndexOptions;
|
||||
import org.apache.lucene.index.IndexableField;
|
||||
|
@ -34,20 +32,20 @@ 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.index.mapper.core.DateFieldMapper.DateFieldType;
|
||||
import org.elasticsearch.index.mapper.core.NumberFieldMapper;
|
||||
import org.elasticsearch.index.mapper.core.StringFieldMapper;
|
||||
import org.elasticsearch.index.mapper.core.DateFieldMapper.DateFieldType;
|
||||
import org.elasticsearch.index.mapper.core.StringFieldMapper.StringFieldType;
|
||||
import org.elasticsearch.index.mapper.internal.TypeFieldMapper;
|
||||
import org.elasticsearch.index.mapper.internal.UidFieldMapper;
|
||||
import org.elasticsearch.index.mapper.object.ArrayValueMapperParser;
|
||||
import org.elasticsearch.index.mapper.object.ObjectMapper;
|
||||
import org.elasticsearch.index.mapper.object.RootObjectMapper;
|
||||
import org.elasticsearch.percolator.PercolatorService;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
@ -169,7 +167,7 @@ class DocumentParser implements Closeable {
|
|||
}
|
||||
// apply doc boost
|
||||
if (context.docBoost() != 1.0f) {
|
||||
Set<String> encounteredFields = Sets.newHashSet();
|
||||
Set<String> encounteredFields = new HashSet<>();
|
||||
for (ParseContext.Document doc : context.docs()) {
|
||||
encounteredFields.clear();
|
||||
for (IndexableField field : doc) {
|
||||
|
|
|
@ -21,12 +21,12 @@ package org.elasticsearch.index.mapper;
|
|||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Iterators;
|
||||
import com.google.common.collect.Sets;
|
||||
import org.elasticsearch.common.collect.CopyOnWriteHashMap;
|
||||
import org.elasticsearch.common.regex.Regex;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
@ -152,7 +152,7 @@ class FieldTypeLookup implements Iterable<MappedFieldType> {
|
|||
* Returns a list of the index names of a simple match regex like pattern against full name and index name.
|
||||
*/
|
||||
public Collection<String> simpleMatchToIndexNames(String pattern) {
|
||||
Set<String> fields = Sets.newHashSet();
|
||||
Set<String> fields = new HashSet<>();
|
||||
for (MappedFieldType fieldType : this) {
|
||||
if (Regex.simpleMatch(pattern, fieldType.names().fullName())) {
|
||||
fields.add(fieldType.names().indexName());
|
||||
|
@ -167,7 +167,7 @@ class FieldTypeLookup implements Iterable<MappedFieldType> {
|
|||
* Returns a list of the full names of a simple match regex like pattern against full name and index name.
|
||||
*/
|
||||
public Collection<String> simpleMatchToFullName(String pattern) {
|
||||
Set<String> fields = Sets.newHashSet();
|
||||
Set<String> fields = new HashSet<>();
|
||||
for (MappedFieldType fieldType : this) {
|
||||
if (Regex.simpleMatch(pattern, fieldType.names().fullName())) {
|
||||
fields.add(fieldType.names().fullName());
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
*/
|
||||
package org.elasticsearch.index.mapper.core;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import org.apache.lucene.analysis.Analyzer;
|
||||
import org.apache.lucene.analysis.TokenStream;
|
||||
import org.apache.lucene.codecs.PostingsFormat;
|
||||
|
@ -29,6 +28,7 @@ import org.elasticsearch.ElasticsearchParseException;
|
|||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.util.set.Sets;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
|
|
@ -219,6 +219,9 @@ public class DateFieldMapper extends NumberFieldMapper {
|
|||
|
||||
@Override
|
||||
public Query rewrite(IndexReader reader) throws IOException {
|
||||
if (getBoost() != 1.0F) {
|
||||
return super.rewrite(reader);
|
||||
}
|
||||
return innerRangeQuery(lowerTerm, upperTerm, includeLower, includeUpper, timeZone, forcedDateParser);
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
|
||||
package org.elasticsearch.index.mapper.object;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import org.elasticsearch.common.Nullable;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.joda.FormatDateTimeFormatter;
|
||||
|
@ -38,6 +37,7 @@ import org.elasticsearch.index.settings.IndexSettings;
|
|||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -66,7 +66,7 @@ public class RootObjectMapper extends ObjectMapper {
|
|||
protected final List<DynamicTemplate> dynamicTemplates = new ArrayList<>();
|
||||
|
||||
// we use this to filter out seen date formats, because we might get duplicates during merging
|
||||
protected Set<String> seenDateFormats = Sets.newHashSet();
|
||||
protected Set<String> seenDateFormats = new HashSet<>();
|
||||
protected List<FormatDateTimeFormatter> dynamicDateTimeFormatters = new ArrayList<>();
|
||||
|
||||
protected boolean dateDetection = Defaults.DATE_DETECTION;
|
||||
|
|
|
@ -51,11 +51,6 @@ public class HasChildQueryBuilder extends AbstractQueryBuilder<HasChildQueryBuil
|
|||
*/
|
||||
public static final String NAME = "has_child";
|
||||
|
||||
/**
|
||||
* The default cut off point only to evaluate parent documents that contain the matching parent id terms
|
||||
* instead of evaluating all parent docs.
|
||||
*/
|
||||
public static final int DEFAULT_SHORT_CIRCUIT_CUTOFF = 8192;
|
||||
/**
|
||||
* The default maximum number of children that are required to match for the parent to be considered a match.
|
||||
*/
|
||||
|
@ -64,12 +59,16 @@ public class HasChildQueryBuilder extends AbstractQueryBuilder<HasChildQueryBuil
|
|||
* The default minimum number of children that are required to match for the parent to be considered a match.
|
||||
*/
|
||||
public static final int DEFAULT_MIN_CHILDREN = 0;
|
||||
/*
|
||||
* The default score mode that is used to combine score coming from multiple parent documents.
|
||||
*/
|
||||
public static final ScoreMode DEFAULT_SCORE_MODE = ScoreMode.None;
|
||||
|
||||
private final QueryBuilder query;
|
||||
|
||||
private final String type;
|
||||
|
||||
private ScoreType scoreType = ScoreType.NONE;
|
||||
private ScoreMode scoreMode = DEFAULT_SCORE_MODE;
|
||||
|
||||
private int minChildren = DEFAULT_MIN_CHILDREN;
|
||||
|
||||
|
@ -79,9 +78,9 @@ public class HasChildQueryBuilder extends AbstractQueryBuilder<HasChildQueryBuil
|
|||
|
||||
static final HasChildQueryBuilder PROTOTYPE = new HasChildQueryBuilder("", EmptyQueryBuilder.PROTOTYPE);
|
||||
|
||||
public HasChildQueryBuilder(String type, QueryBuilder query, Integer maxChildren, Integer minChildren, ScoreType scoreType, QueryInnerHits queryInnerHits) {
|
||||
public HasChildQueryBuilder(String type, QueryBuilder query, int maxChildren, int minChildren, ScoreMode scoreMode, QueryInnerHits queryInnerHits) {
|
||||
this(type, query);
|
||||
scoreType(scoreType);
|
||||
scoreMode(scoreMode);
|
||||
this.maxChildren = maxChildren;
|
||||
this.minChildren = minChildren;
|
||||
this.queryInnerHits = queryInnerHits;
|
||||
|
@ -101,11 +100,11 @@ public class HasChildQueryBuilder extends AbstractQueryBuilder<HasChildQueryBuil
|
|||
/**
|
||||
* Defines how the scores from the matching child documents are mapped into the parent document.
|
||||
*/
|
||||
public HasChildQueryBuilder scoreType(ScoreType scoreType) {
|
||||
if (scoreType == null) {
|
||||
throw new IllegalArgumentException("[" + NAME + "] requires 'score_type' field");
|
||||
public HasChildQueryBuilder scoreMode(ScoreMode scoreMode) {
|
||||
if (scoreMode == null) {
|
||||
throw new IllegalArgumentException("[" + NAME + "] requires 'score_mode' field");
|
||||
}
|
||||
this.scoreType = scoreType;
|
||||
this.scoreMode = scoreMode;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -163,8 +162,8 @@ public class HasChildQueryBuilder extends AbstractQueryBuilder<HasChildQueryBuil
|
|||
/**
|
||||
* Returns how the scores from the matching child documents are mapped into the parent document.
|
||||
*/
|
||||
public ScoreType scoreType() {
|
||||
return scoreType;
|
||||
public ScoreMode scoreMode() {
|
||||
return scoreMode;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -187,7 +186,7 @@ public class HasChildQueryBuilder extends AbstractQueryBuilder<HasChildQueryBuil
|
|||
builder.field("query");
|
||||
query.toXContent(builder, params);
|
||||
builder.field("child_type", type);
|
||||
builder.field("score_type", scoreType.name().toLowerCase(Locale.ROOT));
|
||||
builder.field("score_mode", scoreMode.name().toLowerCase(Locale.ROOT));
|
||||
builder.field("min_children", minChildren);
|
||||
builder.field("max_children", maxChildren);
|
||||
printBoostAndQueryName(builder);
|
||||
|
@ -254,32 +253,7 @@ public class HasChildQueryBuilder extends AbstractQueryBuilder<HasChildQueryBuil
|
|||
if (maxChildren == 0) {
|
||||
maxChildren = Integer.MAX_VALUE;
|
||||
}
|
||||
return new LateParsingQuery(parentDocMapper.typeFilter(), innerQuery, minChildren(), maxChildren, parentType, scoreTypeToScoreMode(scoreType), parentChildIndexFieldData);
|
||||
}
|
||||
|
||||
static ScoreMode scoreTypeToScoreMode(ScoreType scoreType) {
|
||||
ScoreMode scoreMode;
|
||||
// TODO: move entirely over from ScoreType to org.apache.lucene.join.ScoreMode, when we drop the 1.x parent child code.
|
||||
switch (scoreType) {
|
||||
case NONE:
|
||||
scoreMode = ScoreMode.None;
|
||||
break;
|
||||
case MIN:
|
||||
scoreMode = ScoreMode.Min;
|
||||
break;
|
||||
case MAX:
|
||||
scoreMode = ScoreMode.Max;
|
||||
break;
|
||||
case SUM:
|
||||
scoreMode = ScoreMode.Total;
|
||||
break;
|
||||
case AVG:
|
||||
scoreMode = ScoreMode.Avg;
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("score type [" + scoreType + "] not supported");
|
||||
}
|
||||
return scoreMode;
|
||||
return new LateParsingQuery(parentDocMapper.typeFilter(), innerQuery, minChildren(), maxChildren, parentType, scoreMode, parentChildIndexFieldData);
|
||||
}
|
||||
|
||||
final static class LateParsingQuery extends Query {
|
||||
|
@ -304,8 +278,12 @@ public class HasChildQueryBuilder extends AbstractQueryBuilder<HasChildQueryBuil
|
|||
|
||||
@Override
|
||||
public Query rewrite(IndexReader reader) throws IOException {
|
||||
IndexSearcher indexSearcher = new IndexSearcher(reader);
|
||||
if (getBoost() != 1.0F) {
|
||||
return super.rewrite(reader);
|
||||
}
|
||||
String joinField = ParentFieldMapper.joinField(parentType);
|
||||
IndexSearcher indexSearcher = new IndexSearcher(reader);
|
||||
indexSearcher.setQueryCache(null);
|
||||
IndexParentChildFieldData indexParentChildFieldData = parentChildIndexFieldData.loadGlobal(indexSearcher.getIndexReader());
|
||||
MultiDocValues.OrdinalMap ordinalMap = ParentChildIndexFieldData.getOrdinalMap(indexParentChildFieldData, parentType);
|
||||
return JoinUtil.createJoinQuery(joinField, innerQuery, toQuery, indexSearcher, scoreMode, ordinalMap, minChildren, maxChildren);
|
||||
|
@ -361,7 +339,7 @@ public class HasChildQueryBuilder extends AbstractQueryBuilder<HasChildQueryBuil
|
|||
protected boolean doEquals(HasChildQueryBuilder that) {
|
||||
return Objects.equals(query, that.query)
|
||||
&& Objects.equals(type, that.type)
|
||||
&& Objects.equals(scoreType, that.scoreType)
|
||||
&& Objects.equals(scoreMode, that.scoreMode)
|
||||
&& Objects.equals(minChildren, that.minChildren)
|
||||
&& Objects.equals(maxChildren, that.maxChildren)
|
||||
&& Objects.equals(queryInnerHits, that.queryInnerHits);
|
||||
|
@ -369,7 +347,7 @@ public class HasChildQueryBuilder extends AbstractQueryBuilder<HasChildQueryBuil
|
|||
|
||||
@Override
|
||||
protected int doHashCode() {
|
||||
return Objects.hash(query, type, scoreType, minChildren, maxChildren, queryInnerHits);
|
||||
return Objects.hash(query, type, scoreMode, minChildren, maxChildren, queryInnerHits);
|
||||
}
|
||||
|
||||
protected HasChildQueryBuilder(StreamInput in) throws IOException {
|
||||
|
@ -377,7 +355,7 @@ public class HasChildQueryBuilder extends AbstractQueryBuilder<HasChildQueryBuil
|
|||
minChildren = in.readInt();
|
||||
maxChildren = in.readInt();
|
||||
final int ordinal = in.readVInt();
|
||||
scoreType = ScoreType.values()[ordinal];
|
||||
scoreMode = ScoreMode.values()[ordinal];
|
||||
query = in.readQuery();
|
||||
if (in.readBoolean()) {
|
||||
queryInnerHits = new QueryInnerHits(in);
|
||||
|
@ -394,7 +372,7 @@ public class HasChildQueryBuilder extends AbstractQueryBuilder<HasChildQueryBuil
|
|||
out.writeString(type);
|
||||
out.writeInt(minChildren());
|
||||
out.writeInt(maxChildren());
|
||||
out.writeVInt(scoreType.ordinal());
|
||||
out.writeVInt(scoreMode.ordinal());
|
||||
out.writeQuery(query);
|
||||
if (queryInnerHits != null) {
|
||||
out.writeBoolean(true);
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
package org.elasticsearch.index.query;
|
||||
|
||||
import org.apache.lucene.search.join.ScoreMode;
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
@ -43,7 +44,7 @@ public class HasChildQueryParser extends BaseQueryParser {
|
|||
XContentParser parser = parseContext.parser();
|
||||
float boost = AbstractQueryBuilder.DEFAULT_BOOST;
|
||||
String childType = null;
|
||||
ScoreType scoreType = ScoreType.NONE;
|
||||
ScoreMode scoreMode = HasChildQueryBuilder.DEFAULT_SCORE_MODE;
|
||||
int minChildren = HasChildQueryBuilder.DEFAULT_MIN_CHILDREN;
|
||||
int maxChildren = HasChildQueryBuilder.DEFAULT_MAX_CHILDREN;
|
||||
String queryName = null;
|
||||
|
@ -67,10 +68,8 @@ public class HasChildQueryParser extends BaseQueryParser {
|
|||
} else if (token.isValue()) {
|
||||
if ("type".equals(currentFieldName) || "child_type".equals(currentFieldName) || "childType".equals(currentFieldName)) {
|
||||
childType = parser.text();
|
||||
} else if ("score_type".equals(currentFieldName) || "scoreType".equals(currentFieldName)) {
|
||||
scoreType = ScoreType.fromString(parser.text());
|
||||
} else if ("score_mode".equals(currentFieldName) || "scoreMode".equals(currentFieldName)) {
|
||||
scoreType = ScoreType.fromString(parser.text());
|
||||
scoreMode = parseScoreMode(parser.text());
|
||||
} else if ("boost".equals(currentFieldName)) {
|
||||
boost = parser.floatValue();
|
||||
} else if ("min_children".equals(currentFieldName) || "minChildren".equals(currentFieldName)) {
|
||||
|
@ -84,12 +83,27 @@ public class HasChildQueryParser extends BaseQueryParser {
|
|||
}
|
||||
}
|
||||
}
|
||||
HasChildQueryBuilder hasChildQueryBuilder = new HasChildQueryBuilder(childType, iqb, maxChildren, minChildren, scoreType, queryInnerHits);
|
||||
HasChildQueryBuilder hasChildQueryBuilder = new HasChildQueryBuilder(childType, iqb, maxChildren, minChildren, scoreMode, queryInnerHits);
|
||||
hasChildQueryBuilder.queryName(queryName);
|
||||
hasChildQueryBuilder.boost(boost);
|
||||
return hasChildQueryBuilder;
|
||||
}
|
||||
|
||||
public static ScoreMode parseScoreMode(String scoreModeString) {
|
||||
if ("none".equals(scoreModeString)) {
|
||||
return ScoreMode.None;
|
||||
} else if ("min".equals(scoreModeString)) {
|
||||
return ScoreMode.Min;
|
||||
} else if ("max".equals(scoreModeString)) {
|
||||
return ScoreMode.Max;
|
||||
} else if ("avg".equals(scoreModeString)) {
|
||||
return ScoreMode.Avg;
|
||||
} else if ("total".equals(scoreModeString)) {
|
||||
return ScoreMode.Total;
|
||||
}
|
||||
throw new IllegalArgumentException("No score mode for child query [" + scoreModeString + "] found");
|
||||
}
|
||||
|
||||
@Override
|
||||
public HasChildQueryBuilder getBuilderPrototype() {
|
||||
return HasChildQueryBuilder.PROTOTYPE;
|
||||
|
|
|
@ -43,9 +43,10 @@ import java.util.Set;
|
|||
public class HasParentQueryBuilder extends AbstractQueryBuilder<HasParentQueryBuilder> {
|
||||
|
||||
public static final String NAME = "has_parent";
|
||||
public static final boolean DEFAULT_SCORE = false;
|
||||
private final QueryBuilder query;
|
||||
private final String type;
|
||||
private boolean score = false;
|
||||
private boolean score = DEFAULT_SCORE;
|
||||
private QueryInnerHits innerHit;
|
||||
|
||||
/**
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
*/
|
||||
package org.elasticsearch.index.query;
|
||||
|
||||
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
@ -25,12 +26,11 @@ import org.elasticsearch.index.query.support.QueryInnerHits;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
public class HasParentQueryParser extends BaseQueryParser {
|
||||
|
||||
private static final HasParentQueryBuilder PROTOTYPE = new HasParentQueryBuilder("", EmptyQueryBuilder.PROTOTYPE);
|
||||
private static final ParseField QUERY_FIELD = new ParseField("query", "filter");
|
||||
private static final ParseField SCORE_FIELD = new ParseField("score_type", "score_mode").withAllDeprecated("score");
|
||||
private static final ParseField SCORE_FIELD = new ParseField("score_mode").withAllDeprecated("score");
|
||||
private static final ParseField TYPE_FIELD = new ParseField("parent_type", "type");
|
||||
|
||||
@Override
|
||||
|
@ -44,7 +44,7 @@ public class HasParentQueryParser extends BaseQueryParser {
|
|||
|
||||
float boost = AbstractQueryBuilder.DEFAULT_BOOST;
|
||||
String parentType = null;
|
||||
boolean score = false;
|
||||
boolean score = HasParentQueryBuilder.DEFAULT_SCORE;
|
||||
String queryName = null;
|
||||
QueryInnerHits innerHits = null;
|
||||
|
||||
|
@ -55,10 +55,6 @@ public class HasParentQueryParser extends BaseQueryParser {
|
|||
if (token == XContentParser.Token.FIELD_NAME) {
|
||||
currentFieldName = parser.currentName();
|
||||
} else if (token == XContentParser.Token.START_OBJECT) {
|
||||
// Usually, the query would be parsed here, but the child
|
||||
// type may not have been extracted yet, so use the
|
||||
// XContentStructure.<type> facade to parse if available,
|
||||
// or delay parsing if not.
|
||||
if (parseContext.parseFieldMatcher().match(currentFieldName, QUERY_FIELD)) {
|
||||
iqb = parseContext.parseInnerQueryBuilder();
|
||||
} else if ("inner_hits".equals(currentFieldName)) {
|
||||
|
@ -70,12 +66,13 @@ public class HasParentQueryParser extends BaseQueryParser {
|
|||
if (parseContext.parseFieldMatcher().match(currentFieldName, TYPE_FIELD)) {
|
||||
parentType = parser.text();
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, SCORE_FIELD)) {
|
||||
// deprecated we use a boolean now
|
||||
String scoreTypeValue = parser.text();
|
||||
if ("score".equals(scoreTypeValue)) {
|
||||
String scoreModeValue = parser.text();
|
||||
if ("score".equals(scoreModeValue)) {
|
||||
score = true;
|
||||
} else if ("none".equals(scoreTypeValue)) {
|
||||
} else if ("none".equals(scoreModeValue)) {
|
||||
score = false;
|
||||
} else {
|
||||
throw new QueryParsingException(parseContext, "[has_parent] query does not support [" + scoreModeValue + "] as an option for score_mode");
|
||||
}
|
||||
} else if ("score".equals(currentFieldName)) {
|
||||
score = parser.booleanValue();
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
|
||||
package org.elasticsearch.index.query;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import org.apache.lucene.analysis.Analyzer;
|
||||
import org.apache.lucene.index.Fields;
|
||||
import org.apache.lucene.queries.TermsQuery;
|
||||
|
@ -41,7 +40,13 @@ import org.elasticsearch.index.query.MoreLikeThisQueryBuilder.Item;
|
|||
import org.elasticsearch.search.internal.SearchContext;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.elasticsearch.index.mapper.Uid.createUidAsBytes;
|
||||
|
||||
|
@ -178,7 +183,7 @@ public class MoreLikeThisQueryParser extends BaseQueryParserTemp {
|
|||
likeItems.add(Item.parse(parser, parseContext.parseFieldMatcher(), new Item()));
|
||||
}
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, Field.STOP_WORDS)) {
|
||||
Set<String> stopWords = Sets.newHashSet();
|
||||
Set<String> stopWords = new HashSet<>();
|
||||
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
|
||||
stopWords.add(parser.text());
|
||||
}
|
||||
|
|
|
@ -1,71 +0,0 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.elasticsearch.index.query;
|
||||
|
||||
|
||||
/**
|
||||
* Defines how scores from child documents are mapped into the parent document.
|
||||
*/
|
||||
public enum ScoreType {
|
||||
/**
|
||||
* Only the lowest score of all matching child documents is mapped into the
|
||||
* parent.
|
||||
*/
|
||||
MIN,
|
||||
/**
|
||||
* Only the highest score of all matching child documents is mapped into the
|
||||
* parent.
|
||||
*/
|
||||
MAX,
|
||||
|
||||
/**
|
||||
* The average score based on all matching child documents are mapped into
|
||||
* the parent.
|
||||
*/
|
||||
AVG,
|
||||
|
||||
/**
|
||||
* The matching children scores is summed up and mapped into the parent.
|
||||
*/
|
||||
SUM,
|
||||
|
||||
/**
|
||||
* Scores are not taken into account
|
||||
*/
|
||||
NONE;
|
||||
|
||||
|
||||
public static ScoreType fromString(String type) {
|
||||
if ("none".equals(type)) {
|
||||
return NONE;
|
||||
} else if ("min".equals(type)) {
|
||||
return MIN;
|
||||
} else if ("max".equals(type)) {
|
||||
return MAX;
|
||||
} else if ("avg".equals(type)) {
|
||||
return AVG;
|
||||
} else if ("sum".equals(type)) {
|
||||
return SUM;
|
||||
} else if ("total".equals(type)) { // This name is consistent with: ScoreMode.Total
|
||||
return SUM;
|
||||
}
|
||||
throw new IllegalArgumentException("No score type for child query [" + type + "] found");
|
||||
}
|
||||
|
||||
}
|
|
@ -89,8 +89,7 @@ import java.util.Locale;
|
|||
* <p>
|
||||
* See {@link GaussDecayFunctionBuilder} and {@link GaussDecayFunctionParser}
|
||||
* for an example. The parser furthermore needs to be registered in the
|
||||
* {@link org.elasticsearch.index.query.functionscore.FunctionScoreModule
|
||||
* FunctionScoreModule}.
|
||||
* {@link org.elasticsearch.search.SearchModule SearchModule}.
|
||||
*
|
||||
* **/
|
||||
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue