Override hashCode() and equals() in Phrase.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 12 Jul 2011 04:54:53 +0000 (06:54 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 12 Jul 2011 04:54:53 +0000 (06:54 +0200)
src/main/java/net/pterodactylus/sone/web/SearchPage.java

index 2a1c1b0..c1b7c3c 100644 (file)
@@ -413,6 +413,30 @@ public class SearchPage extends SoneTemplatePage {
                        return optionality;
                }
 
+               //
+               // OBJECT METHODS
+               //
+
+               /**
+                * {@inheritDoc}
+                */
+               @Override
+               public int hashCode() {
+                       return phrase.hashCode() ^ ((optionality == Optionality.FORBIDDEN) ? (0xaaaaaaaa) : ((optionality == Optionality.REQUIRED) ? 0x55555555 : 0));
+               }
+
+               /**
+                * {@inheritDoc}
+                */
+               @Override
+               public boolean equals(Object object) {
+                       if (!(object instanceof Phrase)) {
+                               return false;
+                       }
+                       Phrase phrase = (Phrase) object;
+                       return (this.optionality == phrase.optionality) && this.phrase.equals(phrase.phrase);
+               }
+
        }
 
        /**