Override Object.hashCode() and Object.equals().
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 14 Oct 2010 07:02:54 +0000 (09:02 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 14 Oct 2010 07:02:54 +0000 (09:02 +0200)
src/main/java/net/pterodactylus/sone/data/Post.java

index 9cf986f..3c02a1c 100644 (file)
@@ -62,4 +62,28 @@ public class Post {
                return text;
        }
 
+       //
+       // OBJECT METHODS
+       //
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       public int hashCode() {
+               return text.hashCode() ^ (int) (time >> 32) ^ (int) (time & 0xffffffff);
+       }
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       public boolean equals(Object object) {
+               if (!(object instanceof Post)) {
+                       return false;
+               }
+               Post post = (Post) object;
+               return (post.time == time) && (post.text.equals(text));
+       }
+
 }