2 * Sone - Album.java - Copyright © 2011–2020 David Roden
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 package net.pterodactylus.sone.data;
20 import java.util.Collections;
21 import java.util.List;
22 import javax.annotation.Nonnull;
24 import com.google.common.base.Function;
27 * Container for images that can also contain nested {@link Album}s.
29 public interface Album extends Identified, Fingerprintable {
31 /** Function that transforms an album into the images it contains. */
32 Function<Album, List<Image>> IMAGES = new Function<Album, List<Image>>() {
36 public List<Image> apply(Album album) {
37 return (album != null) ? album.getImages() : Collections.<Image>emptyList();
42 * Returns the ID of this album.
44 * @return The ID of this album
49 * Returns the Sone this album belongs to.
51 * @return The Sone this album belongs to
56 * Returns the nested albums.
58 * @return The nested albums
60 List<Album> getAlbums();
63 * Adds an album to this album.
68 void addAlbum(Album album);
71 * Removes an album from this album.
76 void removeAlbum(Album album);
79 * Moves the given album up in this album’s albums. If the album is already the
80 * first album, nothing happens.
83 * The album to move up
84 * @return The album that the given album swapped the place with, or
85 * <code>null</code> if the album did not change its place
87 Album moveAlbumUp(Album album);
90 * Moves the given album down in this album’s albums. If the album is already
91 * the last album, nothing happens.
94 * The album to move down
95 * @return The album that the given album swapped the place with, or
96 * <code>null</code> if the album did not change its place
98 Album moveAlbumDown(Album album);
101 * Returns the images in this album.
103 * @return The images in this album
105 List<Image> getImages();
108 * Adds the given image to this album.
113 void addImage(Image image);
116 * Removes the given image from this album.
119 * The image to remove
121 void removeImage(Image image);
124 * Moves the given image up in this album’s images. If the image is already the
125 * first image, nothing happens.
128 * The image to move up
129 * @return The image that the given image swapped the place with, or
130 * <code>null</code> if the image did not change its place
132 Image moveImageUp(Image image);
135 * Moves the given image down in this album’s images. If the image is already
136 * the last image, nothing happens.
139 * The image to move down
140 * @return The image that the given image swapped the place with, or
141 * <code>null</code> if the image did not change its place
143 Image moveImageDown(Image image);
146 * Returns whether this album contains any other albums or images.
148 * @return {@code true} if this album is empty, {@code false} otherwise
153 * Returns whether this album is an identitiy’s root album.
155 * @return {@code true} if this album is an identity’s root album, {@code
161 * Returns the parent album of this album.
163 * @return The parent album of this album, or {@code null} if this album does
169 * Sets the parent album of this album.
172 * The new parent album of this album
175 Album setParent(Album parent);
178 * Removes the parent album of this album.
182 Album removeParent();
185 * Returns the title of this album.
187 * @return The title of this album
192 * Returns the description of this album.
194 * @return The description of this album
196 String getDescription();
199 * Returns a modifier for this album.
201 * @return A modifier for this album
202 * @throws IllegalStateException
203 * if this album can not be modified
205 Modifier modify() throws IllegalStateException;
208 * Allows modifying an album. Modifications are only performed once {@link
209 * #update()} has succesfully returned a new album with the modifications
214 Modifier setTitle(String title);
216 Modifier setDescription(String description);
218 Album update() throws IllegalStateException;
220 class AlbumTitleMustNotBeEmpty extends IllegalStateException { }