Cleanup comparators

This commit is contained in:
TheComputerGeek2 2017-04-06 19:21:23 -07:00 committed by Olof Larsson
parent 31823f5311
commit 89400cdb36
4 changed files with 22 additions and 71 deletions

View File

@ -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<Faction>
public class ComparatorFactionList extends ComparatorAbstract<Faction>
{
// -------------------------------------------- //
// FIELDS
@ -28,28 +28,19 @@ public class ComparatorFactionList implements Comparator<Faction>
}
// -------------------------------------------- //
// 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

View File

@ -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<MPlayer>, Named
public class ComparatorMPlayerInactivity extends ComparatorAbstract<MPlayer> implements Named
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
@ -15,7 +14,7 @@ public class ComparatorMPlayerInactivity implements Comparator<MPlayer>, Named
public static ComparatorMPlayerInactivity get() { return i; }
// -------------------------------------------- //
// OVERRIDE: NAMED
// OVERRIDE
// -------------------------------------------- //
@Override
@ -24,18 +23,9 @@ public class ComparatorMPlayerInactivity implements Comparator<MPlayer>, 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();

View File

@ -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<MPlayer>, Named
public class ComparatorMPlayerPower extends ComparatorAbstract<MPlayer> implements Named
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
@ -15,7 +14,7 @@ public class ComparatorMPlayerPower implements Comparator<MPlayer>, Named
public static ComparatorMPlayerPower get() { return i; }
// -------------------------------------------- //
// OVERRIDE: NAMED
// OVERRIDE
// -------------------------------------------- //
@Override
@ -24,32 +23,15 @@ public class ComparatorMPlayerPower implements Comparator<MPlayer>, 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();
}
}

View File

@ -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<MPlayer>, Named
public class ComparatorMPlayerRole extends ComparatorAbstract<MPlayer> implements Named
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
@ -16,7 +15,7 @@ public class ComparatorMPlayerRole implements Comparator<MPlayer>, Named
public static ComparatorMPlayerRole get() { return i; }
// -------------------------------------------- //
// OVERRIDE: NAMED
// OVERRIDE
// -------------------------------------------- //
@Override
@ -25,24 +24,13 @@ public class ComparatorMPlayerRole implements Comparator<MPlayer>, 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();
}
}