import java.util.Map;
import java.util.UUID;
+import net.pterodactylus.sone.data.impl.ImageBuilderImpl;
+import net.pterodactylus.sone.database.ImageBuilder;
+
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;
}
@Override
- public void addImage(Image image) {
- checkNotNull(image, "image must not be null");
- checkNotNull(image.getSone(), "image must have an owner");
- checkArgument(image.getSone().equals(sone), "image must belong to the same Sone as this album");
- if (image.getAlbum() != null) {
- image.getAlbum().removeImage(image);
- }
- image.setAlbum(this);
- if (imageIds.isEmpty() && (albumImage == null)) {
- albumImage = image.getId();
- }
- if (!imageIds.contains(image.getId())) {
- imageIds.add(image.getId());
- images.put(image.getId(), image);
- }
- }
-
- @Override
public void removeImage(Image image) {
checkNotNull(image, "image must not be null");
checkNotNull(image.getSone(), "image must have an owner");
}
@Override
+ public ImageBuilder newImageBuilder() throws IllegalStateException {
+ return new ImageBuilderImpl() {
+ @Override
+ public Image build() throws IllegalStateException {
+ Image image = super.build();
+ if (images.isEmpty() && (albumImage == null)) {
+ albumImage = image.getId();
+ }
+ images.put(image.getId(), image);
+ imageIds.add(image.getId());
+ return image;
+ }
+ };
+ }
+
+ @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() || images.containsKey(albumImage.get()), "album image must belong to this album");
if (title.isPresent()) {
AlbumImpl.this.title = title.get();
}