+ 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();
+ }
+ }
+ }
+
+ /**
+ * Moves the given image up in this album’s images. If the image is already
+ * the first image, nothing happens.
+ *
+ * @param image
+ * The image to move up
+ */
+ public void moveImageUp(Image image) {
+ Validation.begin().isNotNull("Image", image).check().isEqual("Image Album", image.getAlbum(), this).isEqual("Album Owner", image.getAlbum().getSone(), sone).check();
+ int oldIndex = imageIds.indexOf(image.getId());
+ if (oldIndex <= 0) {
+ return;
+ }
+ imageIds.remove(image.getId());
+ imageIds.add(oldIndex - 1, image.getId());
+ }
+
+ /**
+ * Move the given image down in this album’s images. If the image is already
+ * the last image, nothing happens.
+ *
+ * @param image
+ * The image to move down
+ */
+ public void moveImageDown(Image image) {
+ Validation.begin().isNotNull("Image", image).check().isEqual("Image Album", image.getAlbum(), this).isEqual("Album Owner", image.getAlbum().getSone(), sone).check();
+ int oldIndex = imageIds.indexOf(image.getId());
+ if ((oldIndex == -1) || (oldIndex >= (imageIds.size() - 1))) {
+ return;
+ }
+ imageIds.remove(image.getId());
+ imageIds.add(oldIndex + 1, image.getId());