Don’t implement equals() without hashCode()!
[Sone.git] / src / main / java / net / pterodactylus / sone / data / Album.java
index 4f52f50..601e68d 100644 (file)
@@ -51,6 +51,9 @@ public class Album implements Fingerprintable {
        /** The description of this album. */
        private String description;
 
+       /** The index of the album picture. */
+       private int albumImage = -1;
+
        /**
         * Creates a new album with a random ID.
         */
@@ -154,7 +157,7 @@ public class Album implements Fingerprintable {
         *            The image to add
         */
        public void addImage(Image image) {
-               Validation.begin().isNotNull("Image", image).check().isEqual("Image Owner", image.getSone(), sone).check();
+               Validation.begin().isNotNull("Image", image).check().isNotNull("Image Owner", image.getSone()).check().isEqual("Image Owner", image.getSone(), sone).check();
                images.add(image);
        }
 
@@ -170,6 +173,19 @@ public class Album implements Fingerprintable {
        }
 
        /**
+        * Returns the album image of this album, or {@code null} if no album image
+        * has been set.
+        *
+        * @return The image to show when this album is listed
+        */
+       public Image getAlbumImage() {
+               if (albumImage == -1) {
+                       return null;
+               }
+               return images.get(albumImage);
+       }
+
+       /**
         * Returns the parent album of this album.
         *
         * @return The parent album of this album, or {@code null} if this album
@@ -288,6 +304,14 @@ public class Album implements Fingerprintable {
         * {@inheritDoc}
         */
        @Override
+       public int hashCode() {
+               return id.hashCode();
+       }
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
        public boolean equals(Object object) {
                if (!(object instanceof Album)) {
                        return false;