1 package com.stateofflow.eclipse.metrics.metric;
2
3 import com.stateofflow.eclipse.metrics.calculators.Calculator;
4
5 public class MetricId {
6 private static final String METHOD_SUBTYPE = "method";
7 private static final String TYPE_SUBTYPE = "type";
8 private final Class< ? extends Calculator> calculatorClass;
9 private final String subtype;
10
11 private MetricId(final Class< ? extends Calculator> calculatorClass, final String subtype) {
12 this.calculatorClass = calculatorClass;
13 this.subtype = subtype;
14 }
15
16 public static MetricId createTypeId(final Class< ? extends Calculator> calculatorClass) {
17 return create(calculatorClass, TYPE_SUBTYPE);
18 }
19
20 public static MetricId createMethodId(final Class< ? extends Calculator> calculatorClass) {
21 return create(calculatorClass, METHOD_SUBTYPE);
22 }
23
24 public static MetricId create(final Class< ? extends Calculator> calculatorClass, final String subtype) {
25 return new MetricId(calculatorClass, subtype);
26 }
27
28 public MetricPropertyKey createUpperBoundPropertyKey() {
29 return new MetricPropertyKey(this, "upperBound");
30 }
31
32 public MetricPropertyKey createEnablementPropertyKey() {
33 return new MetricPropertyKey(this, "enabled");
34 }
35
36 @Override
37 public int hashCode() {
38 return calculatorClass.hashCode();
39 }
40
41 @Override
42 public boolean equals(final Object obj) {
43 if (obj == this) {
44 return true;
45 }
46
47 if (obj == null || !obj.getClass().equals(getClass())) {
48 return false;
49 }
50
51 final MetricId that = (MetricId) obj;
52 return calculatorClass.equals(that.calculatorClass) && subtype.equals(that.subtype);
53 }
54
55 @Override
56 public String toString() {
57 return calculatorClass.getName() + "." + subtype;
58 }
59 }
60