summaryrefslogtreecommitdiffstats
path: root/simplemetrics/src/main/java/com/yahoo/metrics/simple/Identifier.java
blob: 8d2ac23689be9bd02f4b47d1f4d4be215ff79573 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
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.
 *
 * @author Steinar Knutsen
 */
public class Identifier {

    private final String name;
    private final Point location;

    public Identifier(String name, Point location) {
        this.name = name;
        this.location = 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());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) return true;
        if (obj == null) return false;
        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)) {
            return false;
        }
        if (name == null) {
            if (other.name != null) {
                return false;
            }
        } else if (!name.equals(other.name)) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        StringBuilder builder = new StringBuilder();
        builder.append("Identifier [name=").append(name).append(", location=").append(location).append("]");
        return builder.toString();
    }

    public String getName() {
        return name;
    }

    public Point getLocation() {
        return location;
    }

}