Changeset f96342d


Ignore:
Timestamp:
Mar 19, 2011 4:39:22 PM (9 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
34d951a
Parents:
5eb6bf1
Message:

backport equals() fix

File:
1 edited

Legend:

Unmodified
Added
Removed
  • core/java/src/net/i2p/stat/Rate.java

    r5eb6bf1 rf96342d  
    44import java.util.Properties;
    55
     6import net.i2p.data.DataHelper;
    67import net.i2p.util.Log;
    78
     
    472473    }
    473474
     475    /**
     476     * This is used in StatSummarizer and SummaryListener.
     477     * We base it on the stat we are tracking, not the stored data.
     478     */
    474479    @Override
    475480    public boolean equals(Object obj) {
     
    478483        Rate r = (Rate) obj;
    479484        return _period == r.getPeriod() && _creationDate == r.getCreationDate() &&
    480         //_lastCoalesceDate == r.getLastCoalesceDate() &&
    481                _currentTotalValue == r.getCurrentTotalValue() && _currentEventCount == r.getCurrentEventCount()
    482                && _currentTotalEventTime == r.getCurrentTotalEventTime() && _lastTotalValue == r.getLastTotalValue()
    483                && _lastEventCount == r.getLastEventCount() && _lastTotalEventTime == r.getLastTotalEventTime()
    484                && _extremeTotalValue == r.getExtremeTotalValue() && _extremeEventCount == r.getExtremeEventCount()
    485                && _extremeTotalEventTime == r.getExtremeTotalEventTime()
    486                && _lifetimeTotalValue == r.getLifetimeTotalValue() && _lifetimeEventCount == r.getLifetimeEventCount()
    487                && _lifetimeTotalEventTime == r.getLifetimeTotalEventTime();
     485               // do this the easy way to avoid NPEs.
     486               // Alternative: compare name and group name (very carefully to avoid NPEs)
     487               _stat == r._stat;
    488488    }
    489489
     
    491491     * It doesn't appear that Rates are ever stored in a Set or Map
    492492     * (RateStat stores in an array) so let's make this easy.
    493      * We can always make something faster if it's actually used.
    494493     */
    495494    @Override
    496495    public int hashCode() {
    497 /*****
    498         int hash = 5;
    499         hash = 67 * hash + (int)(Double.doubleToLongBits(this._currentTotalValue) ^ (Double.doubleToLongBits(this._currentTotalValue) >>> 32));
    500         hash = 67 * hash + (int)(this._currentEventCount ^ (this._currentEventCount >>> 32));
    501         hash = 67 * hash + (int)(this._currentTotalEventTime ^ (this._currentTotalEventTime >>> 32));
    502         hash = 67 * hash + (int)(Double.doubleToLongBits(this._lastTotalValue) ^ (Double.doubleToLongBits(this._lastTotalValue) >>> 32));
    503         hash = 67 * hash + (int)(this._lastEventCount ^ (this._lastEventCount >>> 32));
    504         hash = 67 * hash + (int)(this._lastTotalEventTime ^ (this._lastTotalEventTime >>> 32));
    505         hash = 67 * hash + (int)(Double.doubleToLongBits(this._extremeTotalValue) ^ (Double.doubleToLongBits(this._extremeTotalValue) >>> 32));
    506         hash = 67 * hash + (int)(this._extremeEventCount ^ (this._extremeEventCount >>> 32));
    507         hash = 67 * hash + (int)(this._extremeTotalEventTime ^ (this._extremeTotalEventTime >>> 32));
    508         hash = 67 * hash + (int)(Double.doubleToLongBits(this._lifetimeTotalValue) ^ (Double.doubleToLongBits(this._lifetimeTotalValue) >>> 32));
    509         hash = 67 * hash + (int)(this._lifetimeEventCount ^ (this._lifetimeEventCount >>> 32));
    510         hash = 67 * hash + (int)(this._lifetimeTotalEventTime ^ (this._lifetimeTotalEventTime >>> 32));
    511         hash = 67 * hash + (int)(this._creationDate ^ (this._creationDate >>> 32));
    512         hash = 67 * hash + (int)(this._period ^ (this._period >>> 32));
    513         return hash;
    514 ******/
    515         return toString().hashCode();
     496        return DataHelper.hashCode(_stat) ^ ((int)_period) ^ ((int) _creationDate);
    516497    }
    517498
Note: See TracChangeset for help on using the changeset viewer.