9
9
10
10
package org .elasticsearch .index .mapper ;
11
11
12
+ import java .util .Objects ;
13
+
12
14
/**
13
15
* What type of index structure is available for this field
14
16
*/
15
- public class IndexType {
17
+ // NB This is a class not a record because it has a private constructor
18
+ public final class IndexType {
16
19
17
20
/**
18
21
* An IndexType with no index structures or doc values
@@ -109,16 +112,10 @@ public boolean supportsSortShortcuts() {
109
112
* @return an inverted-index based IndexType
110
113
*/
111
114
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 ;
120
117
}
121
- return NONE ;
118
+ return new IndexType ( isIndexed , false , false , false , hasDocValues , false ) ;
122
119
}
123
120
124
121
/**
@@ -132,16 +129,10 @@ public static IndexType skippers() {
132
129
* @return a point-based IndexType
133
130
*/
134
131
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 ;
143
134
}
144
- return NONE ;
135
+ return new IndexType ( false , isIndexed , isIndexed , false , hasDocValues , false ) ;
145
136
}
146
137
147
138
/**
@@ -164,4 +155,40 @@ public static IndexType docValuesOnly() {
164
155
public static IndexType vectors () {
165
156
return new IndexType (false , false , false , true , false , false );
166
157
}
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
+ }
167
194
}
0 commit comments