Move default Sone implementation to better package.
[Sone.git] / src / main / java / net / pterodactylus / sone / data / AlbumImpl.java
index f489b0b..bb32d75 100644 (file)
@@ -47,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>();
@@ -71,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());
        }
 
        /**
@@ -81,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");
        }
 
@@ -100,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);
        }
@@ -310,6 +303,9 @@ public class AlbumImpl implements Album {
 
                        @Override
                        public Album update() throws IllegalStateException {
+                               if (title.isPresent() && title.get().trim().isEmpty()) {
+                                       throw new AlbumTitleMustNotBeEmpty();
+                               }
                                if (title.isPresent()) {
                                        AlbumImpl.this.title = title.get();
                                }
@@ -324,6 +320,8 @@ public class AlbumImpl implements Album {
                };
        }
 
+       public static class AlbumTitleMustNotBeEmpty extends IllegalStateException { }
+
        //
        // FINGERPRINTABLE METHODS
        //