Skip to content

Commit 86142ce

Browse files
vjkoskelaBrandonArp
authored andcommitted
Fix TPStatistic hashcode to use the name instead of the type as it is the only dynamic statistic. (#97)
1 parent 223536c commit 86142ce

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/main/java/com/arpnetworking/tsdcore/statistics/BaseStatistic.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
package com.arpnetworking.tsdcore.statistics;
1717

1818
import com.google.common.base.MoreObjects;
19+
import com.google.common.base.Supplier;
20+
import com.google.common.base.Suppliers;
1921

2022
import java.util.Collections;
2123
import java.util.Set;
@@ -39,7 +41,7 @@ public Set<Statistic> getDependencies() {
3941

4042
@Override
4143
public int hashCode() {
42-
return getClass().hashCode();
44+
return _hashCodeSupplier.get();
4345
}
4446

4547
@Override
@@ -57,5 +59,7 @@ public String toString() {
5759
.toString();
5860
}
5961

62+
private final Supplier<Integer> _hashCodeSupplier = Suppliers.memoize(() -> getClass().hashCode());
63+
6064
private static final long serialVersionUID = -1334453626232464982L;
6165
}

src/main/java/com/arpnetworking/tsdcore/statistics/TPStatistic.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,23 @@ public Quantity calculateAggregations(final List<AggregatedData> aggregations) {
8484
return allSamples.get(index);
8585
}
8686

87+
@Override
88+
public int hashCode() {
89+
return getName().hashCode();
90+
}
91+
92+
@Override
93+
public boolean equals(final Object o) {
94+
if (this == o) {
95+
return true;
96+
}
97+
if (!(o instanceof TPStatistic)) {
98+
return false;
99+
}
100+
final TPStatistic otherTPStatistic = (TPStatistic) o;
101+
return getName().equals(otherTPStatistic.getName());
102+
}
103+
87104
/**
88105
* Public constructor.
89106
*

0 commit comments

Comments
 (0)