X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fdemoscenemusic%2Fdata%2FDefaultParty.java;h=3e0f296d58c97748feaeeb8285bfe32ec8f4250a;hb=c9abfe7d653c88931b01137a65188873ee586a37;hp=1b3ace4552f37ba362ac10aeb866127a133887c2;hpb=f3d8fcb4cd0be44270bfab8c58c4a07565ce6a87;p=demoscenemusic.git diff --git a/src/main/java/net/pterodactylus/demoscenemusic/data/DefaultParty.java b/src/main/java/net/pterodactylus/demoscenemusic/data/DefaultParty.java index 1b3ace4..3e0f296 100644 --- a/src/main/java/net/pterodactylus/demoscenemusic/data/DefaultParty.java +++ b/src/main/java/net/pterodactylus/demoscenemusic/data/DefaultParty.java @@ -18,6 +18,10 @@ package net.pterodactylus.demoscenemusic.data; import java.util.Collection; +import java.util.Comparator; + +import net.pterodactylus.util.number.Numbers; + /** * Default implementation of a party data container. * @@ -25,6 +29,23 @@ import java.util.Collection; */ public class DefaultParty extends DefaultBase implements Party { + /** Comparator that sorts parties by name and descending year. */ + public static final Comparator NAME_YEAR_COMPARATOR = new Comparator() { + + @Override + public int compare(Party leftParty, Party rightParty) { + int diff = leftParty.getName().compareToIgnoreCase(rightParty.getName()); + if (diff != 0) { + return diff; + } + int leftYear = Numbers.safeParseInteger(leftParty.getProperties().get("party/year"), 0); + int rightYear = Numbers.safeParseInteger(rightParty.getProperties().get("party/year"), 0); + /* show newest parties first. */ + return rightYear - leftYear; + } + + }; + /** * Creates a new party data container. * @@ -74,4 +95,27 @@ public class DefaultParty extends DefaultBase implements Party { return this; } + // + // OBJECT METHODS + // + + /** + * {@inheritDoc} + */ + @Override + public int hashCode() { + return getId().hashCode(); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean equals(Object object) { + if (!(object instanceof Party)) { + return false; + } + return ((Party) object).getId().equals(getId()); + } + }