- /**
- * 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 (images.isEmpty()) {
- albumImage = image.getId();
- }
- if (!images.containsKey(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();
- images.remove(image);
- if (image.getId().equals(albumImage)) {
- if (images.isEmpty()) {
- albumImage = null;
- } else {
- albumImage = images.values().iterator().next().getId();
- }
- }
- }
-
- /**
- * Returns the album image of this album, or {@code null} if no album image
- * has been set.
- *
- * @return The image to show when this album is listed
- */
- public Image getAlbumImage() {
- if (albumImage == null) {
- return null;
- }
- return images.get(albumImage);
- }
-
- /**
- * Sets the ID of the album image.
- *
- * @param id
- * The ID of the album image
- * @return This album
- */
- public Album setAlbumImage(String id) {
- this.albumImage = id;
- return this;
- }