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.
*
*/
public class DefaultParty extends DefaultBase implements Party {
+ /** Comparator that sorts parties by name and descending year. */
+ public static final Comparator<Party> NAME_YEAR_COMPARATOR = new Comparator<Party>() {
+
+ @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.
*