2 * DemosceneMusic - AbstractParty.java - Copyright © 2012 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.demoscenemusic.data;
20 import java.util.Collection;
21 import java.util.Comparator;
23 import net.pterodactylus.util.number.Numbers;
26 * Default implementation of a party data container.
28 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
30 public class DefaultParty extends DefaultBase implements Party {
32 /** Comparator that sorts parties by name and descending year. */
33 public static final Comparator<Party> NAME_YEAR_COMPARATOR = new Comparator<Party>() {
36 public int compare(Party leftParty, Party rightParty) {
37 int diff = leftParty.getName().compareToIgnoreCase(rightParty.getName());
41 int leftYear = Numbers.safeParseInteger(leftParty.getProperties().get("party/year"), 0);
42 int rightYear = Numbers.safeParseInteger(rightParty.getProperties().get("party/year"), 0);
43 /* show newest parties first. */
44 return rightYear - leftYear;
50 * Creates a new party data container.
55 public DefaultParty(String id) {
67 public String getName() {
68 return getValue("name", String.class).get();
75 public DefaultParty setName(String name) {
76 getValue("name", String.class).set(name);
84 @SuppressWarnings("unchecked")
85 public Collection<Track> getReleases() {
86 return getValue("releases", Collection.class).get();
93 public Party setReleases(Collection<Track> tracks) {
94 getValue("releases", Collection.class).set(tracks);
106 public int hashCode() {
107 return getId().hashCode();
114 public boolean equals(Object object) {
115 if (!(object instanceof Party)) {
118 return ((Party) object).getId().equals(getId());