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=3ec362f4cfa517dcc7825ee921b1ac16abb67a7d;hp=348857739cdcfae1d9ac39589dc15d52f84b7013;hb=b9fc06f5bf20b1c0d5e7c5e9b49e87581a843ee7;hpb=a80191ba660bd732bbd852197cd2d10f619af9d6 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 3488577..3ec362f 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–2019 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,6 +21,7 @@ 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 java.nio.charset.StandardCharsets.UTF_8; import java.util.ArrayList; import java.util.HashMap; @@ -41,8 +42,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 { @@ -53,13 +52,13 @@ public class AlbumImpl implements Album { private final Sone sone; /** Nested albums. */ - private final List albums = new ArrayList(); + private final List albums = new ArrayList<>(); /** The image IDs in order. */ - private final List imageIds = new ArrayList(); + private final List imageIds = new ArrayList<>(); /** The images in this album. */ - private final Map images = new HashMap(); + private final Map images = new HashMap<>(); /** The parent album. */ private Album parent; @@ -70,9 +69,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()); @@ -105,7 +101,7 @@ public class AlbumImpl implements Album { @Override public List getAlbums() { - return new ArrayList(albums); + return new ArrayList<>(albums); } @Override @@ -157,7 +153,7 @@ public class AlbumImpl implements Album { @Override public List getImages() { - return new ArrayList(Collections2.filter(Collections2.transform(imageIds, new Function() { + return new ArrayList<>(Collections2.filter(Collections2.transform(imageIds, new Function() { @Override @SuppressWarnings("synthetic-access") @@ -176,9 +172,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); @@ -192,13 +185,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 @@ -232,14 +218,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(); } @@ -284,8 +262,6 @@ public class AlbumImpl implements Album { private Optional description = absent(); - private Optional albumImage = absent(); - @Override public Modifier setTitle(String title) { this.title = fromNullable(title); @@ -299,12 +275,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(); @@ -315,9 +285,6 @@ public class AlbumImpl implements Album { if (description.isPresent()) { AlbumImpl.this.description = description.get(); } - if (albumImage.isPresent()) { - AlbumImpl.this.albumImage = albumImage.get(); - } return AlbumImpl.this; } }; @@ -330,31 +297,28 @@ public class AlbumImpl implements Album { @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(")"); - } + hash.putString("Album(", UTF_8); + hash.putString("ID(", UTF_8).putString(id, UTF_8).putString(")", UTF_8); + hash.putString("Title(", UTF_8).putString(title, UTF_8).putString(")", UTF_8); + hash.putString("Description(", UTF_8).putString(description, UTF_8).putString(")", UTF_8); /* add nested albums. */ - hash.putString("Albums("); + hash.putString("Albums(", UTF_8); for (Album album : albums) { - hash.putString(album.getFingerprint()); + hash.putString(album.getFingerprint(), UTF_8); } - hash.putString(")"); + hash.putString(")", UTF_8); /* add images. */ - hash.putString("Images("); + hash.putString("Images(", UTF_8); for (Image image : getImages()) { if (image.isInserted()) { - hash.putString(image.getFingerprint()); + hash.putString(image.getFingerprint(), UTF_8); } } - hash.putString(")"); + hash.putString(")", UTF_8); - hash.putString(")"); + hash.putString(")", UTF_8); return hash.hash().toString(); }