summaryrefslogtreecommitdiffstats
path: root/simplemetrics
diff options
context:
space:
mode:
authorArne H Juul <arnej@yahoo-inc.com>2016-11-08 11:56:08 +0100
committerArne H Juul <arnej@yahoo-inc.com>2016-11-08 11:56:08 +0100
commitbc148a328e3ac237c02ae6fb6f890c40a7419103 (patch)
tree85f67a4a527fae2f61552d326685c6140eaf14de /simplemetrics
parent407a8f28eb5ddfcf1345149fe52882496e71943b (diff)
avoid keeping null Point around, use emptyPoint instead
Diffstat (limited to 'simplemetrics')
-rw-r--r--simplemetrics/src/main/java/com/yahoo/metrics/simple/Identifier.java22
-rw-r--r--simplemetrics/src/test/java/com/yahoo/metrics/simple/CounterTest.java4
-rw-r--r--simplemetrics/src/test/java/com/yahoo/metrics/simple/GaugeTest.java2
-rw-r--r--simplemetrics/src/test/java/com/yahoo/metrics/simple/MetricsTest.java2
4 files changed, 11 insertions, 19 deletions
diff --git a/simplemetrics/src/main/java/com/yahoo/metrics/simple/Identifier.java b/simplemetrics/src/main/java/com/yahoo/metrics/simple/Identifier.java
index 8d2ac23689b..adaa948a70d 100644
--- a/simplemetrics/src/main/java/com/yahoo/metrics/simple/Identifier.java
+++ b/simplemetrics/src/main/java/com/yahoo/metrics/simple/Identifier.java
@@ -4,7 +4,7 @@ package com.yahoo.metrics.simple;
/**
* The name of the metric and its n-dimensional position. Basically a pair of a
* Point and a metric name. Written to be robust against null input as the API
- * gives very little guidance.
+ * gives very little guidance, converting null to empty string/point. Immutable.
*
* @author Steinar Knutsen
*/
@@ -14,16 +14,16 @@ public class Identifier {
private final Point location;
public Identifier(String name, Point location) {
- this.name = name;
- this.location = location;
+ this.name = (name == null ? "" : name);
+ this.location = (location == null ? Point.emptyPoint() : location);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
- result = prime * result + ((location == null) ? 0 : location.hashCode());
- result = prime * result + ((name == null) ? 0 : name.hashCode());
+ result = prime * result + location.hashCode();
+ result = prime * result + name.hashCode();
return result;
}
@@ -34,18 +34,10 @@ public class Identifier {
if (getClass() != obj.getClass()) return false;
Identifier other = (Identifier) obj;
- if (location == null) {
- if (other.location != null) {
- return false;
- }
- } else if (!location.equals(other.location)) {
+ if (!location.equals(other.location)) {
return false;
}
- if (name == null) {
- if (other.name != null) {
- return false;
- }
- } else if (!name.equals(other.name)) {
+ if (!name.equals(other.name)) {
return false;
}
return true;
diff --git a/simplemetrics/src/test/java/com/yahoo/metrics/simple/CounterTest.java b/simplemetrics/src/test/java/com/yahoo/metrics/simple/CounterTest.java
index d5e7f095308..4bbd9a8cfa9 100644
--- a/simplemetrics/src/test/java/com/yahoo/metrics/simple/CounterTest.java
+++ b/simplemetrics/src/test/java/com/yahoo/metrics/simple/CounterTest.java
@@ -43,7 +43,7 @@ public class CounterTest {
assertEquals(1, valuesByMetricName.size());
List<Entry<Point, UntypedMetric>> x = valuesByMetricName.get(metricName);
assertEquals(1, x.size());
- assertNull(x.get(0).getKey());
+ assertEquals(Point.emptyPoint(), x.get(0).getKey());
assertEquals(1L, x.get(0).getValue().getCount());
}
@@ -58,7 +58,7 @@ public class CounterTest {
assertEquals(1, valuesByMetricName.size());
List<Entry<Point, UntypedMetric>> x = valuesByMetricName.get(metricName);
assertEquals(1, x.size());
- assertNull(x.get(0).getKey());
+ assertEquals(Point.emptyPoint(), x.get(0).getKey());
assertEquals(twoToThePowerOfFourtyeight, x.get(0).getValue().getCount());
}
diff --git a/simplemetrics/src/test/java/com/yahoo/metrics/simple/GaugeTest.java b/simplemetrics/src/test/java/com/yahoo/metrics/simple/GaugeTest.java
index 1ba83517742..c95740f1c01 100644
--- a/simplemetrics/src/test/java/com/yahoo/metrics/simple/GaugeTest.java
+++ b/simplemetrics/src/test/java/com/yahoo/metrics/simple/GaugeTest.java
@@ -45,7 +45,7 @@ public class GaugeTest {
assertEquals(1, valuesByMetricName.size());
List<Entry<Point, UntypedMetric>> x = valuesByMetricName.get(metricName);
assertEquals(1, x.size());
- assertNull(x.get(0).getKey());
+ assertEquals(Point.emptyPoint(), x.get(0).getKey());
assertEquals(1L, x.get(0).getValue().getCount());
assertEquals(1.0d, x.get(0).getValue().getLast(), 0.0d);
}
diff --git a/simplemetrics/src/test/java/com/yahoo/metrics/simple/MetricsTest.java b/simplemetrics/src/test/java/com/yahoo/metrics/simple/MetricsTest.java
index d33e25cab01..d99dc4c40ff 100644
--- a/simplemetrics/src/test/java/com/yahoo/metrics/simple/MetricsTest.java
+++ b/simplemetrics/src/test/java/com/yahoo/metrics/simple/MetricsTest.java
@@ -44,7 +44,7 @@ public class MetricsTest extends UnitTestSetup {
Collection<Entry<Point, UntypedMetric>> values = s.getValuesForMetric(metricName);
assertEquals(1, values.size());
Entry<Point, UntypedMetric> value = values.iterator().next();
- assertNull(value.getKey());
+ assertEquals(Point.emptyPoint(), value.getKey());
assertEquals(1.0d, value.getValue().getLast(), 0.0d); // using number exactly expressible as doubles
assertEquals(1L, value.getValue().getCount());
}