From: Sasa M. <sa...@us...> - 2004-07-20 08:21:10
|
Update of /cvsroot/jrobin/src/org/jrobin/core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21840/org/jrobin/core Modified Files: ArcDef.java DsDef.java RrdDef.java Util.java Log Message: implemented equals() for RrdDef class Index: DsDef.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/DsDef.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** DsDef.java 20 May 2004 10:29:32 -0000 1.5 --- DsDef.java 20 Jul 2004 08:21:02 -0000 1.6 *************** *** 173,175 **** --- 173,180 ---- } + boolean exactlyEqual(DsDef def) { + return dsName.equals(def.dsName) && dsType.equals(def.dsType) && + heartbeat == def.heartbeat && Util.equal(minValue, def.minValue) && + Util.equal(maxValue, def.maxValue); + } } Index: RrdDef.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdDef.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** RrdDef.java 20 May 2004 10:29:33 -0000 1.12 --- RrdDef.java 20 Jul 2004 08:21:02 -0000 1.13 *************** *** 549,551 **** --- 549,612 ---- 20L * dsCount * arcCount + 8L * dsCount * rowsCount; } + + /** + * Compares the current RrdDef with another. RrdDefs are considered equal if:<p> + *<ul> + * <li>RRD steps match + * <li>all datasources have exactly the same definition in both RrdDef objects (datasource names, + * types, heartbeat, min and max values must match) + * <li>all archives have exactly the same definition in both RrdDef objects (archive consolidation + * functions, X-file factors, step and row counts must match) + * </ul> + * @param obj The second RrdDef object + * @return true if RrdDefs match exactly, false otherwise + */ + public boolean equals(Object obj) { + if(obj == null || !(obj instanceof RrdDef)) { + return false; + } + RrdDef rrdDef2 = (RrdDef) obj; + // check primary RRD step + if(step != rrdDef2.step) { + return false; + } + // check datasources + DsDef[] dsDefs = getDsDefs(), dsDefs2 = rrdDef2.getDsDefs(); + if(dsDefs.length != dsDefs2.length) { + return false; + } + for(int i = 0; i < dsDefs.length; i++) { + boolean matched = false; + for(int j = 0; j < dsDefs2.length; j++) { + if(dsDefs[i].exactlyEqual(dsDefs2[j])) { + matched = true; + break; + } + } + // this datasource could not be matched + if(!matched) { + return false; + } + } + // check archives + ArcDef[] arcDefs = getArcDefs(), arcDefs2 = rrdDef2.getArcDefs(); + if(arcDefs.length != arcDefs2.length) { + return false; + } + for(int i = 0; i < arcDefs.length; i++) { + boolean matched = false; + for(int j = 0; j < arcDefs2.length; j++) { + if(arcDefs[i].exactlyEqual(arcDefs2[j])) { + matched = true; + break; + } + } + // this archive could not be matched + if(!matched) { + return false; + } + } + // everything matches + return true; + } } Index: Util.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/Util.java,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** Util.java 14 Jul 2004 12:52:34 -0000 1.19 --- Util.java 20 Jul 2004 08:21:02 -0000 1.20 *************** *** 534,536 **** --- 534,551 ---- } + /** + * Compares two doubles, but returns true if x = y = Double.NaN + * @param x First double + * @param y Second double + * @return true, if doubles are equal, false otherwise. + */ + public static boolean equal(double x, double y) { + if(Double.isNaN(x) && Double.isNaN(y)) { + return true; + } + else { + return x == y; + } + } + } \ No newline at end of file Index: ArcDef.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/ArcDef.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** ArcDef.java 20 May 2004 10:29:32 -0000 1.6 --- ArcDef.java 20 Jul 2004 08:21:01 -0000 1.7 *************** *** 162,164 **** --- 162,168 ---- } + boolean exactlyEqual(ArcDef def) { + return consolFun.equals(def.consolFun) && xff == def.xff && + steps == def.steps && rows == def.rows; + } } |