X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fdata%2FAlbumImpl.java;h=b60e99e1032d0905b6fcd66c01e1eb590751f2a0;hb=ec06ae64c86f0b06bb0cf9f8b289e7907e81dffa;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..b60e99e 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; @@ -45,7 +47,7 @@ public class AlbumImpl implements Album { private final String id; /** The Sone this album belongs to. */ - private Sone sone; + private final Sone sone; /** Nested albums. */ private final List albums = new ArrayList(); @@ -69,8 +71,8 @@ public class AlbumImpl implements Album { private String albumImage; /** Creates a new album with a random ID. */ - public AlbumImpl() { - this(UUID.randomUUID().toString()); + public AlbumImpl(Sone sone) { + this(sone, UUID.randomUUID().toString()); } /** @@ -79,7 +81,8 @@ public class AlbumImpl implements Album { * @param id * The ID of the album */ - public AlbumImpl(String id) { + public AlbumImpl(Sone sone, String id) { + this.sone = checkNotNull(sone, "Sone must not be null"); this.id = checkNotNull(id, "id must not be null"); } @@ -98,14 +101,6 @@ public class AlbumImpl implements Album { } @Override - public Album setSone(Sone sone) { - checkNotNull(sone, "sone must not be null"); - checkState((this.sone == null) || (this.sone.equals(sone)), "album owner must not already be set to some other Sone"); - this.sone = sone; - return this; - } - - @Override public List getAlbums() { return new ArrayList(albums); } @@ -242,12 +237,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 +269,52 @@ public class AlbumImpl implements Album { } @Override - public Album setTitle(String title) { - this.title = checkNotNull(title, "title must not be null"); - return this; - } - - @Override public String getDescription() { return description; } @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; + } + }; } //