Override Object.hashCode() and Object.equals().
[demoscenemusic.git] / src / main / java / net / pterodactylus / demoscenemusic / data / DefaultTrack.java
1 /*
2  * DemosceneMusic - Track.java - Copyright © 2012 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.demoscenemusic.data;
19
20 import java.util.Collection;
21 import java.util.List;
22 import java.util.Map;
23
24 /**
25  * Default implementation of a track data container.
26  *
27  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
28  */
29 public class DefaultTrack extends DefaultBase implements Track {
30
31         /**
32          * Creates a new track data container.
33          *
34          * @param id
35          *            The ID of the track
36          */
37         public DefaultTrack(String id) {
38                 super(id);
39         }
40
41         //
42         // TRACK METHODS
43         //
44
45         /**
46          * {@inheritDoc}
47          */
48         @Override
49         public String getName() {
50                 return getValue("name", String.class).get();
51         }
52
53         /**
54          * {@inheritDoc}
55          */
56         @Override
57         public Track setName(String name) {
58                 getValue("name", String.class).set(name);
59                 return this;
60         }
61
62         /**
63          * {@inheritDoc}
64          */
65         @Override
66         @SuppressWarnings("unchecked")
67         public List<Artist> getArtists() {
68                 return getValue("artists", List.class).get();
69         }
70
71         /**
72          * {@inheritDoc}
73          */
74         @Override
75         public Track setArtists(List<Artist> artists) {
76                 getValue("artists", List.class).set(artists);
77                 return this;
78         }
79
80         /**
81          * {@inheritDoc}
82          */
83         @Override
84         @SuppressWarnings("unchecked")
85         public Collection<Style> getStyles() {
86                 return getValue("styles", Collection.class).get();
87         }
88
89         /**
90          * {@inheritDoc}
91          */
92         @Override
93         public Track setStyles(Collection<? extends Style> styles) {
94                 getValue("styles", Collection.class).set(styles);
95                 return this;
96         }
97
98         /**
99          * {@inheritDoc}
100          */
101         @Override
102         public String getRemix() {
103                 return getValue("remix", String.class).get();
104         }
105
106         /**
107          * {@inheritDoc}
108          */
109         @Override
110         public Track setRemix(String remix) {
111                 getValue("remix", String.class).set(remix);
112                 return this;
113         }
114
115         /**
116          * {@inheritDoc}
117          */
118         @Override
119         @SuppressWarnings("unchecked")
120         public List<Artist> getRemixArtists() {
121                 return getValue("remixArtists", List.class).get();
122         }
123
124         /**
125          * {@inheritDoc}
126          */
127         @Override
128         public Track setRemixArtists(List<Artist> remixArtists) {
129                 getValue("remixArtists", List.class).set(remixArtists);
130                 return this;
131         }
132
133         /**
134          * {@inheritDoc}
135          */
136         @Override
137         @SuppressWarnings("unchecked")
138         public Collection<TrackDerivative> getDerivatives() {
139                 return getValue("derivatives", Collection.class).get();
140         }
141
142         /**
143          * {@inheritDoc}
144          */
145         @Override
146         public Track setDerivatives(Collection<TrackDerivative> derivatives) {
147                 getValue("derivatives", Collection.class).set(derivatives);
148                 return this;
149         }
150
151         /**
152          * {@inheritDoc}
153          */
154         @Override
155         @SuppressWarnings("unchecked")
156         public Map<Relationship, Collection<Track>> getRelatedTracks() {
157                 return getValue("relatedTracks", Map.class).get();
158         }
159
160         /**
161          * {@inheritDoc}
162          */
163         @Override
164         public Track setRelatedTracks(Map<Relationship, Collection<Track>> relatedTracks) {
165                 getValue("relatedTracks", Map.class).set(relatedTracks);
166                 return this;
167         }
168
169         /**
170          * {@inheritDoc}
171          */
172         @Override
173         @SuppressWarnings("unchecked")
174         public Collection<Party> getParties() {
175                 return getValue("parties", Collection.class).get();
176         }
177
178         /**
179          * {@inheritDoc}
180          */
181         @Override
182         public Track setParties(Collection<Party> parties) {
183                 getValue("parties", Collection.class).set(parties);
184                 return this;
185         }
186
187         //
188         // OBJECT METHODS
189         //
190
191         /**
192          * {@inheritDoc}
193          */
194         @Override
195         public int hashCode() {
196                 return getId().hashCode();
197         }
198
199         /**
200          * {@inheritDoc}
201          */
202         @Override
203         public boolean equals(Object object) {
204                 if (!(object instanceof Track)) {
205                         return false;
206                 }
207                 return ((Track) object).getId().equals(getId());
208         }
209
210 }