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 static java.util.Arrays.asList;
21 import static java.util.Collections.emptyList;
23 import java.util.ArrayList;
24 import java.util.Collections;
25 import java.util.List;
26 import javax.annotation.Nonnull;
28 import com.google.common.base.Function;
29 import com.google.common.base.Predicate;
30 import com.google.common.collect.FluentIterable;
31 import com.google.common.collect.ImmutableList;
34 * Container for images that can also contain nested {@link Album}s.
36 public interface Album extends Identified, Fingerprintable {
38 /** Function that flattens the given album and all albums beneath it. */
39 Function<Album, List<Album>> FLATTENER = new Function<Album, List<Album>>() {
43 public List<Album> apply(Album album) {
47 List<Album> albums = new ArrayList<>();
49 for (Album subAlbum : album.getAlbums()) {
50 albums.addAll(FluentIterable.from(ImmutableList.of(subAlbum)).transformAndConcat(FLATTENER).toList());
56 /** Function that transforms an album into the images it contains. */
57 Function<Album, List<Image>> IMAGES = new Function<Album, List<Image>>() {
61 public List<Image> apply(Album album) {
62 return (album != null) ? album.getImages() : Collections.<Image>emptyList();
67 * Returns the ID of this album.
69 * @return The ID of this album
74 * Returns the Sone this album belongs to.
76 * @return The Sone this album belongs to
81 * Returns the nested albums.
83 * @return The nested albums
85 List<Album> getAlbums();
88 * Adds an album to this album.
93 void addAlbum(Album album);
96 * Removes an album from this album.
101 void removeAlbum(Album album);
104 * Moves the given album up in this album’s albums. If the album is already the
105 * first album, nothing happens.
108 * The album to move up
109 * @return The album that the given album swapped the place with, or
110 * <code>null</code> if the album did not change its place
112 Album moveAlbumUp(Album album);
115 * Moves the given album down in this album’s albums. If the album is already
116 * the last album, nothing happens.
119 * The album to move down
120 * @return The album that the given album swapped the place with, or
121 * <code>null</code> if the album did not change its place
123 Album moveAlbumDown(Album album);
126 * Returns the images in this album.
128 * @return The images in this album
130 List<Image> getImages();
133 * Adds the given image to this album.
138 void addImage(Image image);
141 * Removes the given image from this album.
144 * The image to remove
146 void removeImage(Image image);
149 * Moves the given image up in this album’s images. If the image is already the
150 * first image, nothing happens.
153 * The image to move up
154 * @return The image that the given image swapped the place with, or
155 * <code>null</code> if the image did not change its place
157 Image moveImageUp(Image image);
160 * Moves the given image down in this album’s images. If the image is already
161 * the last image, nothing happens.
164 * The image to move down
165 * @return The image that the given image swapped the place with, or
166 * <code>null</code> if the image did not change its place
168 Image moveImageDown(Image image);
171 * Returns whether this album contains any other albums or images.
173 * @return {@code true} if this album is empty, {@code false} otherwise
178 * Returns whether this album is an identitiy’s root album.
180 * @return {@code true} if this album is an identity’s root album, {@code
186 * Returns the parent album of this album.
188 * @return The parent album of this album, or {@code null} if this album does
194 * Sets the parent album of this album.
197 * The new parent album of this album
200 Album setParent(Album parent);
203 * Removes the parent album of this album.
207 Album removeParent();
210 * Returns the title of this album.
212 * @return The title of this album
217 * Returns the description of this album.
219 * @return The description of this album
221 String getDescription();
224 * Returns a modifier for this album.
226 * @return A modifier for this album
227 * @throws IllegalStateException
228 * if this album can not be modified
230 Modifier modify() throws IllegalStateException;
233 * Allows modifying an album. Modifications are only performed once {@link
234 * #update()} has succesfully returned a new album with the modifications
239 Modifier setTitle(String title);
241 Modifier setDescription(String description);
243 Album update() throws IllegalStateException;
245 class AlbumTitleMustNotBeEmpty extends IllegalStateException { }