3eefc3e2601b90174d21b32954e828c2fa555447
[Sone.git] / src / main / java / net / pterodactylus / sone / data / Album.java
1 /*
2  * Sone - Album.java - Copyright © 2011–2020 David Roden
3  *
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.
8  *
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.
13  *
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/>.
16  */
17
18 package net.pterodactylus.sone.data;
19
20 import java.util.Collections;
21 import java.util.List;
22 import javax.annotation.Nonnull;
23
24 import com.google.common.base.Function;
25
26 /**
27  * Container for images that can also contain nested {@link Album}s.
28  */
29 public interface Album extends Identified, Fingerprintable {
30
31         /** Function that transforms an album into the images it contains. */
32         Function<Album, List<Image>> IMAGES = new Function<Album, List<Image>>() {
33
34                 @Override
35                 @Nonnull
36                 public List<Image> apply(Album album) {
37                         return (album != null) ? album.getImages() : Collections.<Image>emptyList();
38                 }
39         };
40
41         /**
42          * Returns the ID of this album.
43          *
44          * @return The ID of this album
45          */
46         String getId();
47
48         /**
49          * Returns the Sone this album belongs to.
50          *
51          * @return The Sone this album belongs to
52          */
53         Sone getSone();
54
55         /**
56          * Returns the nested albums.
57          *
58          * @return The nested albums
59          */
60         List<Album> getAlbums();
61
62         /**
63          * Adds an album to this album.
64          *
65          * @param album
66          *              The album to add
67          */
68         void addAlbum(Album album);
69
70         /**
71          * Removes an album from this album.
72          *
73          * @param album
74          *              The album to remove
75          */
76         void removeAlbum(Album album);
77
78         /**
79          * Moves the given album up in this album’s albums. If the album is already the
80          * first album, nothing happens.
81          *
82          * @param album
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
86          */
87         Album moveAlbumUp(Album album);
88
89         /**
90          * Moves the given album down in this album’s albums. If the album is already
91          * the last album, nothing happens.
92          *
93          * @param album
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
97          */
98         Album moveAlbumDown(Album album);
99
100         /**
101          * Returns the images in this album.
102          *
103          * @return The images in this album
104          */
105         List<Image> getImages();
106
107         /**
108          * Adds the given image to this album.
109          *
110          * @param image
111          *              The image to add
112          */
113         void addImage(Image image);
114
115         /**
116          * Removes the given image from this album.
117          *
118          * @param image
119          *              The image to remove
120          */
121         void removeImage(Image image);
122
123         /**
124          * Moves the given image up in this album’s images. If the image is already the
125          * first image, nothing happens.
126          *
127          * @param image
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
131          */
132         Image moveImageUp(Image image);
133
134         /**
135          * Moves the given image down in this album’s images. If the image is already
136          * the last image, nothing happens.
137          *
138          * @param image
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
142          */
143         Image moveImageDown(Image image);
144
145         /**
146          * Returns whether this album contains any other albums or images.
147          *
148          * @return {@code true} if this album is empty, {@code false} otherwise
149          */
150         boolean isEmpty();
151
152         /**
153          * Returns whether this album is an identitiy’s root album.
154          *
155          * @return {@code true} if this album is an identity’s root album, {@code
156          *         false} otherwise
157          */
158         boolean isRoot();
159
160         /**
161          * Returns the parent album of this album.
162          *
163          * @return The parent album of this album, or {@code null} if this album does
164          *         not have a parent
165          */
166         Album getParent();
167
168         /**
169          * Sets the parent album of this album.
170          *
171          * @param parent
172          *              The new parent album of this album
173          * @return This album
174          */
175         Album setParent(Album parent);
176
177         /**
178          * Removes the parent album of this album.
179          *
180          * @return This album
181          */
182         Album removeParent();
183
184         /**
185          * Returns the title of this album.
186          *
187          * @return The title of this album
188          */
189         String getTitle();
190
191         /**
192          * Returns the description of this album.
193          *
194          * @return The description of this album
195          */
196         String getDescription();
197
198         /**
199          * Returns a modifier for this album.
200          *
201          * @return A modifier for this album
202          * @throws IllegalStateException
203          *              if this album can not be modified
204          */
205         Modifier modify() throws IllegalStateException;
206
207         /**
208          * Allows modifying an album. Modifications are only performed once {@link
209          * #update()} has succesfully returned a new album with the modifications
210          * made.
211          */
212         interface Modifier {
213
214                 Modifier setTitle(String title);
215
216                 Modifier setDescription(String description);
217
218                 Album update() throws IllegalStateException;
219
220                 class AlbumTitleMustNotBeEmpty extends IllegalStateException { }
221
222         }
223
224 }