Skip to content

Commit

Permalink
Add, fix equals, hashCode, toString on various classes. (apache#3723)
Browse files Browse the repository at this point in the history
* TimeFormatExtractionFn: Add toString.

* InDimFilter: Add toString, allow accepting any Collection of values.

* DimensionTopNMetricSpec: Fix toString.

* InvertedTopNMetricSpec: Add toString.

* HyperUniqueFinalizingPostAggregator: Add equals, hashCode, toString.
  • Loading branch information
gianm authored Dec 1, 2016
1 parent 477e0ca commit 6873582
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,39 @@ public String getFieldName()
{
return fieldName;
}

@Override
public boolean equals(Object o)
{
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}

HyperUniqueFinalizingPostAggregator that = (HyperUniqueFinalizingPostAggregator) o;

if (name != null ? !name.equals(that.name) : that.name != null) {
return false;
}
return fieldName != null ? fieldName.equals(that.fieldName) : that.fieldName == null;
}

@Override
public int hashCode()
{
int result = name != null ? name.hashCode() : 0;
result = 31 * result + (fieldName != null ? fieldName.hashCode() : 0);
return result;
}

@Override
public String toString()
{
return "HyperUniqueFinalizingPostAggregator{" +
"name='" + name + '\'' +
", fieldName='" + fieldName + '\'' +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@

public class TimeFormatExtractionFn implements ExtractionFn
{
private final DateTimeZone tz;
private final String format;
private final DateTimeZone tz;
private final Locale locale;
private final QueryGranularity granularity;
private final DateTimeFormatter formatter;
Expand Down Expand Up @@ -161,4 +161,10 @@ public int hashCode()
result = 31 * result + granularity.hashCode();
return result;
}

@Override
public String toString()
{
return String.format("timeFormat(\"%s\", %s, %s, %s)", format, tz, locale, granularity);
}
}
24 changes: 23 additions & 1 deletion processing/src/main/java/io/druid/query/filter/InDimFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.Function;
import com.google.common.base.Joiner;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import com.google.common.base.Supplier;
Expand All @@ -40,6 +41,7 @@
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
Expand All @@ -59,7 +61,7 @@ public class InDimFilter implements DimFilter
@JsonCreator
public InDimFilter(
@JsonProperty("dimension") String dimension,
@JsonProperty("values") List<String> values,
@JsonProperty("values") Collection<String> values,
@JsonProperty("extractionFn") ExtractionFn extractionFn
)
{
Expand Down Expand Up @@ -227,6 +229,26 @@ public int hashCode()
return result;
}

@Override
public String toString()
{
final StringBuilder builder = new StringBuilder();

if (extractionFn != null) {
builder.append(extractionFn).append("(");
}

builder.append(dimension);

if (extractionFn != null) {
builder.append(")");
}

builder.append(" IN (").append(Joiner.on(", ").join(values)).append(")");

return builder.toString();
}

// As the set of filtered values can be large, parsing them as longs should be done only if needed, and only once.
// Pass in a common long predicate supplier to all filters created by .toFilter(), so that
// we only compute the long hashset/array once per query.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public String toString()
{
return "DimensionTopNMetricSpec{" +
"previousStop='" + previousStop + '\'' +
"ordering='" + ordering + '\'' +
", ordering=" + ordering +
'}';
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,12 @@ public int hashCode()
{
return delegate != null ? delegate.hashCode() : 0;
}

@Override
public String toString()
{
return "InvertedTopNMetricSpec{" +
"delegate=" + delegate +
'}';
}
}

0 comments on commit 6873582

Please sign in to comment.