Override Object.hashCode() and Object.equals().
[demoscenemusic.git] / src / main / java / net / pterodactylus / demoscenemusic / data / DefaultStyle.java
1 /*
2  * DemosceneMusic - AbstractStyle.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 /**
21  * Default implementation of a style data container.
22  *
23  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
24  */
25 public class DefaultStyle extends DefaultBase implements Style {
26
27         /**
28          * Creates a new style data container.
29          *
30          * @param id
31          *            The ID of the style
32          */
33         public DefaultStyle(String id) {
34                 super(id);
35         }
36
37         //
38         // STYLE METHODS
39         //
40
41         /**
42          * {@inheritDoc}
43          */
44         @Override
45         public String getName() {
46                 return getValue("name", String.class).get();
47         }
48
49         /**
50          * {@inheritDoc}
51          */
52         @Override
53         public Style setName(String name) {
54                 getValue("name", String.class).set(name);
55                 return this;
56         }
57
58         //
59         // OBJECT METHODS
60         //
61
62         /**
63          * {@inheritDoc}
64          */
65         @Override
66         public int hashCode() {
67                 return getId().hashCode();
68         }
69
70         /**
71          * {@inheritDoc}
72          */
73         @Override
74         public boolean equals(Object object) {
75                 if (!(object instanceof Style)) {
76                         return false;
77                 }
78                 return ((Style) object).getId().equals(getId());
79         }
80
81 }