I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
Commit f96342d3 authored by zzz's avatar zzz
Browse files

backport equals() fix

parent 5eb6bf1b
No related branches found
No related tags found
No related merge requests found
...@@ -3,6 +3,7 @@ package net.i2p.stat; ...@@ -3,6 +3,7 @@ package net.i2p.stat;
import java.io.IOException; import java.io.IOException;
import java.util.Properties; import java.util.Properties;
import net.i2p.data.DataHelper;
import net.i2p.util.Log; import net.i2p.util.Log;
/** /**
...@@ -471,48 +472,28 @@ public class Rate { ...@@ -471,48 +472,28 @@ public class Rate {
coalesce(); coalesce();
} }
/**
* This is used in StatSummarizer and SummaryListener.
* We base it on the stat we are tracking, not the stored data.
*/
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if ((obj == null) || !(obj instanceof Rate)) return false; if ((obj == null) || !(obj instanceof Rate)) return false;
if (obj == this) return true; if (obj == this) return true;
Rate r = (Rate) obj; Rate r = (Rate) obj;
return _period == r.getPeriod() && _creationDate == r.getCreationDate() && return _period == r.getPeriod() && _creationDate == r.getCreationDate() &&
//_lastCoalesceDate == r.getLastCoalesceDate() && // do this the easy way to avoid NPEs.
_currentTotalValue == r.getCurrentTotalValue() && _currentEventCount == r.getCurrentEventCount() // Alternative: compare name and group name (very carefully to avoid NPEs)
&& _currentTotalEventTime == r.getCurrentTotalEventTime() && _lastTotalValue == r.getLastTotalValue() _stat == r._stat;
&& _lastEventCount == r.getLastEventCount() && _lastTotalEventTime == r.getLastTotalEventTime()
&& _extremeTotalValue == r.getExtremeTotalValue() && _extremeEventCount == r.getExtremeEventCount()
&& _extremeTotalEventTime == r.getExtremeTotalEventTime()
&& _lifetimeTotalValue == r.getLifetimeTotalValue() && _lifetimeEventCount == r.getLifetimeEventCount()
&& _lifetimeTotalEventTime == r.getLifetimeTotalEventTime();
} }
/** /**
* It doesn't appear that Rates are ever stored in a Set or Map * It doesn't appear that Rates are ever stored in a Set or Map
* (RateStat stores in an array) so let's make this easy. * (RateStat stores in an array) so let's make this easy.
* We can always make something faster if it's actually used.
*/ */
@Override @Override
public int hashCode() { public int hashCode() {
/***** return DataHelper.hashCode(_stat) ^ ((int)_period) ^ ((int) _creationDate);
int hash = 5;
hash = 67 * hash + (int)(Double.doubleToLongBits(this._currentTotalValue) ^ (Double.doubleToLongBits(this._currentTotalValue) >>> 32));
hash = 67 * hash + (int)(this._currentEventCount ^ (this._currentEventCount >>> 32));
hash = 67 * hash + (int)(this._currentTotalEventTime ^ (this._currentTotalEventTime >>> 32));
hash = 67 * hash + (int)(Double.doubleToLongBits(this._lastTotalValue) ^ (Double.doubleToLongBits(this._lastTotalValue) >>> 32));
hash = 67 * hash + (int)(this._lastEventCount ^ (this._lastEventCount >>> 32));
hash = 67 * hash + (int)(this._lastTotalEventTime ^ (this._lastTotalEventTime >>> 32));
hash = 67 * hash + (int)(Double.doubleToLongBits(this._extremeTotalValue) ^ (Double.doubleToLongBits(this._extremeTotalValue) >>> 32));
hash = 67 * hash + (int)(this._extremeEventCount ^ (this._extremeEventCount >>> 32));
hash = 67 * hash + (int)(this._extremeTotalEventTime ^ (this._extremeTotalEventTime >>> 32));
hash = 67 * hash + (int)(Double.doubleToLongBits(this._lifetimeTotalValue) ^ (Double.doubleToLongBits(this._lifetimeTotalValue) >>> 32));
hash = 67 * hash + (int)(this._lifetimeEventCount ^ (this._lifetimeEventCount >>> 32));
hash = 67 * hash + (int)(this._lifetimeTotalEventTime ^ (this._lifetimeTotalEventTime >>> 32));
hash = 67 * hash + (int)(this._creationDate ^ (this._creationDate >>> 32));
hash = 67 * hash + (int)(this._period ^ (this._period >>> 32));
return hash;
******/
return toString().hashCode();
} }
@Override @Override
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment