From 89400cdb363b742e52a6745757793586f12dc459 Mon Sep 17 00:00:00 2001 From: TheComputerGeek2 Date: Thu, 6 Apr 2017 19:21:23 -0700 Subject: [PATCH] Cleanup comparators --- .../comparator/ComparatorFactionList.java | 25 +++++----------- .../ComparatorMPlayerInactivity.java | 18 +++-------- .../comparator/ComparatorMPlayerPower.java | 30 ++++--------------- .../comparator/ComparatorMPlayerRole.java | 20 +++---------- 4 files changed, 22 insertions(+), 71 deletions(-) diff --git a/src/com/massivecraft/factions/comparator/ComparatorFactionList.java b/src/com/massivecraft/factions/comparator/ComparatorFactionList.java index e2274525..74de992f 100644 --- a/src/com/massivecraft/factions/comparator/ComparatorFactionList.java +++ b/src/com/massivecraft/factions/comparator/ComparatorFactionList.java @@ -1,14 +1,14 @@ package com.massivecraft.factions.comparator; import com.massivecraft.factions.entity.Faction; +import com.massivecraft.massivecore.comparator.ComparatorAbstract; import com.massivecraft.massivecore.comparator.ComparatorComparable; import com.massivecraft.massivecore.util.IdUtil; import org.bukkit.command.CommandSender; import java.lang.ref.WeakReference; -import java.util.Comparator; -public class ComparatorFactionList implements Comparator +public class ComparatorFactionList extends ComparatorAbstract { // -------------------------------------------- // // FIELDS @@ -28,28 +28,19 @@ public class ComparatorFactionList implements Comparator } // -------------------------------------------- // - // OVERRIDE: COMPARATOR + // OVERRIDE // -------------------------------------------- // @Override - public int compare(Faction f1, Faction f2) + public int compareInner(Faction f1, Faction f2) { - int ret = 0; - - // Null - if (f1 == null && f2 == null) ret = 0; - if (f1 == null) ret = -1; - if (f2 == null) ret = +1; - if (ret != 0) return ret; - // None a.k.a. Wilderness - if (f1.isNone() && f2.isNone()) ret = 0; - if (f1.isNone()) ret = -1; - if (f2.isNone()) ret = +1; - if (ret != 0) return ret; + if (f1.isNone() && f2.isNone()) return 0; + if (f1.isNone()) return -1; + if (f2.isNone()) return 1; // Players Online - ret = f2.getMPlayersWhereOnlineTo(this.getWatcher()).size() - f1.getMPlayersWhereOnlineTo(this.getWatcher()).size(); + int ret = f2.getMPlayersWhereOnlineTo(this.getWatcher()).size() - f1.getMPlayersWhereOnlineTo(this.getWatcher()).size(); if (ret != 0) return ret; // Players Total diff --git a/src/com/massivecraft/factions/comparator/ComparatorMPlayerInactivity.java b/src/com/massivecraft/factions/comparator/ComparatorMPlayerInactivity.java index 94c4845c..967874ca 100644 --- a/src/com/massivecraft/factions/comparator/ComparatorMPlayerInactivity.java +++ b/src/com/massivecraft/factions/comparator/ComparatorMPlayerInactivity.java @@ -2,10 +2,9 @@ package com.massivecraft.factions.comparator; import com.massivecraft.factions.entity.MPlayer; import com.massivecraft.massivecore.Named; +import com.massivecraft.massivecore.comparator.ComparatorAbstract; -import java.util.Comparator; - -public class ComparatorMPlayerInactivity implements Comparator, Named +public class ComparatorMPlayerInactivity extends ComparatorAbstract implements Named { // -------------------------------------------- // // INSTANCE & CONSTRUCT @@ -15,7 +14,7 @@ public class ComparatorMPlayerInactivity implements Comparator, Named public static ComparatorMPlayerInactivity get() { return i; } // -------------------------------------------- // - // OVERRIDE: NAMED + // OVERRIDE // -------------------------------------------- // @Override @@ -24,18 +23,9 @@ public class ComparatorMPlayerInactivity implements Comparator, Named return "Time"; } - // -------------------------------------------- // - // OVERRIDE: COMPARATOR - // -------------------------------------------- // - @Override - public int compare(MPlayer m1, MPlayer m2) + public int compareInner(MPlayer m1, MPlayer m2) { - // Null - if (m1 == null && m2 == null) return 0; - else if (m1 == null) return -1; - else if (m2 == null) return +1; - // Online boolean o1 = m1.isOnline(); boolean o2 = m2.isOnline(); diff --git a/src/com/massivecraft/factions/comparator/ComparatorMPlayerPower.java b/src/com/massivecraft/factions/comparator/ComparatorMPlayerPower.java index 978d2d37..5fd01fdc 100644 --- a/src/com/massivecraft/factions/comparator/ComparatorMPlayerPower.java +++ b/src/com/massivecraft/factions/comparator/ComparatorMPlayerPower.java @@ -2,10 +2,9 @@ package com.massivecraft.factions.comparator; import com.massivecraft.factions.entity.MPlayer; import com.massivecraft.massivecore.Named; +import com.massivecraft.massivecore.comparator.ComparatorAbstract; -import java.util.Comparator; - -public class ComparatorMPlayerPower implements Comparator, Named +public class ComparatorMPlayerPower extends ComparatorAbstract implements Named { // -------------------------------------------- // // INSTANCE & CONSTRUCT @@ -15,7 +14,7 @@ public class ComparatorMPlayerPower implements Comparator, Named public static ComparatorMPlayerPower get() { return i; } // -------------------------------------------- // - // OVERRIDE: NAMED + // OVERRIDE // -------------------------------------------- // @Override @@ -24,32 +23,15 @@ public class ComparatorMPlayerPower implements Comparator, Named return "Power"; } - // -------------------------------------------- // - // OVERRIDE: COMPARATOR - // -------------------------------------------- // - @Override - public int compare(MPlayer m1, MPlayer m2) + public int compareInner(MPlayer m1, MPlayer m2) { - int ret = 0; - - // Null - if (m1 == null && m2 == null) return 0; - else if (m1 == null) return -1; - else if (m2 == null) return +1; - // Power - int p1 = m1.getPowerRounded(); - int p2 = m2.getPowerRounded(); - ret = p1 - p2; + int ret = m1.getPowerRounded() - m2.getPowerRounded(); if (ret != 0) return ret; // MaxPower - int max1 = m1.getPowerMaxRounded(); - int max2 = m2.getPowerMaxRounded(); - ret = max1 - max2; - - return ret; + return m1.getPowerMaxRounded() - m2.getPowerMaxRounded(); } } diff --git a/src/com/massivecraft/factions/comparator/ComparatorMPlayerRole.java b/src/com/massivecraft/factions/comparator/ComparatorMPlayerRole.java index 874f32f2..dc15e998 100644 --- a/src/com/massivecraft/factions/comparator/ComparatorMPlayerRole.java +++ b/src/com/massivecraft/factions/comparator/ComparatorMPlayerRole.java @@ -3,10 +3,9 @@ package com.massivecraft.factions.comparator; import com.massivecraft.factions.Rel; import com.massivecraft.factions.entity.MPlayer; import com.massivecraft.massivecore.Named; +import com.massivecraft.massivecore.comparator.ComparatorAbstract; -import java.util.Comparator; - -public class ComparatorMPlayerRole implements Comparator, Named +public class ComparatorMPlayerRole extends ComparatorAbstract implements Named { // -------------------------------------------- // // INSTANCE & CONSTRUCT @@ -16,7 +15,7 @@ public class ComparatorMPlayerRole implements Comparator, Named public static ComparatorMPlayerRole get() { return i; } // -------------------------------------------- // - // OVERRIDE: NAMED + // OVERRIDE // -------------------------------------------- // @Override @@ -25,24 +24,13 @@ public class ComparatorMPlayerRole implements Comparator, Named return "Rank"; } - // -------------------------------------------- // - // OVERRIDE: COMPARATOR - // -------------------------------------------- // - @Override - public int compare(MPlayer m1, MPlayer m2) + public int compareInner(MPlayer m1, MPlayer m2) { - // Null - if (m1 == null && m2 == null) return 0; - else if (m1 == null) return -1; - else if (m2 == null) return +1; - // Rank Rel r1 = m1.getRole(); Rel r2 = m2.getRole(); return r2.getValue() - r1.getValue(); } - - }