From 879e615314510c6ea687144868de66f85c5a300a Mon Sep 17 00:00:00 2001 From: Gian Merlino Date: Fri, 29 Aug 2014 15:02:04 -0700 Subject: [PATCH] AggregatorFactory equals() and hashCode() methods. --- ...ApproximateHistogramAggregatorFactory.java | 46 +++++++++++++++++++ ...mateHistogramFoldingAggregatorFactory.java | 46 +++++++++++++++++++ .../CardinalityAggregatorFactory.java | 35 +++++++++++++- 3 files changed, 126 insertions(+), 1 deletion(-) diff --git a/histogram/src/main/java/io/druid/query/aggregation/histogram/ApproximateHistogramAggregatorFactory.java b/histogram/src/main/java/io/druid/query/aggregation/histogram/ApproximateHistogramAggregatorFactory.java index 603d07765ee..458486423f9 100644 --- a/histogram/src/main/java/io/druid/query/aggregation/histogram/ApproximateHistogramAggregatorFactory.java +++ b/histogram/src/main/java/io/druid/query/aggregation/histogram/ApproximateHistogramAggregatorFactory.java @@ -238,6 +238,52 @@ public class ApproximateHistogramAggregatorFactory implements AggregatorFactory return new ApproximateHistogram(resolution); } + @Override + public boolean equals(Object o) + { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + ApproximateHistogramAggregatorFactory that = (ApproximateHistogramAggregatorFactory) o; + + if (Float.compare(that.lowerLimit, lowerLimit) != 0) { + return false; + } + if (numBuckets != that.numBuckets) { + return false; + } + if (resolution != that.resolution) { + return false; + } + if (Float.compare(that.upperLimit, upperLimit) != 0) { + return false; + } + if (fieldName != null ? !fieldName.equals(that.fieldName) : that.fieldName != null) { + return false; + } + if (name != null ? !name.equals(that.name) : that.name != null) { + return false; + } + + return true; + } + + @Override + public int hashCode() + { + int result = name != null ? name.hashCode() : 0; + result = 31 * result + (fieldName != null ? fieldName.hashCode() : 0); + result = 31 * result + resolution; + result = 31 * result + numBuckets; + result = 31 * result + (lowerLimit != +0.0f ? Float.floatToIntBits(lowerLimit) : 0); + result = 31 * result + (upperLimit != +0.0f ? Float.floatToIntBits(upperLimit) : 0); + return result; + } + @Override public String toString() { diff --git a/histogram/src/main/java/io/druid/query/aggregation/histogram/ApproximateHistogramFoldingAggregatorFactory.java b/histogram/src/main/java/io/druid/query/aggregation/histogram/ApproximateHistogramFoldingAggregatorFactory.java index c5bb1e552c5..04dc43a804b 100644 --- a/histogram/src/main/java/io/druid/query/aggregation/histogram/ApproximateHistogramFoldingAggregatorFactory.java +++ b/histogram/src/main/java/io/druid/query/aggregation/histogram/ApproximateHistogramFoldingAggregatorFactory.java @@ -148,6 +148,52 @@ public class ApproximateHistogramFoldingAggregatorFactory extends ApproximateHis .array(); } + @Override + public boolean equals(Object o) + { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + ApproximateHistogramAggregatorFactory that = (ApproximateHistogramAggregatorFactory) o; + + if (Float.compare(that.lowerLimit, lowerLimit) != 0) { + return false; + } + if (numBuckets != that.numBuckets) { + return false; + } + if (resolution != that.resolution) { + return false; + } + if (Float.compare(that.upperLimit, upperLimit) != 0) { + return false; + } + if (fieldName != null ? !fieldName.equals(that.fieldName) : that.fieldName != null) { + return false; + } + if (name != null ? !name.equals(that.name) : that.name != null) { + return false; + } + + return true; + } + + @Override + public int hashCode() + { + int result = name != null ? name.hashCode() : 0; + result = 31 * result + (fieldName != null ? fieldName.hashCode() : 0); + result = 31 * result + resolution; + result = 31 * result + numBuckets; + result = 31 * result + (lowerLimit != +0.0f ? Float.floatToIntBits(lowerLimit) : 0); + result = 31 * result + (upperLimit != +0.0f ? Float.floatToIntBits(upperLimit) : 0); + return result; + } + @Override public String toString() { diff --git a/processing/src/main/java/io/druid/query/aggregation/cardinality/CardinalityAggregatorFactory.java b/processing/src/main/java/io/druid/query/aggregation/cardinality/CardinalityAggregatorFactory.java index 10443c828cd..b1db05a2284 100644 --- a/processing/src/main/java/io/druid/query/aggregation/cardinality/CardinalityAggregatorFactory.java +++ b/processing/src/main/java/io/druid/query/aggregation/cardinality/CardinalityAggregatorFactory.java @@ -39,7 +39,6 @@ import org.apache.commons.codec.binary.Base64; import javax.annotation.Nullable; import java.nio.ByteBuffer; -import java.util.Arrays; import java.util.Comparator; import java.util.List; @@ -233,6 +232,40 @@ public class CardinalityAggregatorFactory implements AggregatorFactory return HyperLogLogCollector.makeLatestCollector(); } + @Override + public boolean equals(Object o) + { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + CardinalityAggregatorFactory that = (CardinalityAggregatorFactory) o; + + if (byRow != that.byRow) { + return false; + } + if (fieldNames != null ? !fieldNames.equals(that.fieldNames) : that.fieldNames != null) { + return false; + } + if (name != null ? !name.equals(that.name) : that.name != null) { + return false; + } + + return true; + } + + @Override + public int hashCode() + { + int result = name != null ? name.hashCode() : 0; + result = 31 * result + (fieldNames != null ? fieldNames.hashCode() : 0); + result = 31 * result + (byRow ? 1 : 0); + return result; + } + @Override public String toString() {