summaryrefslogtreecommitdiffstats
path: root/simplemetrics/src/main/java/com/yahoo
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/src/main/java/com/yahoo
parent407a8f28eb5ddfcf1345149fe52882496e71943b (diff)
avoid keeping null Point around, use emptyPoint instead
Diffstat (limited to 'simplemetrics/src/main/java/com/yahoo')
-rw-r--r--simplemetrics/src/main/java/com/yahoo/metrics/simple/Identifier.java22
1 files changed, 7 insertions, 15 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;