Skip to content

Commit

Permalink
Remove some more usages of ParseFieldMatcher in favour of using Parse…
Browse files Browse the repository at this point in the history
…Field directly

Relates to #19552
Relates to #22130
  • Loading branch information
javanna committed Dec 30, 2016
1 parent 6c54cba commit df2acb3
Show file tree
Hide file tree
Showing 24 changed files with 109 additions and 109 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public T lookupReturningNullIfNotFound(String name, ParseFieldMatcher parseField
}
ParseField parseField = parseFieldAndValue.v1();
T value = parseFieldAndValue.v2();
boolean match = parseFieldMatcher.match(name, parseField);
boolean match = parseField.match(name);
//this is always expected to match, ParseField is useful for deprecation warnings etc. here
assert match : "ParseField did not match registered name [" + name + "][" + registryName + "]";
return value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,15 +359,15 @@ public static Item parse(XContentParser parser, ParseFieldMatcher parseFieldMatc
if (token == XContentParser.Token.FIELD_NAME) {
currentFieldName = parser.currentName();
} else if (currentFieldName != null) {
if (parseFieldMatcher.match(currentFieldName, Field.INDEX)) {
if (Field.INDEX.match(currentFieldName)) {
item.index = parser.text();
} else if (parseFieldMatcher.match(currentFieldName, Field.TYPE)) {
} else if (Field.TYPE.match(currentFieldName)) {
item.type = parser.text();
} else if (parseFieldMatcher.match(currentFieldName, Field.ID)) {
} else if (Field.ID.match(currentFieldName)) {
item.id = parser.text();
} else if (parseFieldMatcher.match(currentFieldName, Field.DOC)) {
} else if (Field.DOC.match(currentFieldName)) {
item.doc = jsonBuilder().copyCurrentStructure(parser).bytes();
} else if (parseFieldMatcher.match(currentFieldName, Field.FIELDS)) {
} else if (Field.FIELDS.match(currentFieldName)) {
if (token == XContentParser.Token.START_ARRAY) {
List<String> fields = new ArrayList<>();
while (parser.nextToken() != XContentParser.Token.END_ARRAY) {
Expand All @@ -378,7 +378,7 @@ public static Item parse(XContentParser parser, ParseFieldMatcher parseFieldMatc
throw new ElasticsearchParseException(
"failed to parse More Like This item. field [fields] must be an array");
}
} else if (parseFieldMatcher.match(currentFieldName, Field.PER_FIELD_ANALYZER)) {
} else if (Field.PER_FIELD_ANALYZER.match(currentFieldName)) {
item.perFieldAnalyzer(TermVectorsRequest.readPerFieldAnalyzer(parser.map()));
} else if ("_routing".equals(currentFieldName) || "routing".equals(currentFieldName)) {
item.routing = parser.text();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public XContentParser parser() {
}

public boolean isDeprecatedSetting(String setting) {
return this.parseFieldMatcher.match(setting, CACHE) || this.parseFieldMatcher.match(setting, CACHE_KEY);
return this.CACHE.match(setting) || this.CACHE_KEY.match(setting);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -524,24 +524,24 @@ public static BlobStoreIndexShardSnapshot fromXContent(XContentParser parser) th
String currentFieldName = parser.currentName();
token = parser.nextToken();
if (token.isValue()) {
if (parseFieldMatcher.match(currentFieldName, PARSE_NAME)) {
if (PARSE_NAME.match(currentFieldName)) {
snapshot = parser.text();
} else if (parseFieldMatcher.match(currentFieldName, PARSE_INDEX_VERSION)) {
} else if (PARSE_INDEX_VERSION.match(currentFieldName)) {
// The index-version is needed for backward compatibility with v 1.0
indexVersion = parser.longValue();
} else if (parseFieldMatcher.match(currentFieldName, PARSE_START_TIME)) {
} else if (PARSE_START_TIME.match(currentFieldName)) {
startTime = parser.longValue();
} else if (parseFieldMatcher.match(currentFieldName, PARSE_TIME)) {
} else if (PARSE_TIME.match(currentFieldName)) {
time = parser.longValue();
} else if (parseFieldMatcher.match(currentFieldName, PARSE_NUMBER_OF_FILES)) {
} else if (PARSE_NUMBER_OF_FILES.match(currentFieldName)) {
numberOfFiles = parser.intValue();
} else if (parseFieldMatcher.match(currentFieldName, PARSE_TOTAL_SIZE)) {
} else if (PARSE_TOTAL_SIZE.match(currentFieldName)) {
totalSize = parser.longValue();
} else {
throw new ElasticsearchParseException("unknown parameter [{}]", currentFieldName);
}
} else if (token == XContentParser.Token.START_ARRAY) {
if (parseFieldMatcher.match(currentFieldName, PARSE_FILES)) {
if (PARSE_FILES.match(currentFieldName)) {
while ((parser.nextToken()) != XContentParser.Token.END_ARRAY) {
indexFiles.add(FileInfo.fromXContent(parser));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,15 +245,15 @@ public static BlobStoreIndexShardSnapshots fromXContent(XContentParser parser) t
String currentFieldName = parser.currentName();
token = parser.nextToken();
if (token == XContentParser.Token.START_ARRAY) {
if (parseFieldMatcher.match(currentFieldName, ParseFields.FILES) == false) {
if (ParseFields.FILES.match(currentFieldName) == false) {
throw new ElasticsearchParseException("unknown array [{}]", currentFieldName);
}
while (parser.nextToken() != XContentParser.Token.END_ARRAY) {
FileInfo fileInfo = FileInfo.fromXContent(parser);
files.put(fileInfo.name(), fileInfo);
}
} else if (token == XContentParser.Token.START_OBJECT) {
if (parseFieldMatcher.match(currentFieldName, ParseFields.SNAPSHOTS) == false) {
if (ParseFields.SNAPSHOTS.match(currentFieldName) == false) {
throw new ElasticsearchParseException("unknown object [{}]", currentFieldName);
}
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
Expand All @@ -268,7 +268,7 @@ public static BlobStoreIndexShardSnapshots fromXContent(XContentParser parser) t
if (token == XContentParser.Token.FIELD_NAME) {
currentFieldName = parser.currentName();
if (parser.nextToken() == XContentParser.Token.START_ARRAY) {
if (parseFieldMatcher.match(currentFieldName, ParseFields.FILES) == false) {
if (ParseFields.FILES.match(currentFieldName) == false) {
throw new ElasticsearchParseException("unknown array [{}]", currentFieldName);
}
List<String> fileNames = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ static void buildFromContent(XContentParser parser, AnalyzeRequest analyzeReques
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
if (token == XContentParser.Token.FIELD_NAME) {
currentFieldName = parser.currentName();
} else if (parseFieldMatcher.match(currentFieldName, Fields.TEXT) && token == XContentParser.Token.VALUE_STRING) {
} else if (Fields.TEXT.match(currentFieldName) && token == XContentParser.Token.VALUE_STRING) {
analyzeRequest.text(parser.text());
} else if (parseFieldMatcher.match(currentFieldName, Fields.TEXT) && token == XContentParser.Token.START_ARRAY) {
} else if (Fields.TEXT.match(currentFieldName) && token == XContentParser.Token.START_ARRAY) {
List<String> texts = new ArrayList<>();
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
if (token.isValue() == false) {
Expand All @@ -94,19 +94,19 @@ static void buildFromContent(XContentParser parser, AnalyzeRequest analyzeReques
texts.add(parser.text());
}
analyzeRequest.text(texts.toArray(new String[texts.size()]));
} else if (parseFieldMatcher.match(currentFieldName, Fields.ANALYZER) && token == XContentParser.Token.VALUE_STRING) {
} else if (Fields.ANALYZER.match(currentFieldName) && token == XContentParser.Token.VALUE_STRING) {
analyzeRequest.analyzer(parser.text());
} else if (parseFieldMatcher.match(currentFieldName, Fields.FIELD) && token == XContentParser.Token.VALUE_STRING) {
} else if (Fields.FIELD.match(currentFieldName) && token == XContentParser.Token.VALUE_STRING) {
analyzeRequest.field(parser.text());
} else if (parseFieldMatcher.match(currentFieldName, Fields.TOKENIZER)) {
} else if (Fields.TOKENIZER.match(currentFieldName)) {
if (token == XContentParser.Token.VALUE_STRING) {
analyzeRequest.tokenizer(parser.text());
} else if (token == XContentParser.Token.START_OBJECT) {
analyzeRequest.tokenizer(parser.map());
} else {
throw new IllegalArgumentException(currentFieldName + " should be tokenizer's name or setting");
}
} else if (parseFieldMatcher.match(currentFieldName, Fields.TOKEN_FILTERS)
} else if (Fields.TOKEN_FILTERS.match(currentFieldName)
&& token == XContentParser.Token.START_ARRAY) {
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
if (token == XContentParser.Token.VALUE_STRING) {
Expand All @@ -118,7 +118,7 @@ static void buildFromContent(XContentParser parser, AnalyzeRequest analyzeReques
+ " array element should contain filter's name or setting");
}
}
} else if (parseFieldMatcher.match(currentFieldName, Fields.CHAR_FILTERS)
} else if (Fields.CHAR_FILTERS.match(currentFieldName)
&& token == XContentParser.Token.START_ARRAY) {
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
if (token == XContentParser.Token.VALUE_STRING) {
Expand All @@ -130,13 +130,13 @@ static void buildFromContent(XContentParser parser, AnalyzeRequest analyzeReques
+ " array element should contain char filter's name or setting");
}
}
} else if (parseFieldMatcher.match(currentFieldName, Fields.EXPLAIN)) {
} else if (Fields.EXPLAIN.match(currentFieldName)) {
if (parser.isBooleanValue()) {
analyzeRequest.explain(parser.booleanValue());
} else {
throw new IllegalArgumentException(currentFieldName + " must be either 'true' or 'false'");
}
} else if (parseFieldMatcher.match(currentFieldName, Fields.ATTRIBUTES) && token == XContentParser.Token.START_ARRAY) {
} else if (Fields.ATTRIBUTES.match(currentFieldName) && token == XContentParser.Token.START_ARRAY) {
List<String> attributes = new ArrayList<>();
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
if (token.isValue() == false) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public ParseField parseField() {
public static SubAggCollectionMode parse(String value, ParseFieldMatcher parseFieldMatcher) {
SubAggCollectionMode[] modes = SubAggCollectionMode.values();
for (SubAggCollectionMode mode : modes) {
if (parseFieldMatcher.match(value, mode.parseField)) {
if (mode.parseField.match(value)) {
return mode;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,17 +134,17 @@ public static Range fromXContent(XContentParser parser, ParseFieldMatcher parseF
if (token == XContentParser.Token.FIELD_NAME) {
currentFieldName = parser.currentName();
} else if (token == XContentParser.Token.VALUE_NUMBER) {
if (parseFieldMatcher.match(currentFieldName, FROM_FIELD)) {
if (FROM_FIELD.match(currentFieldName)) {
from = parser.doubleValue();
} else if (parseFieldMatcher.match(currentFieldName, TO_FIELD)) {
} else if (TO_FIELD.match(currentFieldName)) {
to = parser.doubleValue();
}
} else if (token == XContentParser.Token.VALUE_STRING) {
if (parseFieldMatcher.match(currentFieldName, FROM_FIELD)) {
if (FROM_FIELD.match(currentFieldName)) {
fromAsStr = parser.text();
} else if (parseFieldMatcher.match(currentFieldName, TO_FIELD)) {
} else if (TO_FIELD.match(currentFieldName)) {
toAsStr = parser.text();
} else if (parseFieldMatcher.match(currentFieldName, KEY_FIELD)) {
} else if (KEY_FIELD.match(currentFieldName)) {
key = parser.text();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,17 +180,17 @@ private static Range parseRange(XContentParser parser, QueryParseContext context
if (token == XContentParser.Token.FIELD_NAME) {
toOrFromOrKey = parser.currentName();
} else if (token == XContentParser.Token.VALUE_NUMBER) {
if (parseFieldMatcher.match(toOrFromOrKey, Range.FROM_FIELD)) {
if (Range.FROM_FIELD.match(toOrFromOrKey)) {
from = parser.doubleValue();
} else if (parseFieldMatcher.match(toOrFromOrKey, Range.TO_FIELD)) {
} else if (Range.TO_FIELD.match(toOrFromOrKey)) {
to = parser.doubleValue();
}
} else if (token == XContentParser.Token.VALUE_STRING) {
if (parseFieldMatcher.match(toOrFromOrKey, Range.KEY_FIELD)) {
if (Range.KEY_FIELD.match(toOrFromOrKey)) {
key = parser.text();
} else if (parseFieldMatcher.match(toOrFromOrKey, Range.FROM_FIELD)) {
} else if (Range.FROM_FIELD.match(toOrFromOrKey)) {
fromAsStr = parser.text();
} else if (parseFieldMatcher.match(toOrFromOrKey, Range.TO_FIELD)) {
} else if (Range.TO_FIELD.match(toOrFromOrKey)) {
toAsStr = parser.text();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ boolean needsGlobalOrdinals() {

public static ExecutionMode fromString(String value, ParseFieldMatcher parseFieldMatcher) {
for (ExecutionMode mode : values()) {
if (parseFieldMatcher.match(value, mode.parseField)) {
if (mode.parseField.match(value)) {
return mode;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ Aggregator create(String name, AggregatorFactories factories, ValuesSource value

public static ExecutionMode fromString(String value, ParseFieldMatcher parseFieldMatcher) {
for (ExecutionMode mode : values()) {
if (parseFieldMatcher.match(value, mode.parseField)) {
if (mode.parseField.match(value)) {
return mode;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ boolean needsGlobalOrdinals() {

public static ExecutionMode fromString(String value, ParseFieldMatcher parseFieldMatcher) {
for (ExecutionMode mode : values()) {
if (parseFieldMatcher.match(value, mode.parseField)) {
if (mode.parseField.match(value)) {
return mode;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,11 @@ public static IncludeExclude parseInclude(XContentParser parser, QueryParseConte
} else
// This "include":{"pattern":"foo.*"} syntax is undocumented since 2.0
// Regexes should be "include":"foo.*"
if (parseFieldMatcher.match(currentFieldName, PATTERN_FIELD)) {
if (PATTERN_FIELD.match(currentFieldName)) {
return new IncludeExclude(parser.text(), null);
} else if (parseFieldMatcher.match(currentFieldName, NUM_PARTITIONS_FIELD)) {
} else if (NUM_PARTITIONS_FIELD.match(currentFieldName)) {
numPartitions = parser.intValue();
} else if (parseFieldMatcher.match(currentFieldName, PARTITION_FIELD)) {
} else if (PARTITION_FIELD.match(currentFieldName)) {
partition = parser.intValue();
} else {
throw new ElasticsearchParseException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public static SeasonalityType parse(String text, ParseFieldMatcher parseFieldMat
}
SeasonalityType result = null;
for (SeasonalityType policy : values()) {
if (parseFieldMatcher.match(text, policy.parseField)) {
if (policy.parseField.match(text)) {
result = policy;
break;
}
Expand Down
Loading

0 comments on commit df2acb3

Please sign in to comment.