X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fdata%2FAlbumImpl.java;h=5ee0c2368ee53de7d28b0d23c3d79b4e1cad2198;hb=fc2165a3e44887c18d6faca054cc4efa384ca797;hp=56c44aa54224abed00fc9ec8bdcfbc72b31a422b;hpb=f313a48bfc36f9968d18b76436739c093b562b7a;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 56c44aa..5ee0c23 100644 --- a/src/main/java/net/pterodactylus/sone/data/AlbumImpl.java +++ b/src/main/java/net/pterodactylus/sone/data/AlbumImpl.java @@ -17,6 +17,8 @@ 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; @@ -27,6 +29,9 @@ import java.util.List; import java.util.Map; import java.util.UUID; +import net.pterodactylus.sone.data.impl.ImageBuilderImpl; +import net.pterodactylus.sone.database.ImageBuilder; + import com.google.common.base.Function; import com.google.common.base.Optional; import com.google.common.base.Predicates; @@ -170,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"); @@ -242,12 +229,6 @@ public class AlbumImpl implements Album { } @Override - public AlbumImpl setAlbumImage(String id) { - this.albumImage = id; - return this; - } - - @Override public boolean isEmpty() { return albums.isEmpty() && images.isEmpty(); } @@ -280,20 +261,68 @@ public class AlbumImpl implements Album { } @Override - public Album setTitle(String title) { - this.title = checkNotNull(title, "title must not be null"); - return this; + public String getDescription() { + return description; } @Override - public String getDescription() { - return description; + public ImageBuilder newImageBuilder() throws IllegalStateException { + return new ImageBuilderImpl(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 AlbumImpl setDescription(String description) { - this.description = checkNotNull(description, "description must not be null"); - return this; + public Modifier modify() throws IllegalStateException { + // TODO: reenable check for local Sones + return new Modifier() { + private Optional title = absent(); + + private Optional description = absent(); + + private Optional 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; + } + }; } //