import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
-import static com.google.common.base.Preconditions.checkState;
import java.util.ArrayList;
import java.util.HashMap;
import net.pterodactylus.sone.data.Album;
import net.pterodactylus.sone.data.Image;
import net.pterodactylus.sone.data.Sone;
+import net.pterodactylus.sone.database.AlbumBuilder;
import net.pterodactylus.sone.database.ImageBuilder;
import com.google.common.base.Function;
private Album parent;
/** Creates a new album with a random ID. */
- public DefaultAlbum() {
- this(UUID.randomUUID().toString());
+ public DefaultAlbum(Sone sone) {
+ this(UUID.randomUUID().toString(), sone);
}
/**
* @param id
* The ID of the album
*/
- public DefaultAlbum(String id) {
+ public DefaultAlbum(String id, Sone sone) {
super(id);
+ this.sone = sone;
}
//
}
@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);
}
@Override
- public void addAlbum(Album album) {
- checkNotNull(album, "album must not be null");
- checkArgument(album.getSone().equals(sone), "album must belong to the same Sone as this album");
- album.setParent(this);
- if (!albums.contains(album)) {
- albums.add(album);
- }
- }
-
- @Override
public void removeAlbum(Album album) {
checkNotNull(album, "album must not be null");
checkArgument(album.getSone().equals(sone), "album must belong this album’s Sone");
}
@Override
+ public AlbumBuilder newAlbumBuilder() {
+ return new DefaultAlbumBuilder(sone) {
+ @Override
+ public Album build() throws IllegalStateException {
+ Album album = super.build();
+ albums.add(album);
+ return album;
+ }
+ };
+ }
+
+ @Override
public ImageBuilder newImageBuilder() throws IllegalStateException {
return new DefaultImageBuilder(sone, this) {
@Override