From c982216dbe63e8948c53a281cf43c282a313935c Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Mon, 18 Apr 2016 14:13:29 -0400 Subject: [PATCH] Remove PROTOTYPEs from Ranges Relates to #17085 --- .../bucket/range/RangeAggregator.java | 45 +++++++++---------- .../bucket/range/RangeAggregatorBuilder.java | 2 +- .../bucket/range/RangeParser.java | 2 +- .../date/DateRangeAggregatorBuilder.java | 2 +- .../ipv4/IPv4RangeAggregatorBuilder.java | 43 +++++++----------- .../bucket/range/ipv4/IpRangeParser.java | 2 +- 6 files changed, 42 insertions(+), 54 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/range/RangeAggregator.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/range/RangeAggregator.java index 45bfefff2c0..eeb37dfa991 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/range/RangeAggregator.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/range/RangeAggregator.java @@ -58,8 +58,6 @@ public class RangeAggregator extends BucketsAggregator { public static final ParseField KEYED_FIELD = new ParseField("keyed"); public static class Range implements Writeable, ToXContent { - - public static final Range PROTOTYPE = new Range(null, null, null, null, null); public static final ParseField KEY_FIELD = new ParseField("key"); public static final ParseField FROM_FIELD = new ParseField("from"); public static final ParseField TO_FIELD = new ParseField("to"); @@ -78,6 +76,27 @@ public class RangeAggregator extends BucketsAggregator { this(key, null, from, null, to); } + /** + * Read from a stream. + */ + public Range(StreamInput in) throws IOException { + key = in.readOptionalString(); + fromAsStr = in.readOptionalString(); + toAsStr = in.readOptionalString(); + from = in.readDouble(); + to = in.readDouble(); + } + + @Override + public void writeTo(StreamOutput out) throws IOException { + out.writeOptionalString(key); + out.writeOptionalString(fromAsStr); + out.writeOptionalString(toAsStr); + out.writeDouble(from); + out.writeDouble(to); + } + + protected Range(String key, Double from, String fromAsStr, Double to, String toAsStr) { this.key = key; this.from = from == null ? Double.NEGATIVE_INFINITY : from; @@ -108,27 +127,7 @@ public class RangeAggregator extends BucketsAggregator { return new Range(key, from, fromAsStr, to, toAsStr); } - @Override - public Range readFrom(StreamInput in) throws IOException { - String key = in.readOptionalString(); - String fromAsStr = in.readOptionalString(); - String toAsStr = in.readOptionalString(); - double from = in.readDouble(); - double to = in.readDouble(); - return new Range(key, from, fromAsStr, to, toAsStr); - } - - @Override - public void writeTo(StreamOutput out) throws IOException { - out.writeOptionalString(key); - out.writeOptionalString(fromAsStr); - out.writeOptionalString(toAsStr); - out.writeDouble(from); - out.writeDouble(to); - } - - public Range fromXContent(XContentParser parser, ParseFieldMatcher parseFieldMatcher) throws IOException { - + public static Range fromXContent(XContentParser parser, ParseFieldMatcher parseFieldMatcher) throws IOException { XContentParser.Token token; String currentFieldName = null; double from = Double.NEGATIVE_INFINITY; diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/range/RangeAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/range/RangeAggregatorBuilder.java index 5241243e3af..8347625b09a 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/range/RangeAggregatorBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/range/RangeAggregatorBuilder.java @@ -42,7 +42,7 @@ public class RangeAggregatorBuilder extends AbstractRangeBuilder