Change the Rate.equals(..) method to work for Rates w/o a parent RateStat

Change the RateStat.equals(..) method to work with deserialized RateStats
	Update and fix the JUnit tests for both
This commit is contained in:
zab
2013-01-03 20:08:54 +00:00
parent 3eb00c526d
commit 2c8f2ae404
4 changed files with 49 additions and 18 deletions

View File

@ -533,10 +533,13 @@ public class Rate {
if ((obj == null) || !(obj instanceof Rate)) return false;
if (obj == this) return true;
Rate r = (Rate) obj;
return _period == r.getPeriod() && _creationDate == r.getCreationDate() &&
// do this the easy way to avoid NPEs.
// Alternative: compare name and group name (very carefully to avoid NPEs)
_stat == r._stat;
if (_period != r.getPeriod() || _creationDate != r.getCreationDate())
return false;
if (_stat == null && r._stat == null)
return true;
if (_stat != null && r._stat != null)
return _stat.nameGroupDescEquals(r._stat);
return false;
}
/**

View File

@ -166,13 +166,16 @@ public class RateStat {
if (obj == this)
return true;
RateStat rs = (RateStat) obj;
if (DataHelper.eq(getGroupName(), rs.getGroupName()) && DataHelper.eq(getDescription(), rs.getDescription())
&& DataHelper.eq(getName(), rs.getName())) {
if (nameGroupDescEquals(rs))
return deepEquals(this._rates, rs._rates);
}
return false;
}
boolean nameGroupDescEquals(RateStat rs) {
return DataHelper.eq(getGroupName(), rs.getGroupName()) && DataHelper.eq(getDescription(), rs.getDescription())
&& DataHelper.eq(getName(), rs.getName());
}
public void store(OutputStream out, String prefix) throws IOException {
StringBuilder buf = new StringBuilder(1024);