Move default Sone implementation to better package.
[Sone.git] / src / main / java / net / pterodactylus / sone / data / AlbumImpl.java
index 5422812..bb32d75 100644 (file)
@@ -31,7 +31,6 @@ import java.util.UUID;
 
 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;
@@ -48,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<Album> albums = new ArrayList<Album>();
@@ -72,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());
        }
 
        /**
@@ -82,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");
        }
 
@@ -101,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<Album> getAlbums() {
                return new ArrayList<Album>(albums);
        }
@@ -283,7 +275,7 @@ public class AlbumImpl implements Album {
 
        @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<String> title = absent();
 
@@ -311,7 +303,9 @@ public class AlbumImpl implements Album {
 
                        @Override
                        public Album update() throws IllegalStateException {
-                               checkState(!albumImage.isPresent(), "album image must belong to this album");
+                               if (title.isPresent() && title.get().trim().isEmpty()) {
+                                       throw new AlbumTitleMustNotBeEmpty();
+                               }
                                if (title.isPresent()) {
                                        AlbumImpl.this.title = title.get();
                                }
@@ -326,6 +320,8 @@ public class AlbumImpl implements Album {
                };
        }
 
+       public static class AlbumTitleMustNotBeEmpty extends IllegalStateException { }
+
        //
        // FINGERPRINTABLE METHODS
        //