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;
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>();
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());
}
/**
* @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");
}
}
@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 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();
@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();
}
};
}
+ public static class AlbumTitleMustNotBeEmpty extends IllegalStateException { }
+
//
// FINGERPRINTABLE METHODS
//