1
2
3
4
5
6
7
8
9 package org.jrobin.core.jrrd;
10
11
12
13
14
15
16
17 public class DataSourceType {
18
19 private static final int _COUNTER = 0;
20 private static final String STR_COUNTER = "COUNTER";
21
22
23
24
25 public static final DataSourceType COUNTER =
26 new DataSourceType(_COUNTER);
27 private static final int _ABSOLUTE = 1;
28 private static final String STR_ABSOLUTE = "ABSOLUTE";
29
30
31
32
33 public static final DataSourceType ABSOLUTE =
34 new DataSourceType(_ABSOLUTE);
35 private static final int _GAUGE = 2;
36 private static final String STR_GAUGE = "GAUGE";
37
38
39
40
41 public static final DataSourceType GAUGE = new DataSourceType(_GAUGE);
42 private static final int _DERIVE = 3;
43 private static final String STR_DERIVE = "DERIVE";
44
45
46
47
48 public static final DataSourceType DERIVE = new DataSourceType(_DERIVE);
49 private int type;
50
51 private DataSourceType(int type) {
52 this.type = type;
53 }
54
55
56
57
58
59
60
61 public static DataSourceType get(String s) {
62
63 if (s.equalsIgnoreCase(STR_COUNTER)) {
64 return COUNTER;
65 }
66 else if (s.equalsIgnoreCase(STR_ABSOLUTE)) {
67 return ABSOLUTE;
68 }
69 else if (s.equalsIgnoreCase(STR_GAUGE)) {
70 return GAUGE;
71 }
72 else if (s.equalsIgnoreCase(STR_DERIVE)) {
73 return DERIVE;
74 }
75 else {
76 throw new IllegalArgumentException("Invalid DataSourceType");
77 }
78 }
79
80
81
82
83
84
85
86 public boolean equals(Object obj) {
87
88 if (!(obj instanceof DataSourceType)) {
89 throw new IllegalArgumentException("Not a DataSourceType");
90 }
91
92 return (((DataSourceType) obj).type == type)
93 ? true
94 : false;
95 }
96
97
98
99
100
101
102 public String toString() {
103
104 String strType;
105
106 switch (type) {
107
108 case _COUNTER:
109 strType = STR_COUNTER;
110 break;
111
112 case _ABSOLUTE:
113 strType = STR_ABSOLUTE;
114 break;
115
116 case _GAUGE:
117 strType = STR_GAUGE;
118 break;
119
120 case _DERIVE:
121 strType = STR_DERIVE;
122 break;
123
124 default :
125
126 throw new RuntimeException("This should never happen");
127 }
128
129 return strType;
130 }
131 }