1 9 package org.jrobin.core.jrrd; 10 11 17 public class DataSourceType { 18 19 private static final int _COUNTER = 0; 20 private static final String STR_COUNTER = "COUNTER"; 21 22 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 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 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 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 61 public static DataSourceType get(String s) { 62 63 if (s.equalsIgnoreCase(STR_COUNTER)) { 64 return COUNTER; 65 } else if (s.equalsIgnoreCase(STR_ABSOLUTE)) { 66 return ABSOLUTE; 67 } else if (s.equalsIgnoreCase(STR_GAUGE)) { 68 return GAUGE; 69 } else if (s.equalsIgnoreCase(STR_DERIVE)) { 70 return DERIVE; 71 } else { 72 throw new IllegalArgumentException ("Invalid DataSourceType"); 73 } 74 } 75 76 82 public boolean equals(Object obj) { 83 84 if (!(obj instanceof DataSourceType)) { 85 throw new IllegalArgumentException ("Not a DataSourceType"); 86 } 87 88 return (((DataSourceType) obj).type == type) 89 ? true 90 : false; 91 } 92 93 98 public String toString() { 99 100 String strType; 101 102 switch (type) { 103 104 case _COUNTER: 105 strType = STR_COUNTER; 106 break; 107 108 case _ABSOLUTE: 109 strType = STR_ABSOLUTE; 110 break; 111 112 case _GAUGE: 113 strType = STR_GAUGE; 114 break; 115 116 case _DERIVE: 117 strType = STR_DERIVE; 118 break; 119 120 default : 121 throw new RuntimeException ("This should never happen"); 123 } 124 125 return strType; 126 } 127 } 128 | Popular Tags |