Merge branch 'release-0.8.9'
[Sone.git] / src / main / java / net / pterodactylus / sone / data / AlbumImpl.java
index 56c44aa..f489b0b 100644 (file)
@@ -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;
@@ -242,12 +244,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 +276,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<String> title = absent();
+
+                       private Optional<String> description = absent();
+
+                       private Optional<String> 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;
+                       }
+               };
        }
 
        //