2 * Sone - Album.java - Copyright © 2011 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.ArrayList;
21 import java.util.List;
22 import java.util.UUID;
24 import net.pterodactylus.util.validation.Validation;
27 * Container for images that can also contain nested {@link Album}s.
29 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
33 /** The ID of this album. */
34 private final String id;
36 /** The Sone this album belongs to. */
37 private final Sone sone;
40 private final List<Album> albums = new ArrayList<Album>();
42 /** The images in this album. */
43 private final List<Image> images = new ArrayList<Image>();
45 /** The parent album. */
48 /** The name of this album. */
51 /** The description of this album. */
52 private String description;
55 * Creates a new album with a random ID.
58 * The Sone this album belongs to
60 public Album(Sone sone) {
61 this(UUID.randomUUID().toString(), sone);
65 * Creates a new album with the given ID.
70 * The Sone this album belongs to
72 public Album(String id, Sone sone) {
73 Validation.begin().isNotNull("Album ID", id).isNotNull("Album Owner", sone).check();
83 * Returns the ID of this album.
85 * @return The ID of this album
87 public String getId() {
92 * Returns the Sone this album belongs to.
94 * @return The Sone this album belongs to
96 public Sone getSone() {
101 * Returns the nested albums.
103 * @return The nested albums
105 public List<Album> getNestedAlbums() {
106 return new ArrayList<Album>(albums);
110 * Adds an album to this album.
115 public void addAlbum(Album album) {
116 Validation.begin().isNotNull("Album", album).check().isEqual("Album Owner", album.sone, sone).isNull("Album Parent", album.parent).check();
118 album.setParent(this);
122 * Removes an album from this album.
125 * The album to remove
127 public void removeAlbum(Album album) {
128 Validation.begin().isNotNull("Album", album).check().isEqual("Album Owner", album.sone, sone).isEqual("Album Parent", album.parent, this).check();
129 albums.remove(album);
130 album.removeParent();
134 * Returns the images in this album.
136 * @return The images in this album
138 public List<Image> getImages() {
139 return new ArrayList<Image>(images);
143 * Adds the given image to this album.
148 public void addImage(Image image) {
149 Validation.begin().isNotNull("Image", image).check().isEqual("Image Owner", image.getSone(), sone).check();
154 * Removes the given image from this album.
157 * The image to remove
159 public void removeImage(Image image) {
160 Validation.begin().isNotNull("Image", image).check().isEqual("Image Owner", image.getSone(), sone).check();
161 images.remove(image);
165 * Returns the parent album of this album.
167 * @return The parent album of this album, or {@code null} if this album
168 * does not have a parent
170 public Album getParent() {
175 * Sets the parent album of this album.
178 * The new parent album of this album
181 protected Album setParent(Album parent) {
182 Validation.begin().isNotNull("Album Parent", parent).check();
183 this.parent = parent;
188 * Removes the parent album of this album.
192 protected Album removeParent() {
193 Validation.begin().isNotNull("Album Parent", parent).check();
199 * Returns the name of this album.
201 * @return The name of this album
203 public String getName() {
208 * Sets the name of this album.
211 * The name of this album
214 public Album setName(String name) {
215 Validation.begin().isNotNull("Album Name", name).check();
221 * Returns the description of this album.
223 * @return The description of this album
225 public String getDescription() {
230 * Sets the description of this album.
233 * The description of this album
236 public Album setDescription(String description) {
237 Validation.begin().isNotNull("Album Description", description).check();
238 this.description = description;
250 public boolean equals(Object object) {
251 if (!(object instanceof Album)) {
254 Album album = (Album) object;
255 return sone.equals(album.sone) && id.equals(album.id);