Override Object.hashCode() and Object.equals().
[Sone.git] / src / main / java / net / pterodactylus / sone / data / Post.java
index 8c7ac51..3c02a1c 100644 (file)
@@ -49,7 +49,7 @@ public class Post {
         *
         * @return The time of the post (in milliseconds since Jan 1, 1970 UTC)
         */
-       public long time() {
+       public long getTime() {
                return time;
        }
 
@@ -58,8 +58,32 @@ public class Post {
         *
         * @return The text of the post
         */
-       public String text() {
+       public String getText() {
                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));
+       }
+
 }