Better hashCode methods.

This commit is contained in:
akwizgran
2012-12-14 22:11:29 +00:00
parent 47749c3c0d
commit 13df22f69a
5 changed files with 12 additions and 9 deletions

View File

@@ -26,6 +26,11 @@ public class Transport {
return properties;
}
@Override
public int hashCode() {
return id.hashCode() ^ properties.hashCode();
}
@Override
public boolean equals(Object o) {
if(o instanceof Transport) {
@@ -34,9 +39,4 @@ public class Transport {
}
return false;
}
@Override
public int hashCode() {
return id.hashCode();
}
}

View File

@@ -96,15 +96,17 @@ class PollerImpl implements Poller, Runnable {
this.plugin = plugin;
}
// Must be consistent with equals()
public int compareTo(PollTime p) {
if(time < p.time) return -1;
if(time > p.time) return 1;
return 0;
}
// Must be consistent with equals()
@Override
public int hashCode() {
return (int) time;
return (int) (time ^ (time >>> 32)) ^ plugin.hashCode();
}
@Override

View File

@@ -42,7 +42,8 @@ abstract class Frame {
@Override
public int hashCode() {
return (int) getSequenceNumber();
long sequenceNumber = getSequenceNumber();
return buf[0] ^ (int) (sequenceNumber ^ (sequenceNumber >>> 32));
}
@Override

View File

@@ -352,7 +352,7 @@ class KeyManagerImpl extends TimerTask implements KeyManager, DatabaseListener {
@Override
public int hashCode() {
return contactId.hashCode() + transportId.hashCode();
return contactId.hashCode() ^ transportId.hashCode();
}
@Override

View File

@@ -164,7 +164,7 @@ class TransportConnectionRecogniser {
@Override
public int hashCode() {
return contactId.hashCode() + (int) period;
return contactId.hashCode() ^ (int) (period ^ (period >>> 32));
}
@Override