Skip to content

Commit e70e3d6

Browse files
authored
Minor FieldTypeLookup tweaks (elastic#63944)
Remove the default constructor, make the class final and adjust visibility of its methods: if the class is package private, it makes little sense to have public methods.
1 parent 6895485 commit e70e3d6

File tree

3 files changed

+5
-15
lines changed

3 files changed

+5
-15
lines changed

server/src/main/java/org/elasticsearch/index/mapper/FieldTypeLookup.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import org.elasticsearch.common.regex.Regex;
2424

2525
import java.util.Collection;
26-
import java.util.Collections;
2726
import java.util.HashMap;
2827
import java.util.HashSet;
2928
import java.util.Iterator;
@@ -33,7 +32,7 @@
3332
/**
3433
* An immutable container for looking up {@link MappedFieldType}s by their name.
3534
*/
36-
class FieldTypeLookup implements Iterable<MappedFieldType> {
35+
final class FieldTypeLookup implements Iterable<MappedFieldType> {
3736

3837
private final Map<String, MappedFieldType> fullNameToFieldType = new HashMap<>();
3938
private final Map<String, String> aliasToConcreteName = new HashMap<>();
@@ -48,10 +47,6 @@ class FieldTypeLookup implements Iterable<MappedFieldType> {
4847
private final Map<String, Set<String>> fieldToCopiedFields = new HashMap<>();
4948
private final DynamicKeyFieldTypeLookup dynamicKeyLookup;
5049

51-
FieldTypeLookup() {
52-
this(Collections.emptyList(), Collections.emptyList());
53-
}
54-
5550
FieldTypeLookup(Collection<FieldMapper> fieldMappers,
5651
Collection<FieldAliasMapper> fieldAliasMappers) {
5752
Map<String, DynamicKeyFieldMapper> dynamicKeyMappers = new HashMap<>();
@@ -87,7 +82,7 @@ class FieldTypeLookup implements Iterable<MappedFieldType> {
8782
/**
8883
* Returns the mapped field type for the given field name.
8984
*/
90-
public MappedFieldType get(String field) {
85+
MappedFieldType get(String field) {
9186
String concreteField = aliasToConcreteName.getOrDefault(field, field);
9287
MappedFieldType fieldType = fullNameToFieldType.get(concreteField);
9388
if (fieldType != null) {
@@ -102,7 +97,7 @@ public MappedFieldType get(String field) {
10297
/**
10398
* Returns a list of the full names of a simple match regex like pattern against full name and index name.
10499
*/
105-
public Set<String> simpleMatchToFullName(String pattern) {
100+
Set<String> simpleMatchToFullName(String pattern) {
106101
Set<String> fields = new HashSet<>();
107102
for (MappedFieldType fieldType : this) {
108103
if (Regex.simpleMatch(pattern, fieldType.name())) {
@@ -129,7 +124,7 @@ public Set<String> simpleMatchToFullName(String pattern) {
129124
* should be a concrete field and *not* an alias.
130125
* @return A set of paths in the _source that contain the field's values.
131126
*/
132-
public Set<String> sourcePaths(String field) {
127+
Set<String> sourcePaths(String field) {
133128
String resolvedField = field;
134129
int lastDotIndex = field.lastIndexOf('.');
135130
if (lastDotIndex > 0) {

server/src/test/java/org/elasticsearch/index/mapper/FieldTypeLookupTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
public class FieldTypeLookupTests extends ESTestCase {
3434

3535
public void testEmpty() {
36-
FieldTypeLookup lookup = new FieldTypeLookup();
36+
FieldTypeLookup lookup = new FieldTypeLookup(Collections.emptyList(), Collections.emptyList());
3737
assertNull(lookup.get("foo"));
3838
Collection<String> names = lookup.simpleMatchToFullName("foo");
3939
assertNotNull(names);

test/framework/src/main/java/org/elasticsearch/test/AbstractBuilderTestCase.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
import org.elasticsearch.index.cache.bitset.BitsetFilterCache;
5353
import org.elasticsearch.index.fielddata.IndexFieldDataCache;
5454
import org.elasticsearch.index.fielddata.IndexFieldDataService;
55-
import org.elasticsearch.index.mapper.MappedFieldType;
5655
import org.elasticsearch.index.mapper.MapperService;
5756
import org.elasticsearch.index.query.QueryShardContext;
5857
import org.elasticsearch.index.shard.ShardId;
@@ -203,10 +202,6 @@ protected static String expectedFieldName(String builderFieldName) {
203202
return ALIAS_TO_CONCRETE_FIELD_NAME.getOrDefault(builderFieldName, builderFieldName);
204203
}
205204

206-
protected Iterable<MappedFieldType> getMapping() {
207-
return serviceHolder.mapperService.fieldTypes();
208-
}
209-
210205
@AfterClass
211206
public static void afterClass() throws Exception {
212207
IOUtils.close(serviceHolder);

0 commit comments

Comments
 (0)