1 25 26 package org.jrobin.core; 27 28 44 45 public class ArcDef { 46 47 public static final String CONSOL_FUNS[] = { "AVERAGE", "MAX", "MIN", "LAST" }; 48 49 private String consolFun; 50 private double xff; 51 private int steps, rows; 52 53 68 public ArcDef(String consolFun, double xff, int steps, int rows) throws RrdException { 69 this.consolFun = consolFun; 70 this.xff = xff; 71 this.steps = steps; 72 this.rows = rows; 73 validate(); 74 } 75 76 80 public String getConsolFun() { 81 return consolFun; 82 } 83 84 88 public double getXff() { 89 return xff; 90 } 91 92 96 public int getSteps() { 97 return steps; 98 } 99 100 104 public int getRows() { 105 return rows; 106 } 107 108 private void validate() throws RrdException { 109 if(!isValidConsolFun(consolFun)) { 110 throw new RrdException("Invalid consolidation function specified: " + consolFun); 111 } 112 if(Double.isNaN(xff) || xff < 0.0 || xff >= 1.0) { 113 throw new RrdException("Invalid xff, must be >= 0 and < 1: " + xff); 114 } 115 if(steps <= 0 || rows <= 0) { 116 throw new RrdException("Invalid steps/rows number: " + steps + "/" + rows); 117 } 118 } 119 120 124 public String dump() { 125 return "RRA:" + consolFun + ":" + xff + ":" + steps + ":" + rows; 126 } 127 128 137 public boolean equals(Object obj) { 138 if(obj instanceof ArcDef) { 139 ArcDef arcObj = (ArcDef) obj; 140 return consolFun.equals(arcObj.consolFun) && steps == arcObj.steps; 141 } 142 return false; 143 } 144 145 151 public static boolean isValidConsolFun(String consolFun) { 152 for(int i = 0; i < CONSOL_FUNS.length; i++) { 153 if(CONSOL_FUNS[i].equals(consolFun)) { 154 return true; 155 } 156 } 157 return false; 158 } 159 160 void setRows(int rows) { 161 this.rows = rows; 162 } 163 164 boolean exactlyEqual(ArcDef def) { 165 return consolFun.equals(def.consolFun) && xff == def.xff && 166 steps == def.steps && rows == def.rows; 167 } 168 } 169 | Popular Tags |