@@ -51,29 +51,41 @@ public interface DocValueFormat extends NamedWriteable {
51
51
/** Format a long value. This is used by terms and histogram aggregations
52
52
* to format keys for fields that use longs as a doc value representation
53
53
* such as the {@code long} and {@code date} fields. */
54
- Object format (long value );
54
+ default Object format (long value ) {
55
+ throw new UnsupportedOperationException ();
56
+ }
55
57
56
58
/** Format a double value. This is used by terms and stats aggregations
57
59
* to format keys for fields that use numbers as a doc value representation
58
60
* such as the {@code long}, {@code double} or {@code date} fields. */
59
- Object format (double value );
61
+ default Object format (double value ) {
62
+ throw new UnsupportedOperationException ();
63
+ }
60
64
61
65
/** Format a binary value. This is used by terms aggregations to format
62
66
* keys for fields that use binary doc value representations such as the
63
67
* {@code keyword} and {@code ip} fields. */
64
- Object format (BytesRef value );
68
+ default Object format (BytesRef value ) {
69
+ throw new UnsupportedOperationException ();
70
+ }
65
71
66
72
/** Parse a value that was formatted with {@link #format(long)} back to the
67
73
* original long value. */
68
- long parseLong (String value , boolean roundUp , LongSupplier now );
74
+ default long parseLong (String value , boolean roundUp , LongSupplier now ) {
75
+ throw new UnsupportedOperationException ();
76
+ }
69
77
70
78
/** Parse a value that was formatted with {@link #format(double)} back to
71
79
* the original double value. */
72
- double parseDouble (String value , boolean roundUp , LongSupplier now );
80
+ default double parseDouble (String value , boolean roundUp , LongSupplier now ) {
81
+ throw new UnsupportedOperationException ();
82
+ }
73
83
74
84
/** Parse a value that was formatted with {@link #format(BytesRef)} back
75
85
* to the original BytesRef. */
76
- BytesRef parseBytesRef (String value );
86
+ default BytesRef parseBytesRef (String value ) {
87
+ throw new UnsupportedOperationException ();
88
+ }
77
89
78
90
DocValueFormat RAW = new DocValueFormat () {
79
91
@@ -83,7 +95,7 @@ public String getWriteableName() {
83
95
}
84
96
85
97
@ Override
86
- public void writeTo (StreamOutput out ) throws IOException {
98
+ public void writeTo (StreamOutput out ) {
87
99
}
88
100
89
101
@ Override
@@ -131,17 +143,7 @@ public String getWriteableName() {
131
143
}
132
144
133
145
@ Override
134
- public void writeTo (StreamOutput out ) throws IOException {
135
- }
136
-
137
- @ Override
138
- public Object format (long value ) {
139
- throw new UnsupportedOperationException ();
140
- }
141
-
142
- @ Override
143
- public Object format (double value ) {
144
- throw new UnsupportedOperationException ();
146
+ public void writeTo (StreamOutput out ) {
145
147
}
146
148
147
149
@ Override
@@ -151,16 +153,6 @@ public String format(BytesRef value) {
151
153
.encodeToString (Arrays .copyOfRange (value .bytes , value .offset , value .offset + value .length ));
152
154
}
153
155
154
- @ Override
155
- public long parseLong (String value , boolean roundUp , LongSupplier now ) {
156
- throw new UnsupportedOperationException ();
157
- }
158
-
159
- @ Override
160
- public double parseDouble (String value , boolean roundUp , LongSupplier now ) {
161
- throw new UnsupportedOperationException ();
162
- }
163
-
164
156
@ Override
165
157
public BytesRef parseBytesRef (String value ) {
166
158
return new BytesRef (Base64 .getDecoder ().decode (value ));
@@ -209,11 +201,6 @@ public String format(double value) {
209
201
return format ((long ) value );
210
202
}
211
203
212
- @ Override
213
- public String format (BytesRef value ) {
214
- throw new UnsupportedOperationException ();
215
- }
216
-
217
204
@ Override
218
205
public long parseLong (String value , boolean roundUp , LongSupplier now ) {
219
206
return parser .parse (value , now , roundUp , DateUtils .dateTimeZoneToZoneId (timeZone ));
@@ -223,11 +210,6 @@ public long parseLong(String value, boolean roundUp, LongSupplier now) {
223
210
public double parseDouble (String value , boolean roundUp , LongSupplier now ) {
224
211
return parseLong (value , roundUp , now );
225
212
}
226
-
227
- @ Override
228
- public BytesRef parseBytesRef (String value ) {
229
- throw new UnsupportedOperationException ();
230
- }
231
213
}
232
214
233
215
DocValueFormat GEOHASH = new DocValueFormat () {
@@ -238,7 +220,7 @@ public String getWriteableName() {
238
220
}
239
221
240
222
@ Override
241
- public void writeTo (StreamOutput out ) throws IOException {
223
+ public void writeTo (StreamOutput out ) {
242
224
}
243
225
244
226
@ Override
@@ -250,26 +232,6 @@ public String format(long value) {
250
232
public String format (double value ) {
251
233
return format ((long ) value );
252
234
}
253
-
254
- @ Override
255
- public String format (BytesRef value ) {
256
- throw new UnsupportedOperationException ();
257
- }
258
-
259
- @ Override
260
- public long parseLong (String value , boolean roundUp , LongSupplier now ) {
261
- throw new UnsupportedOperationException ();
262
- }
263
-
264
- @ Override
265
- public double parseDouble (String value , boolean roundUp , LongSupplier now ) {
266
- throw new UnsupportedOperationException ();
267
- }
268
-
269
- @ Override
270
- public BytesRef parseBytesRef (String value ) {
271
- throw new UnsupportedOperationException ();
272
- }
273
235
};
274
236
275
237
DocValueFormat BOOLEAN = new DocValueFormat () {
@@ -280,22 +242,17 @@ public String getWriteableName() {
280
242
}
281
243
282
244
@ Override
283
- public void writeTo (StreamOutput out ) throws IOException {
245
+ public void writeTo (StreamOutput out ) {
284
246
}
285
247
286
248
@ Override
287
249
public Boolean format (long value ) {
288
- return java . lang . Boolean . valueOf ( value != 0 ) ;
250
+ return value != 0 ;
289
251
}
290
252
291
253
@ Override
292
254
public Boolean format (double value ) {
293
- return java .lang .Boolean .valueOf (value != 0 );
294
- }
295
-
296
- @ Override
297
- public String format (BytesRef value ) {
298
- throw new UnsupportedOperationException ();
255
+ return value != 0 ;
299
256
}
300
257
301
258
@ Override
@@ -313,11 +270,6 @@ public long parseLong(String value, boolean roundUp, LongSupplier now) {
313
270
public double parseDouble (String value , boolean roundUp , LongSupplier now ) {
314
271
return parseLong (value , roundUp , now );
315
272
}
316
-
317
- @ Override
318
- public BytesRef parseBytesRef (String value ) {
319
- throw new UnsupportedOperationException ();
320
- }
321
273
};
322
274
323
275
DocValueFormat IP = new DocValueFormat () {
@@ -328,17 +280,7 @@ public String getWriteableName() {
328
280
}
329
281
330
282
@ Override
331
- public void writeTo (StreamOutput out ) throws IOException {
332
- }
333
-
334
- @ Override
335
- public String format (long value ) {
336
- throw new UnsupportedOperationException ();
337
- }
338
-
339
- @ Override
340
- public String format (double value ) {
341
- throw new UnsupportedOperationException ();
283
+ public void writeTo (StreamOutput out ) {
342
284
}
343
285
344
286
@ Override
@@ -348,16 +290,6 @@ public String format(BytesRef value) {
348
290
return NetworkAddress .format (inet );
349
291
}
350
292
351
- @ Override
352
- public long parseLong (String value , boolean roundUp , LongSupplier now ) {
353
- throw new UnsupportedOperationException ();
354
- }
355
-
356
- @ Override
357
- public double parseDouble (String value , boolean roundUp , LongSupplier now ) {
358
- throw new UnsupportedOperationException ();
359
- }
360
-
361
293
@ Override
362
294
public BytesRef parseBytesRef (String value ) {
363
295
return new BytesRef (InetAddressPoint .encode (InetAddresses .forString (value )));
@@ -401,11 +333,6 @@ public String format(double value) {
401
333
return format .format (value );
402
334
}
403
335
404
- @ Override
405
- public String format (BytesRef value ) {
406
- throw new UnsupportedOperationException ();
407
- }
408
-
409
336
@ Override
410
337
public long parseLong (String value , boolean roundUp , LongSupplier now ) {
411
338
Number n ;
@@ -438,11 +365,6 @@ public double parseDouble(String value, boolean roundUp, LongSupplier now) {
438
365
return n .doubleValue ();
439
366
}
440
367
441
- @ Override
442
- public BytesRef parseBytesRef (String value ) {
443
- throw new UnsupportedOperationException ();
444
- }
445
-
446
368
@ Override
447
369
public boolean equals (Object o ) {
448
370
if (this == o ) {
0 commit comments