X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fdata%2Fimpl%2FAlbumImpl.java;h=f87273cf3c62216e47ccca3432bdbc900f45ba9c;hp=46584e877e5511c8429ced27c8f6418016a5bc8d;hb=62573c314957b1851f4fbe693b8746686caa940a;hpb=9f1e09d12a8e07cd235dfb790747e04ecfba3965 diff --git a/src/main/java/net/pterodactylus/sone/data/impl/AlbumImpl.java b/src/main/java/net/pterodactylus/sone/data/impl/AlbumImpl.java index 46584e8..f87273c 100644 --- a/src/main/java/net/pterodactylus/sone/data/impl/AlbumImpl.java +++ b/src/main/java/net/pterodactylus/sone/data/impl/AlbumImpl.java @@ -1,5 +1,5 @@ /* - * Sone - Album.java - Copyright © 2011–2013 David Roden + * Sone - AlbumImpl.java - Copyright © 2011–2016 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 @@ -21,7 +21,6 @@ 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; @@ -42,8 +41,6 @@ import com.google.common.hash.Hashing; /** * Container for images that can also contain nested {@link AlbumImpl}s. - * - * @author David ‘Bombe’ Roden */ public class AlbumImpl implements Album { @@ -71,9 +68,6 @@ public class AlbumImpl implements Album { /** 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(Sone sone) { this(sone, UUID.randomUUID().toString()); @@ -135,7 +129,7 @@ public class AlbumImpl implements Album { checkArgument(equals(album.getParent()), "album must belong to this album"); int oldIndex = albums.indexOf(album); if (oldIndex <= 0) { - return null; + return album; } albums.remove(oldIndex); albums.add(oldIndex - 1, album); @@ -149,7 +143,7 @@ public class AlbumImpl implements 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; + return album; } albums.remove(oldIndex); albums.add(oldIndex + 1, album); @@ -177,9 +171,6 @@ public class AlbumImpl implements Album { image.getAlbum().removeImage(image); } image.setAlbum(this); - if (imageIds.isEmpty() && (albumImage == null)) { - albumImage = image.getId(); - } if (!imageIds.contains(image.getId())) { imageIds.add(image.getId()); images.put(image.getId(), image); @@ -193,13 +184,6 @@ public class AlbumImpl implements Album { 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 @@ -210,7 +194,7 @@ public class AlbumImpl implements Album { checkArgument(image.getAlbum().equals(this), "image must belong to this album"); int oldIndex = imageIds.indexOf(image.getId()); if (oldIndex <= 0) { - return null; + return image; } imageIds.remove(image.getId()); imageIds.add(oldIndex - 1, image.getId()); @@ -225,7 +209,7 @@ public class AlbumImpl implements 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; + return image; } imageIds.remove(image.getId()); imageIds.add(oldIndex + 1, image.getId()); @@ -233,14 +217,6 @@ public class AlbumImpl implements Album { } @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(); } @@ -285,8 +261,6 @@ public class AlbumImpl implements Album { private Optional description = absent(); - private Optional albumImage = absent(); - @Override public Modifier setTitle(String title) { this.title = fromNullable(title); @@ -300,12 +274,6 @@ public class AlbumImpl implements Album { } @Override - public Modifier setAlbumImage(String imageId) { - this.albumImage = fromNullable(imageId); - return this; - } - - @Override public Album update() throws IllegalStateException { if (title.isPresent() && title.get().trim().isEmpty()) { throw new AlbumTitleMustNotBeEmpty(); @@ -316,16 +284,11 @@ public class AlbumImpl implements Album { if (description.isPresent()) { AlbumImpl.this.description = description.get(); } - if (albumImage.isPresent()) { - AlbumImpl.this.albumImage = albumImage.get(); - } return AlbumImpl.this; } }; } - public static class AlbumTitleMustNotBeEmpty extends IllegalStateException { } - // // FINGERPRINTABLE METHODS // @@ -337,9 +300,6 @@ public class AlbumImpl implements 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(");