james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fel...@apache.org
Subject svn commit: r1092747 - /james/server/trunk/fetchmail/src/main/java/org/apache/james/fetchmail/Account.java
Date Fri, 15 Apr 2011 15:45:18 GMT
Author: felixk
Date: Fri Apr 15 15:45:17 2011
New Revision: 1092747

URL: http://svn.apache.org/viewvc?rev=1092747&view=rev
Log:
Be on the save side when using java 6. When overriding equals also override hashCode.

This class defines a compareTo(...) method but inherits its equals() method from java.lang.Object.
Generally, the value of compareTo should return zero if and only if equals returns true. If
this is violated, weird and unpredictable failures will occur in classes such as PriorityQueue.
In Java 5 the PriorityQueue.remove method uses the compareTo method, while in Java 6 it uses
the equals method.

>From the JavaDoc for the compareTo method in the Comparable interface:

    It is strongly recommended, but not strictly required that (x.compareTo(y)==0) == (x.equals(y)).
Generally speaking, any class that implements the Comparable interface and violates this condition
should clearly indicate this fact. The recommended language is "Note: this class has a natural
ordering that is inconsistent with equals." 

Modified:
    james/server/trunk/fetchmail/src/main/java/org/apache/james/fetchmail/Account.java

Modified: james/server/trunk/fetchmail/src/main/java/org/apache/james/fetchmail/Account.java
URL: http://svn.apache.org/viewvc/james/server/trunk/fetchmail/src/main/java/org/apache/james/fetchmail/Account.java?rev=1092747&r1=1092746&r2=1092747&view=diff
==============================================================================
--- james/server/trunk/fetchmail/src/main/java/org/apache/james/fetchmail/Account.java (original)
+++ james/server/trunk/fetchmail/src/main/java/org/apache/james/fetchmail/Account.java Fri
Apr 15 15:45:17 2011
@@ -264,6 +264,29 @@ class Account implements Comparable<Acco
     }
 
     /**
+     * {@inheritDoc}
+     */
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj)
+            return true;
+        if (obj == null)
+            return false;
+        if (getClass() != obj.getClass())
+            return false;
+        final Account other = (Account) obj;
+        return getSequenceNumber() == other.getSequenceNumber();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public int hashCode() {
+        return 31 * 17 + getSequenceNumber();
+    }
+
+    /**
      * Returns the deferredRecipientNotFoundMessageIDs. lazily initialised.
      * 
      * @return List



---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message