Rename album and builder implementations.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 12 Oct 2013 12:41:16 +0000 (14:41 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 28 Feb 2014 21:17:43 +0000 (22:17 +0100)
src/main/java/net/pterodactylus/sone/data/AlbumImpl.java [deleted file]
src/main/java/net/pterodactylus/sone/data/SoneImpl.java
src/main/java/net/pterodactylus/sone/data/impl/AlbumBuilderImpl.java [deleted file]
src/main/java/net/pterodactylus/sone/data/impl/DefaultAlbum.java [new file with mode: 0644]
src/main/java/net/pterodactylus/sone/data/impl/DefaultAlbumBuilder.java [new file with mode: 0644]
src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java
src/test/java/net/pterodactylus/sone/database/memory/MemoryDatabaseTest.java

diff --git a/src/main/java/net/pterodactylus/sone/data/AlbumImpl.java b/src/main/java/net/pterodactylus/sone/data/AlbumImpl.java
deleted file mode 100644 (file)
index c236ee1..0000000
+++ /dev/null
@@ -1,381 +0,0 @@
-/*
- * Sone - Album.java - Copyright © 2011–2013 David Roden
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-package net.pterodactylus.sone.data;
-
-import static com.google.common.base.Optional.absent;
-import static com.google.common.base.Optional.fromNullable;
-import static com.google.common.base.Preconditions.checkArgument;
-import static com.google.common.base.Preconditions.checkNotNull;
-import static com.google.common.base.Preconditions.checkState;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
-
-import net.pterodactylus.sone.data.impl.DefaultImageBuilder;
-import net.pterodactylus.sone.database.ImageBuilder;
-
-import com.google.common.base.Function;
-import com.google.common.base.Optional;
-import com.google.common.base.Predicates;
-import com.google.common.collect.Collections2;
-import com.google.common.hash.Hasher;
-import com.google.common.hash.Hashing;
-
-/**
- * Container for images that can also contain nested {@link AlbumImpl}s.
- *
- * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
- */
-public class AlbumImpl implements Album {
-
-       /** The ID of this album. */
-       private final String id;
-
-       /** The Sone this album belongs to. */
-       private Sone sone;
-
-       /** Nested albums. */
-       private final List<Album> albums = new ArrayList<Album>();
-
-       /** The image IDs in order. */
-       private final List<String> imageIds = new ArrayList<String>();
-
-       /** The images in this album. */
-       private final Map<String, Image> images = new HashMap<String, Image>();
-
-       /** The parent album. */
-       private Album parent;
-
-       /** The title of this album. */
-       private String title;
-
-       /** The description of this album. */
-       private String description;
-
-       /** The ID of the album picture. */
-       private String albumImage;
-
-       /** Creates a new album with a random ID. */
-       public AlbumImpl() {
-               this(UUID.randomUUID().toString());
-       }
-
-       /**
-        * Creates a new album with the given ID.
-        *
-        * @param id
-        *              The ID of the album
-        */
-       public AlbumImpl(String id) {
-               this.id = checkNotNull(id, "id must not be null");
-       }
-
-       //
-       // ACCESSORS
-       //
-
-       @Override
-       public String getId() {
-               return id;
-       }
-
-       @Override
-       public Sone getSone() {
-               return sone;
-       }
-
-       @Override
-       public Album setSone(Sone sone) {
-               checkNotNull(sone, "sone must not be null");
-               checkState((this.sone == null) || (this.sone.equals(sone)), "album owner must not already be set to some other Sone");
-               this.sone = sone;
-               return this;
-       }
-
-       @Override
-       public List<Album> getAlbums() {
-               return new ArrayList<Album>(albums);
-       }
-
-       @Override
-       public void addAlbum(Album album) {
-               checkNotNull(album, "album must not be null");
-               checkArgument(album.getSone().equals(sone), "album must belong to the same Sone as this album");
-               album.setParent(this);
-               if (!albums.contains(album)) {
-                       albums.add(album);
-               }
-       }
-
-       @Override
-       public void removeAlbum(Album album) {
-               checkNotNull(album, "album must not be null");
-               checkArgument(album.getSone().equals(sone), "album must belong this album’s Sone");
-               checkArgument(equals(album.getParent()), "album must belong to this album");
-               albums.remove(album);
-               album.removeParent();
-       }
-
-       @Override
-       public Album moveAlbumUp(Album album) {
-               checkNotNull(album, "album must not be null");
-               checkArgument(album.getSone().equals(sone), "album must belong to the same Sone as this album");
-               checkArgument(equals(album.getParent()), "album must belong to this album");
-               int oldIndex = albums.indexOf(album);
-               if (oldIndex <= 0) {
-                       return null;
-               }
-               albums.remove(oldIndex);
-               albums.add(oldIndex - 1, album);
-               return albums.get(oldIndex);
-       }
-
-       @Override
-       public Album moveAlbumDown(Album album) {
-               checkNotNull(album, "album must not be null");
-               checkArgument(album.getSone().equals(sone), "album must belong to the same Sone as this album");
-               checkArgument(equals(album.getParent()), "album must belong to this album");
-               int oldIndex = albums.indexOf(album);
-               if ((oldIndex < 0) || (oldIndex >= (albums.size() - 1))) {
-                       return null;
-               }
-               albums.remove(oldIndex);
-               albums.add(oldIndex + 1, album);
-               return albums.get(oldIndex);
-       }
-
-       @Override
-       public List<Image> getImages() {
-               return new ArrayList<Image>(Collections2.filter(Collections2.transform(imageIds, new Function<String, Image>() {
-
-                       @Override
-                       @SuppressWarnings("synthetic-access")
-                       public Image apply(String imageId) {
-                               return images.get(imageId);
-                       }
-               }), Predicates.notNull()));
-       }
-
-       @Override
-       public void removeImage(Image image) {
-               checkNotNull(image, "image must not be null");
-               checkNotNull(image.getSone(), "image must have an owner");
-               checkArgument(image.getSone().equals(sone), "image must belong to the same Sone as this album");
-               imageIds.remove(image.getId());
-               images.remove(image.getId());
-               if (image.getId().equals(albumImage)) {
-                       if (images.isEmpty()) {
-                               albumImage = null;
-                       } else {
-                               albumImage = images.values().iterator().next().getId();
-                       }
-               }
-       }
-
-       @Override
-       public Image moveImageUp(Image image) {
-               checkNotNull(image, "image must not be null");
-               checkNotNull(image.getSone(), "image must have an owner");
-               checkArgument(image.getSone().equals(sone), "image must belong to the same Sone as this album");
-               checkArgument(image.getAlbum().equals(this), "image must belong to this album");
-               int oldIndex = imageIds.indexOf(image.getId());
-               if (oldIndex <= 0) {
-                       return null;
-               }
-               imageIds.remove(image.getId());
-               imageIds.add(oldIndex - 1, image.getId());
-               return images.get(imageIds.get(oldIndex));
-       }
-
-       @Override
-       public Image moveImageDown(Image image) {
-               checkNotNull(image, "image must not be null");
-               checkNotNull(image.getSone(), "image must have an owner");
-               checkArgument(image.getSone().equals(sone), "image must belong to the same Sone as this album");
-               checkArgument(image.getAlbum().equals(this), "image must belong to this album");
-               int oldIndex = imageIds.indexOf(image.getId());
-               if ((oldIndex == -1) || (oldIndex >= (imageIds.size() - 1))) {
-                       return null;
-               }
-               imageIds.remove(image.getId());
-               imageIds.add(oldIndex + 1, image.getId());
-               return images.get(imageIds.get(oldIndex));
-       }
-
-       @Override
-       public Image getAlbumImage() {
-               if (albumImage == null) {
-                       return null;
-               }
-               return Optional.fromNullable(images.get(albumImage)).or(images.values().iterator().next());
-       }
-
-       @Override
-       public boolean isEmpty() {
-               return albums.isEmpty() && images.isEmpty();
-       }
-
-       @Override
-       public boolean isRoot() {
-               return parent == null;
-       }
-
-       @Override
-       public Album getParent() {
-               return parent;
-       }
-
-       @Override
-       public Album setParent(Album parent) {
-               this.parent = checkNotNull(parent, "parent must not be null");
-               return this;
-       }
-
-       @Override
-       public Album removeParent() {
-               this.parent = null;
-               return this;
-       }
-
-       @Override
-       public String getTitle() {
-               return title;
-       }
-
-       @Override
-       public String getDescription() {
-               return description;
-       }
-
-       @Override
-       public ImageBuilder newImageBuilder() throws IllegalStateException {
-               return new DefaultImageBuilder(this) {
-                       @Override
-                       public Image build() throws IllegalStateException {
-                               Image image = super.build();
-                               if (images.isEmpty() && (albumImage == null)) {
-                                       albumImage = image.getId();
-                               }
-                               images.put(image.getId(), image);
-                               imageIds.add(image.getId());
-                               return image;
-                       }
-               };
-       }
-
-       @Override
-       public Modifier modify() throws IllegalStateException {
-               // TODO: reenable check for local Sones
-               return new Modifier() {
-                       private Optional<String> title = absent();
-
-                       private Optional<String> description = absent();
-
-                       private Optional<String> albumImage = absent();
-
-                       @Override
-                       public Modifier setTitle(String title) {
-                               this.title = fromNullable(title);
-                               return this;
-                       }
-
-                       @Override
-                       public Modifier setDescription(String description) {
-                               this.description = fromNullable(description);
-                               return this;
-                       }
-
-                       @Override
-                       public Modifier setAlbumImage(String imageId) {
-                               this.albumImage = fromNullable(imageId);
-                               return this;
-                       }
-
-                       @Override
-                       public Album update() throws IllegalStateException {
-                               if (title.isPresent()) {
-                                       AlbumImpl.this.title = title.get();
-                               }
-                               if (description.isPresent()) {
-                                       AlbumImpl.this.description = description.get();
-                               }
-                               if (albumImage.isPresent()) {
-                                       AlbumImpl.this.albumImage = albumImage.get();
-                               }
-                               return AlbumImpl.this;
-                       }
-               };
-       }
-
-       //
-       // FINGERPRINTABLE METHODS
-       //
-
-       @Override
-       public String getFingerprint() {
-               Hasher hash = Hashing.sha256().newHasher();
-               hash.putString("Album(");
-               hash.putString("ID(").putString(id).putString(")");
-               hash.putString("Title(").putString(title).putString(")");
-               hash.putString("Description(").putString(description).putString(")");
-               if (albumImage != null) {
-                       hash.putString("AlbumImage(").putString(albumImage).putString(")");
-               }
-
-               /* add nested albums. */
-               hash.putString("Albums(");
-               for (Album album : albums) {
-                       hash.putString(album.getFingerprint());
-               }
-               hash.putString(")");
-
-               /* add images. */
-               hash.putString("Images(");
-               for (Image image : getImages()) {
-                       if (image.isInserted()) {
-                               hash.putString(image.getFingerprint());
-                       }
-               }
-               hash.putString(")");
-
-               hash.putString(")");
-               return hash.hash().toString();
-       }
-
-       //
-       // OBJECT METHODS
-       //
-
-       @Override
-       public int hashCode() {
-               return id.hashCode();
-       }
-
-       @Override
-       public boolean equals(Object object) {
-               if (!(object instanceof AlbumImpl)) {
-                       return false;
-               }
-               AlbumImpl album = (AlbumImpl) object;
-               return id.equals(album.id);
-       }
-
-}
index 880eb95..8e35d32 100644 (file)
@@ -29,6 +29,7 @@ import java.util.logging.Level;
 import java.util.logging.Logger;
 
 import net.pterodactylus.sone.core.Options;
+import net.pterodactylus.sone.data.impl.DefaultAlbum;
 import net.pterodactylus.sone.freenet.wot.Identity;
 import net.pterodactylus.util.logging.Logging;
 
@@ -99,7 +100,7 @@ public class SoneImpl implements Sone {
        private final Set<String> likedReplyIds = new CopyOnWriteArraySet<String>();
 
        /** The root album containing all albums. */
-       private final Album rootAlbum = new AlbumImpl().setSone(this);
+       private final Album rootAlbum = new DefaultAlbum().setSone(this);
 
        /** Sone-specific options. */
        private Options options = new Options();
diff --git a/src/main/java/net/pterodactylus/sone/data/impl/AlbumBuilderImpl.java b/src/main/java/net/pterodactylus/sone/data/impl/AlbumBuilderImpl.java
deleted file mode 100644 (file)
index 3403a62..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Sone - MemoryAlbumBuilder.java - Copyright © 2013 David Roden
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-package net.pterodactylus.sone.data.impl;
-
-import net.pterodactylus.sone.data.Album;
-import net.pterodactylus.sone.data.AlbumImpl;
-import net.pterodactylus.sone.database.AlbumBuilder;
-
-/**
- * {@link AlbumBuilder} implementation that creates {@link AlbumImpl} objects.
- *
- * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
- */
-public class AlbumBuilderImpl extends AbstractAlbumBuilder {
-
-       @Override
-       public Album build() throws IllegalStateException {
-               validate();
-               return randomId ? new AlbumImpl() : new AlbumImpl(id);
-       }
-
-}
diff --git a/src/main/java/net/pterodactylus/sone/data/impl/DefaultAlbum.java b/src/main/java/net/pterodactylus/sone/data/impl/DefaultAlbum.java
new file mode 100644 (file)
index 0000000..70fac0d
--- /dev/null
@@ -0,0 +1,383 @@
+/*
+ * Sone - Album.java - Copyright © 2011–2013 David Roden
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package net.pterodactylus.sone.data.impl;
+
+import static com.google.common.base.Optional.absent;
+import static com.google.common.base.Optional.fromNullable;
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkNotNull;
+import static com.google.common.base.Preconditions.checkState;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+import net.pterodactylus.sone.data.Album;
+import net.pterodactylus.sone.data.Image;
+import net.pterodactylus.sone.data.Sone;
+import net.pterodactylus.sone.database.ImageBuilder;
+
+import com.google.common.base.Function;
+import com.google.common.base.Optional;
+import com.google.common.base.Predicates;
+import com.google.common.collect.Collections2;
+import com.google.common.hash.Hasher;
+import com.google.common.hash.Hashing;
+
+/**
+ * Container for images that can also contain nested {@link Album}s.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class DefaultAlbum implements Album {
+
+       /** The ID of this album. */
+       private final String id;
+
+       /** The Sone this album belongs to. */
+       private Sone sone;
+
+       /** Nested albums. */
+       private final List<Album> albums = new ArrayList<Album>();
+
+       /** The image IDs in order. */
+       private final List<String> imageIds = new ArrayList<String>();
+
+       /** The images in this album. */
+       private final Map<String, Image> images = new HashMap<String, Image>();
+
+       /** The parent album. */
+       private Album parent;
+
+       /** The title of this album. */
+       private String title;
+
+       /** The description of this album. */
+       private String description;
+
+       /** The ID of the album picture. */
+       private String albumImage;
+
+       /** Creates a new album with a random ID. */
+       public DefaultAlbum() {
+               this(UUID.randomUUID().toString());
+       }
+
+       /**
+        * Creates a new album with the given ID.
+        *
+        * @param id
+        *              The ID of the album
+        */
+       public DefaultAlbum(String id) {
+               this.id = checkNotNull(id, "id must not be null");
+       }
+
+       //
+       // ACCESSORS
+       //
+
+       @Override
+       public String getId() {
+               return id;
+       }
+
+       @Override
+       public Sone getSone() {
+               return sone;
+       }
+
+       @Override
+       public Album setSone(Sone sone) {
+               checkNotNull(sone, "sone must not be null");
+               checkState((this.sone == null) || (this.sone.equals(sone)), "album owner must not already be set to some other Sone");
+               this.sone = sone;
+               return this;
+       }
+
+       @Override
+       public List<Album> getAlbums() {
+               return new ArrayList<Album>(albums);
+       }
+
+       @Override
+       public void addAlbum(Album album) {
+               checkNotNull(album, "album must not be null");
+               checkArgument(album.getSone().equals(sone), "album must belong to the same Sone as this album");
+               album.setParent(this);
+               if (!albums.contains(album)) {
+                       albums.add(album);
+               }
+       }
+
+       @Override
+       public void removeAlbum(Album album) {
+               checkNotNull(album, "album must not be null");
+               checkArgument(album.getSone().equals(sone), "album must belong this album’s Sone");
+               checkArgument(equals(album.getParent()), "album must belong to this album");
+               albums.remove(album);
+               album.removeParent();
+       }
+
+       @Override
+       public Album moveAlbumUp(Album album) {
+               checkNotNull(album, "album must not be null");
+               checkArgument(album.getSone().equals(sone), "album must belong to the same Sone as this album");
+               checkArgument(equals(album.getParent()), "album must belong to this album");
+               int oldIndex = albums.indexOf(album);
+               if (oldIndex <= 0) {
+                       return null;
+               }
+               albums.remove(oldIndex);
+               albums.add(oldIndex - 1, album);
+               return albums.get(oldIndex);
+       }
+
+       @Override
+       public Album moveAlbumDown(Album album) {
+               checkNotNull(album, "album must not be null");
+               checkArgument(album.getSone().equals(sone), "album must belong to the same Sone as this album");
+               checkArgument(equals(album.getParent()), "album must belong to this album");
+               int oldIndex = albums.indexOf(album);
+               if ((oldIndex < 0) || (oldIndex >= (albums.size() - 1))) {
+                       return null;
+               }
+               albums.remove(oldIndex);
+               albums.add(oldIndex + 1, album);
+               return albums.get(oldIndex);
+       }
+
+       @Override
+       public List<Image> getImages() {
+               return new ArrayList<Image>(Collections2.filter(Collections2.transform(imageIds, new Function<String, Image>() {
+
+                       @Override
+                       @SuppressWarnings("synthetic-access")
+                       public Image apply(String imageId) {
+                               return images.get(imageId);
+                       }
+               }), Predicates.notNull()));
+       }
+
+       @Override
+       public void removeImage(Image image) {
+               checkNotNull(image, "image must not be null");
+               checkNotNull(image.getSone(), "image must have an owner");
+               checkArgument(image.getSone().equals(sone), "image must belong to the same Sone as this album");
+               imageIds.remove(image.getId());
+               images.remove(image.getId());
+               if (image.getId().equals(albumImage)) {
+                       if (images.isEmpty()) {
+                               albumImage = null;
+                       } else {
+                               albumImage = images.values().iterator().next().getId();
+                       }
+               }
+       }
+
+       @Override
+       public Image moveImageUp(Image image) {
+               checkNotNull(image, "image must not be null");
+               checkNotNull(image.getSone(), "image must have an owner");
+               checkArgument(image.getSone().equals(sone), "image must belong to the same Sone as this album");
+               checkArgument(image.getAlbum().equals(this), "image must belong to this album");
+               int oldIndex = imageIds.indexOf(image.getId());
+               if (oldIndex <= 0) {
+                       return null;
+               }
+               imageIds.remove(image.getId());
+               imageIds.add(oldIndex - 1, image.getId());
+               return images.get(imageIds.get(oldIndex));
+       }
+
+       @Override
+       public Image moveImageDown(Image image) {
+               checkNotNull(image, "image must not be null");
+               checkNotNull(image.getSone(), "image must have an owner");
+               checkArgument(image.getSone().equals(sone), "image must belong to the same Sone as this album");
+               checkArgument(image.getAlbum().equals(this), "image must belong to this album");
+               int oldIndex = imageIds.indexOf(image.getId());
+               if ((oldIndex == -1) || (oldIndex >= (imageIds.size() - 1))) {
+                       return null;
+               }
+               imageIds.remove(image.getId());
+               imageIds.add(oldIndex + 1, image.getId());
+               return images.get(imageIds.get(oldIndex));
+       }
+
+       @Override
+       public Image getAlbumImage() {
+               if (albumImage == null) {
+                       return null;
+               }
+               return Optional.fromNullable(images.get(albumImage)).or(images.values().iterator().next());
+       }
+
+       @Override
+       public boolean isEmpty() {
+               return albums.isEmpty() && images.isEmpty();
+       }
+
+       @Override
+       public boolean isRoot() {
+               return parent == null;
+       }
+
+       @Override
+       public Album getParent() {
+               return parent;
+       }
+
+       @Override
+       public Album setParent(Album parent) {
+               this.parent = checkNotNull(parent, "parent must not be null");
+               return this;
+       }
+
+       @Override
+       public Album removeParent() {
+               this.parent = null;
+               return this;
+       }
+
+       @Override
+       public String getTitle() {
+               return title;
+       }
+
+       @Override
+       public String getDescription() {
+               return description;
+       }
+
+       @Override
+       public ImageBuilder newImageBuilder() throws IllegalStateException {
+               return new DefaultImageBuilder(this) {
+                       @Override
+                       public Image build() throws IllegalStateException {
+                               Image image = super.build();
+                               if (images.isEmpty() && (albumImage == null)) {
+                                       albumImage = image.getId();
+                               }
+                               images.put(image.getId(), image);
+                               imageIds.add(image.getId());
+                               return image;
+                       }
+               };
+       }
+
+       @Override
+       public Modifier modify() throws IllegalStateException {
+               // TODO: reenable check for local Sones
+               return new Modifier() {
+                       private Optional<String> title = absent();
+
+                       private Optional<String> description = absent();
+
+                       private Optional<String> albumImage = absent();
+
+                       @Override
+                       public Modifier setTitle(String title) {
+                               this.title = fromNullable(title);
+                               return this;
+                       }
+
+                       @Override
+                       public Modifier setDescription(String description) {
+                               this.description = fromNullable(description);
+                               return this;
+                       }
+
+                       @Override
+                       public Modifier setAlbumImage(String imageId) {
+                               this.albumImage = fromNullable(imageId);
+                               return this;
+                       }
+
+                       @Override
+                       public Album update() throws IllegalStateException {
+                               if (title.isPresent()) {
+                                       DefaultAlbum.this.title = title.get();
+                               }
+                               if (description.isPresent()) {
+                                       DefaultAlbum.this.description = description.get();
+                               }
+                               if (albumImage.isPresent()) {
+                                       DefaultAlbum.this.albumImage = albumImage.get();
+                               }
+                               return DefaultAlbum.this;
+                       }
+               };
+       }
+
+       //
+       // FINGERPRINTABLE METHODS
+       //
+
+       @Override
+       public String getFingerprint() {
+               Hasher hash = Hashing.sha256().newHasher();
+               hash.putString("Album(");
+               hash.putString("ID(").putString(id).putString(")");
+               hash.putString("Title(").putString(title).putString(")");
+               hash.putString("Description(").putString(description).putString(")");
+               if (albumImage != null) {
+                       hash.putString("AlbumImage(").putString(albumImage).putString(")");
+               }
+
+               /* add nested albums. */
+               hash.putString("Albums(");
+               for (Album album : albums) {
+                       hash.putString(album.getFingerprint());
+               }
+               hash.putString(")");
+
+               /* add images. */
+               hash.putString("Images(");
+               for (Image image : getImages()) {
+                       if (image.isInserted()) {
+                               hash.putString(image.getFingerprint());
+                       }
+               }
+               hash.putString(")");
+
+               hash.putString(")");
+               return hash.hash().toString();
+       }
+
+       //
+       // OBJECT METHODS
+       //
+
+       @Override
+       public int hashCode() {
+               return id.hashCode();
+       }
+
+       @Override
+       public boolean equals(Object object) {
+               if (!(object instanceof DefaultAlbum)) {
+                       return false;
+               }
+               DefaultAlbum album = (DefaultAlbum) object;
+               return id.equals(album.id);
+       }
+
+}
diff --git a/src/main/java/net/pterodactylus/sone/data/impl/DefaultAlbumBuilder.java b/src/main/java/net/pterodactylus/sone/data/impl/DefaultAlbumBuilder.java
new file mode 100644 (file)
index 0000000..f3e771c
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * Sone - MemoryAlbumBuilder.java - Copyright © 2013 David Roden
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package net.pterodactylus.sone.data.impl;
+
+import net.pterodactylus.sone.data.Album;
+import net.pterodactylus.sone.database.AlbumBuilder;
+
+/**
+ * {@link AlbumBuilder} implementation that creates {@link DefaultAlbum} objects.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class DefaultAlbumBuilder extends AbstractAlbumBuilder {
+
+       @Override
+       public Album build() throws IllegalStateException {
+               validate();
+               return randomId ? new DefaultAlbum() : new DefaultAlbum(id);
+       }
+
+}
index dc827f0..babe6fe 100644 (file)
@@ -40,7 +40,7 @@ import net.pterodactylus.sone.data.Post;
 import net.pterodactylus.sone.data.PostReply;
 import net.pterodactylus.sone.data.Reply;
 import net.pterodactylus.sone.data.Sone;
-import net.pterodactylus.sone.data.impl.AlbumBuilderImpl;
+import net.pterodactylus.sone.data.impl.DefaultAlbumBuilder;
 import net.pterodactylus.sone.database.AlbumBuilder;
 import net.pterodactylus.sone.database.Database;
 import net.pterodactylus.sone.database.DatabaseException;
@@ -440,7 +440,7 @@ public class MemoryDatabase extends AbstractService implements Database {
 
        @Override
        public AlbumBuilder newAlbumBuilder() {
-               return new AlbumBuilderImpl();
+               return new DefaultAlbumBuilder();
        }
 
        //
index 056a06d..a1c2dbb 100644 (file)
@@ -22,7 +22,7 @@ import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
 
 import net.pterodactylus.sone.data.Album;
-import net.pterodactylus.sone.data.AlbumImpl;
+import net.pterodactylus.sone.data.impl.DefaultAlbum;
 
 import com.google.common.base.Optional;
 import org.junit.Test;
@@ -38,7 +38,7 @@ public class MemoryDatabaseTest {
 
        @Test
        public void testBasicAlbumFunctionality() {
-               Album newAlbum = new AlbumImpl();
+               Album newAlbum = new DefaultAlbum();
                assertThat(memoryDatabase.getAlbum(newAlbum.getId()), is(Optional.<Album>absent()));
                memoryDatabase.storeAlbum(newAlbum);
                assertThat(memoryDatabase.getAlbum(newAlbum.getId()), is(of(newAlbum)));