- public List<Image> getImages() {
- return Mappers.mappedList(imageIds, new Mapper<String, Image>() {
-
- @Override
- @SuppressWarnings("synthetic-access")
- public Image map(String imageId) {
- return images.get(imageId);
- }
-
- });
- }
-
- /**
- * Adds the given image to this album.
- *
- * @param image
- * The image to add
- */
- public void addImage(Image image) {
- Validation.begin().isNotNull("Image", image).check().isNotNull("Image Owner", image.getSone()).check().isEqual("Image Owner", image.getSone(), sone).check();
- 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);
- }
- }
-
- /**
- * Removes the given image from this album.
- *
- * @param image
- * The image to remove
- */
- public void removeImage(Image image) {
- Validation.begin().isNotNull("Image", image).check().isEqual("Image Owner", image.getSone(), sone).check();
- 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
- * @return The image that the given image swapped the place with, or
- * <code>null</code> if the image did not change its place
- */
- public Image 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 null;
- }
- imageIds.remove(image.getId());
- imageIds.add(oldIndex - 1, image.getId());
- return images.get(imageIds.get(oldIndex));
- }