1 25 26 package org.jrobin.core; 27 28 44 public class DsDef { 45 46 public static final String [] DS_TYPES = { "GAUGE", "COUNTER", "DERIVE", "ABSOLUTE" }; 47 48 private String dsName, dsType; 49 private long heartbeat; 50 private double minValue, maxValue; 51 52 68 public DsDef(String dsName, String dsType, long heartbeat, 69 double minValue, double maxValue) throws RrdException { 70 this.dsName = dsName; 71 this.dsType = dsType; 72 this.heartbeat = heartbeat; 73 this.minValue = minValue; 74 this.maxValue = maxValue; 75 validate(); 76 } 77 78 82 public String getDsName() { 83 return dsName; 84 } 85 86 90 public String getDsType() { 91 return dsType; 92 } 93 94 98 public long getHeartbeat() { 99 return heartbeat; 100 } 101 102 106 public double getMinValue() { 107 return minValue; 108 } 109 110 114 public double getMaxValue() { 115 return maxValue; 116 } 117 118 private void validate() throws RrdException { 119 if(dsName == null || dsName.length() == 0) { 120 throw new RrdException("Invalid datasource name specified"); 121 } 122 if(!isValidDsType(dsType)) { 123 throw new RrdException("Invalid datasource type specified: " + dsType); 124 } 125 if(heartbeat <= 0) { 126 throw new RrdException("Invalid heartbeat, must be positive: " + heartbeat); 127 } 128 if(!Double.isNaN(minValue) && !Double.isNaN(maxValue) && minValue >= maxValue) { 129 throw new RrdException("Invalid min/max values specified: " + 130 minValue + "/" + maxValue); 131 } 132 } 133 134 140 public static boolean isValidDsType(String dsType) { 141 for(int i = 0; i < DS_TYPES.length; i++) { 142 if(DS_TYPES[i].equals(dsType)) { 143 return true; 144 } 145 } 146 return false; 147 } 148 149 153 public String dump() { 154 return "DS:" + dsName + ":" + dsType + ":" + heartbeat + 155 ":" + Util.formatDouble(minValue, "U", false) + 156 ":" + Util.formatDouble(maxValue, "U", false); 157 } 158 159 167 public boolean equals(Object obj) { 168 if(obj instanceof DsDef) { 169 DsDef dsObj = (DsDef) obj; 170 return dsName.equals(dsObj.dsName); 171 } 172 return false; 173 } 174 175 boolean exactlyEqual(DsDef def) { 176 return dsName.equals(def.dsName) && dsType.equals(def.dsType) && 177 heartbeat == def.heartbeat && Util.equal(minValue, def.minValue) && 178 Util.equal(maxValue, def.maxValue); 179 } 180 } 181 | Popular Tags |