Add parameter validation.
[Sone.git] / src / main / java / net / pterodactylus / sone / data / Album.java
1 /*
2  * Sone - Album.java - Copyright © 2011 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.ArrayList;
21 import java.util.List;
22 import java.util.UUID;
23
24 import net.pterodactylus.util.validation.Validation;
25
26 /**
27  * Container for images that can also contain nested {@link Album}s.
28  *
29  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
30  */
31 public class Album {
32
33         /** The ID of this album. */
34         private final String id;
35
36         /** The Sone this album belongs to. */
37         private final Sone sone;
38
39         /** Nested albums. */
40         private final List<Album> albums = new ArrayList<Album>();
41
42         /** The images in this album. */
43         private final List<Image> images = new ArrayList<Image>();
44
45         /** The name of this album. */
46         private String name;
47
48         /** The description of this album. */
49         private String description;
50
51         /**
52          * Creates a new album with a random ID.
53          *
54          * @param sone
55          *            The Sone this album belongs to
56          */
57         public Album(Sone sone) {
58                 this(UUID.randomUUID().toString(), sone);
59         }
60
61         /**
62          * Creates a new album with the given ID.
63          *
64          * @param id
65          *            The ID of the album
66          * @param sone
67          *            The Sone this album belongs to
68          */
69         public Album(String id, Sone sone) {
70                 Validation.begin().isNotNull("Album ID", id).isNotNull("Album Owner", sone).check();
71                 this.id = id;
72                 this.sone = sone;
73         }
74
75         //
76         // ACCESSORS
77         //
78
79         /**
80          * Returns the ID of this album.
81          *
82          * @return The ID of this album
83          */
84         public String getId() {
85                 return id;
86         }
87
88         /**
89          * Returns the Sone this album belongs to.
90          *
91          * @return The Sone this album belongs to
92          */
93         public Sone getSone() {
94                 return sone;
95         }
96
97         /**
98          * Returns the nested albums.
99          *
100          * @return The nested albums
101          */
102         public List<Album> getNestedAlbums() {
103                 return new ArrayList<Album>(albums);
104         }
105
106         /**
107          * Returns the images in this album.
108          *
109          * @return The images in this album
110          */
111         public List<Image> getImages() {
112                 return new ArrayList<Image>(images);
113         }
114
115         /**
116          * Returns the name of this album.
117          *
118          * @return The name of this album
119          */
120         public String getName() {
121                 return name;
122         }
123
124         /**
125          * Sets the name of this album.
126          *
127          * @param name
128          *            The name of this album
129          * @return This album
130          */
131         public Album setName(String name) {
132                 Validation.begin().isNotNull("Album Name", name).check();
133                 this.name = name;
134                 return this;
135         }
136
137         /**
138          * Returns the description of this album.
139          *
140          * @return The description of this album
141          */
142         public String getDescription() {
143                 return description;
144         }
145
146         /**
147          * Sets the description of this album.
148          *
149          * @param description
150          *            The description of this album
151          * @return This album
152          */
153         public Album setDescription(String description) {
154                 Validation.begin().isNotNull("Album Description", description).check();
155                 this.description = description;
156                 return this;
157         }
158
159         //
160         // OBJECT METHODS
161         //
162
163         /**
164          * {@inheritDoc}
165          */
166         @Override
167         public boolean equals(Object object) {
168                 if (!(object instanceof Album)) {
169                         return false;
170                 }
171                 Album album = (Album) object;
172                 return sone.equals(album.sone) && id.equals(album.id);
173         }
174
175 }