99
1010package 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