Skip to content

Commit fc7ba8d

Browse files
authored
Add equals()/hashCode()/toString to IndexType (#136288)
1 parent 25863a5 commit fc7ba8d

File tree

1 file changed

+46
-19
lines changed

1 file changed

+46
-19
lines changed

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

Lines changed: 46 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@
99

1010
package org.elasticsearch.index.mapper;
1111

12+
import java.util.Objects;
13+
1214
/**
1315
* What type of index structure is available for this field
1416
*/
15-
public class IndexType {
17+
// NB This is a class not a record because it has a private constructor
18+
public final class IndexType {
1619

1720
/**
1821
* An IndexType with no index structures or doc values
@@ -109,16 +112,10 @@ public boolean supportsSortShortcuts() {
109112
* @return an inverted-index based IndexType
110113
*/
111114
public static IndexType terms(boolean isIndexed, boolean hasDocValues) {
112-
if (isIndexed && hasDocValues) {
113-
return new IndexType(true, false, false, false, true, false);
114-
}
115-
if (isIndexed) {
116-
return new IndexType(true, false, false, false, false, false);
117-
}
118-
if (hasDocValues) {
119-
return new IndexType(false, false, false, false, true, false);
115+
if (isIndexed == false && hasDocValues == false) {
116+
return NONE;
120117
}
121-
return NONE;
118+
return new IndexType(isIndexed, false, false, false, hasDocValues, false);
122119
}
123120

124121
/**
@@ -132,16 +129,10 @@ public static IndexType skippers() {
132129
* @return a point-based IndexType
133130
*/
134131
public static IndexType points(boolean isIndexed, boolean hasDocValues) {
135-
if (isIndexed && hasDocValues) {
136-
return new IndexType(false, true, true, false, true, false);
137-
}
138-
if (isIndexed) {
139-
return new IndexType(false, true, true, false, false, false);
140-
}
141-
if (hasDocValues) {
142-
return new IndexType(false, false, false, false, true, false);
132+
if (isIndexed == false && hasDocValues == false) {
133+
return IndexType.NONE;
143134
}
144-
return NONE;
135+
return new IndexType(false, isIndexed, isIndexed, false, hasDocValues, false);
145136
}
146137

147138
/**
@@ -164,4 +155,40 @@ public static IndexType docValuesOnly() {
164155
public static IndexType vectors() {
165156
return new IndexType(false, false, false, true, false, false);
166157
}
158+
159+
@Override
160+
public String toString() {
161+
return "IndexType{"
162+
+ "hasTerms="
163+
+ hasTerms
164+
+ ", hasPoints="
165+
+ hasPoints
166+
+ ", hasPointsMetadata="
167+
+ hasPointsMetadata
168+
+ ", hasVectors="
169+
+ hasVectors
170+
+ ", hasDocValues="
171+
+ hasDocValues
172+
+ ", hasDocValuesSkipper="
173+
+ hasDocValuesSkipper
174+
+ '}';
175+
}
176+
177+
@Override
178+
public boolean equals(Object o) {
179+
if (o instanceof IndexType indexType) {
180+
return hasTerms == indexType.hasTerms
181+
&& hasPoints == indexType.hasPoints
182+
&& hasPointsMetadata == indexType.hasPointsMetadata
183+
&& hasVectors == indexType.hasVectors
184+
&& hasDocValues == indexType.hasDocValues
185+
&& hasDocValuesSkipper == indexType.hasDocValuesSkipper;
186+
}
187+
return false;
188+
}
189+
190+
@Override
191+
public int hashCode() {
192+
return Objects.hash(hasTerms, hasPoints, hasPointsMetadata, hasVectors, hasDocValues, hasDocValuesSkipper);
193+
}
167194
}

0 commit comments

Comments
 (0)