checkNotNull(image, "image must not be null");
checkArgument(image.getSone().isLocal(), "image must belong to a local Sone");
deleteTemporaryImage(image.getId());
- image.getAlbum().removeImage(image);
- database.removeImage(image);
+ image.remove();
touchConfiguration();
}
List<Image> getImages();
/**
- * Removes the given image from this album.
- *
- * @param image
- * The image to remove
- */
- void removeImage(Image image);
-
- /**
* Moves the given image up in this album’s images. If the image is already the
* first image, nothing happens.
*
private final List<Album> albums = new ArrayList<Album>();
/** The image IDs in order. */
- private final List<String> imageIds = new ArrayList<String>();
+ final List<String> imageIds = new ArrayList<String>();
/** The images in this album. */
- private final Map<String, Image> images = new HashMap<String, Image>();
+ final Map<String, Image> images = new HashMap<String, Image>();
/** The parent album. */
private Album parent;
}
@Override
- public void removeImage(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");
- imageIds.remove(image.getId());
- images.remove(image.getId());
- if (image.getId().equals(albumImage)) {
- if (images.isEmpty()) {
- albumImage = null;
- } else {
- albumImage = images.values().iterator().next().getId();
- }
- }
- }
-
- @Override
public Image moveImageUp(Image image) {
checkNotNull(image, "image must not be null");
checkNotNull(image.getSone(), "image must have an owner");
package net.pterodactylus.sone.data.impl;
+import static com.google.common.collect.FluentIterable.from;
+
import net.pterodactylus.sone.data.Album;
import net.pterodactylus.sone.data.Image;
import net.pterodactylus.sone.data.Sone;
return album;
}
+ @Override
+ public void remove() throws IllegalStateException {
+ synchronized (album) {
+ album.images.remove(getId());
+ album.imageIds.remove(getId());
+ if (getId().equals(album.albumImage)) {
+ album.albumImage = from(album.images.values()).transform(GET_ID).first().orNull();
+ }
+ }
+ }
+
}