X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fdata%2Fimpl%2FDefaultAlbum.java;h=7102bfe2935efb9f03d7298ccb1d6156c8c7b86d;hb=28b2e2b0d2ff2320f5b6a5ac36a858a604c7c7ba;hp=161cdd96d78a7a1be2fbd327d14f32609bc056c7;hpb=84e3f241029a4a0a63069a0a793b4f09408d3ca6;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/data/impl/DefaultAlbum.java b/src/main/java/net/pterodactylus/sone/data/impl/DefaultAlbum.java index 161cdd9..7102bfe 100644 --- a/src/main/java/net/pterodactylus/sone/data/impl/DefaultAlbum.java +++ b/src/main/java/net/pterodactylus/sone/data/impl/DefaultAlbum.java @@ -17,8 +17,8 @@ package net.pterodactylus.sone.data.impl; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Optional.absent; +import static com.google.common.base.Optional.fromNullable; import static com.google.common.base.Preconditions.checkState; import java.util.ArrayList; @@ -104,41 +104,11 @@ public class DefaultAlbum extends AbstractAlbum { } @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() { + public Optional getAlbumImage() { if (albumImage == null) { - return null; + return absent(); } - return Optional.fromNullable(images.get(albumImage)).or(images.values().iterator().next()); + return fromNullable(fromNullable(images.get(albumImage)).or(images.values().iterator().next())); } @Override