diff --git a/plugins/analysis-icu/src/main/java/org/elasticsearch/index/mapper/ICUCollationKeywordFieldMapper.java b/plugins/analysis-icu/src/main/java/org/elasticsearch/index/mapper/ICUCollationKeywordFieldMapper.java index 2c20d4b47844e..d4cc9ee9d6e89 100644 --- a/plugins/analysis-icu/src/main/java/org/elasticsearch/index/mapper/ICUCollationKeywordFieldMapper.java +++ b/plugins/analysis-icu/src/main/java/org/elasticsearch/index/mapper/ICUCollationKeywordFieldMapper.java @@ -54,7 +54,6 @@ import java.util.List; import java.util.Map; import java.util.Objects; -import java.util.function.LongSupplier; public class ICUCollationKeywordFieldMapper extends FieldMapper { @@ -187,17 +186,7 @@ public String getWriteableName() { } @Override - public void writeTo(StreamOutput out) throws IOException { - } - - @Override - public String format(long value) { - throw new UnsupportedOperationException(); - } - - @Override - public String format(double value) { - throw new UnsupportedOperationException(); + public void writeTo(StreamOutput out) { } @Override @@ -208,16 +197,6 @@ public String format(BytesRef value) { return new String(encoded, 0, encodedLength); } - @Override - public long parseLong(String value, boolean roundUp, LongSupplier now) { - throw new UnsupportedOperationException(); - } - - @Override - public double parseDouble(String value, boolean roundUp, LongSupplier now) { - throw new UnsupportedOperationException(); - } - @Override public BytesRef parseBytesRef(String value) { char[] encoded = value.toCharArray(); diff --git a/server/src/main/java/org/elasticsearch/search/DocValueFormat.java b/server/src/main/java/org/elasticsearch/search/DocValueFormat.java index 2bcd41a820c3d..deda38f977530 100644 --- a/server/src/main/java/org/elasticsearch/search/DocValueFormat.java +++ b/server/src/main/java/org/elasticsearch/search/DocValueFormat.java @@ -52,29 +52,41 @@ public interface DocValueFormat extends NamedWriteable { /** Format a long value. This is used by terms and histogram aggregations * to format keys for fields that use longs as a doc value representation * such as the {@code long} and {@code date} fields. */ - Object format(long value); + default Object format(long value) { + throw new UnsupportedOperationException(); + } /** Format a double value. This is used by terms and stats aggregations * to format keys for fields that use numbers as a doc value representation * such as the {@code long}, {@code double} or {@code date} fields. */ - Object format(double value); + default Object format(double value) { + throw new UnsupportedOperationException(); + } /** Format a binary value. This is used by terms aggregations to format * keys for fields that use binary doc value representations such as the * {@code keyword} and {@code ip} fields. */ - Object format(BytesRef value); + default Object format(BytesRef value) { + throw new UnsupportedOperationException(); + } /** Parse a value that was formatted with {@link #format(long)} back to the * original long value. */ - long parseLong(String value, boolean roundUp, LongSupplier now); + default long parseLong(String value, boolean roundUp, LongSupplier now) { + throw new UnsupportedOperationException(); + } /** Parse a value that was formatted with {@link #format(double)} back to * the original double value. */ - double parseDouble(String value, boolean roundUp, LongSupplier now); + default double parseDouble(String value, boolean roundUp, LongSupplier now) { + throw new UnsupportedOperationException(); + } /** Parse a value that was formatted with {@link #format(BytesRef)} back * to the original BytesRef. */ - BytesRef parseBytesRef(String value); + default BytesRef parseBytesRef(String value) { + throw new UnsupportedOperationException(); + } DocValueFormat RAW = new DocValueFormat() { @@ -84,7 +96,7 @@ public String getWriteableName() { } @Override - public void writeTo(StreamOutput out) throws IOException { + public void writeTo(StreamOutput out) { } @Override @@ -132,17 +144,7 @@ public String getWriteableName() { } @Override - public void writeTo(StreamOutput out) throws IOException { - } - - @Override - public Object format(long value) { - throw new UnsupportedOperationException(); - } - - @Override - public Object format(double value) { - throw new UnsupportedOperationException(); + public void writeTo(StreamOutput out) { } @Override @@ -152,16 +154,6 @@ public String format(BytesRef value) { .encodeToString(Arrays.copyOfRange(value.bytes, value.offset, value.offset + value.length)); } - @Override - public long parseLong(String value, boolean roundUp, LongSupplier now) { - throw new UnsupportedOperationException(); - } - - @Override - public double parseDouble(String value, boolean roundUp, LongSupplier now) { - throw new UnsupportedOperationException(); - } - @Override public BytesRef parseBytesRef(String value) { return new BytesRef(Base64.getDecoder().decode(value)); @@ -210,11 +202,6 @@ public String format(double value) { return format((long) value); } - @Override - public String format(BytesRef value) { - throw new UnsupportedOperationException(); - } - @Override public long parseLong(String value, boolean roundUp, LongSupplier now) { return parser.parse(value, now, roundUp, DateUtils.dateTimeZoneToZoneId(timeZone)); @@ -224,11 +211,6 @@ public long parseLong(String value, boolean roundUp, LongSupplier now) { public double parseDouble(String value, boolean roundUp, LongSupplier now) { return parseLong(value, roundUp, now); } - - @Override - public BytesRef parseBytesRef(String value) { - throw new UnsupportedOperationException(); - } } DocValueFormat GEOHASH = new DocValueFormat() { @@ -239,7 +221,7 @@ public String getWriteableName() { } @Override - public void writeTo(StreamOutput out) throws IOException { + public void writeTo(StreamOutput out) { } @Override @@ -251,26 +233,6 @@ public String format(long value) { public String format(double value) { return format((long) value); } - - @Override - public String format(BytesRef value) { - throw new UnsupportedOperationException(); - } - - @Override - public long parseLong(String value, boolean roundUp, LongSupplier now) { - throw new UnsupportedOperationException(); - } - - @Override - public double parseDouble(String value, boolean roundUp, LongSupplier now) { - throw new UnsupportedOperationException(); - } - - @Override - public BytesRef parseBytesRef(String value) { - throw new UnsupportedOperationException(); - } }; DocValueFormat BOOLEAN = new DocValueFormat() { @@ -281,22 +243,17 @@ public String getWriteableName() { } @Override - public void writeTo(StreamOutput out) throws IOException { + public void writeTo(StreamOutput out) { } @Override public Boolean format(long value) { - return java.lang.Boolean.valueOf(value != 0); + return value != 0; } @Override public Boolean format(double value) { - return java.lang.Boolean.valueOf(value != 0); - } - - @Override - public String format(BytesRef value) { - throw new UnsupportedOperationException(); + return value != 0; } @Override @@ -314,11 +271,6 @@ public long parseLong(String value, boolean roundUp, LongSupplier now) { public double parseDouble(String value, boolean roundUp, LongSupplier now) { return parseLong(value, roundUp, now); } - - @Override - public BytesRef parseBytesRef(String value) { - throw new UnsupportedOperationException(); - } }; DocValueFormat IP = new DocValueFormat() { @@ -329,17 +281,7 @@ public String getWriteableName() { } @Override - public void writeTo(StreamOutput out) throws IOException { - } - - @Override - public String format(long value) { - throw new UnsupportedOperationException(); - } - - @Override - public String format(double value) { - throw new UnsupportedOperationException(); + public void writeTo(StreamOutput out) { } @Override @@ -349,16 +291,6 @@ public String format(BytesRef value) { return NetworkAddress.format(inet); } - @Override - public long parseLong(String value, boolean roundUp, LongSupplier now) { - throw new UnsupportedOperationException(); - } - - @Override - public double parseDouble(String value, boolean roundUp, LongSupplier now) { - throw new UnsupportedOperationException(); - } - @Override public BytesRef parseBytesRef(String value) { return new BytesRef(InetAddressPoint.encode(InetAddresses.forString(value))); @@ -399,7 +331,7 @@ public String format(long value) { @Override public String format(double value) { - /** + /* * Explicitly check for NaN, since it formats to "�" or "NaN" depending on JDK version. * * Decimal formatter uses the JRE's default symbol list (via Locale.ROOT above). In JDK8, @@ -418,11 +350,6 @@ public String format(double value) { return format.format(value); } - @Override - public String format(BytesRef value) { - throw new UnsupportedOperationException(); - } - @Override public long parseLong(String value, boolean roundUp, LongSupplier now) { Number n; @@ -455,11 +382,6 @@ public double parseDouble(String value, boolean roundUp, LongSupplier now) { return n.doubleValue(); } - @Override - public BytesRef parseBytesRef(String value) { - throw new UnsupportedOperationException(); - } - @Override public boolean equals(Object o) { if (this == o) {