X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fdata%2FAlbumImpl.java;h=c236ee1b3384a8f945523b170fbcee9e1462350f;hb=a121cba206f6455c6cf2d34519995a3c7305ad4c;hp=5422812288e1426a612deef165516c8601cbb088;hpb=32829fc3533dd94ebc1c5fe025caaa3b620886d5;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/data/AlbumImpl.java b/src/main/java/net/pterodactylus/sone/data/AlbumImpl.java index 5422812..c236ee1 100644 --- a/src/main/java/net/pterodactylus/sone/data/AlbumImpl.java +++ b/src/main/java/net/pterodactylus/sone/data/AlbumImpl.java @@ -29,9 +29,11 @@ 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.Preconditions; import com.google.common.base.Predicates; import com.google.common.collect.Collections2; import com.google.common.hash.Hasher; @@ -173,24 +175,6 @@ public class AlbumImpl implements Album { } @Override - public void addImage(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"); - if (image.getAlbum() != null) { - 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); - } - } - - @Override public void removeImage(Image image) { checkNotNull(image, "image must not be null"); checkNotNull(image.getSone(), "image must have an owner"); @@ -282,8 +266,24 @@ public class AlbumImpl implements Album { } @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 { - Preconditions.checkState(getSone().isLocal(), "album must belong to a local Sone"); + // TODO: reenable check for local Sones return new Modifier() { private Optional title = absent(); @@ -311,7 +311,6 @@ public class AlbumImpl implements Album { @Override public Album update() throws IllegalStateException { - checkState(!albumImage.isPresent(), "album image must belong to this album"); if (title.isPresent()) { AlbumImpl.this.title = title.get(); }