Fix Map comparison. Entry may not implement comparable. Also typo for iterator in ComparatorCollection.

This commit is contained in:
Olof Larsson 2016-05-02 09:31:53 +02:00
parent c87afdd957
commit b407f474c8
No known key found for this signature in database
GPG Key ID: BBEF14F97DA52474
3 changed files with 55 additions and 2 deletions

View File

@ -66,7 +66,7 @@ public abstract class ComparatorAbstract<T> implements Comparator<T>
// -------------------------------------------- // // -------------------------------------------- //
private int compareSystem(T object1, T object2) private int compareSystem(T object1, T object2)
{ {
// Create // Create
int ret = 0; int ret = 0;
@ -94,6 +94,9 @@ public abstract class ComparatorAbstract<T> implements Comparator<T>
ret = ComparatorComparable.get().compare(object1, object2); ret = ComparatorComparable.get().compare(object1, object2);
if (ret != 0) return ret; if (ret != 0) return ret;
ret = ComparatorEntry.get().compare(object1, object2);
if (ret != 0) return ret;
ret = ComparatorCollection.get().compare(object1, object2); ret = ComparatorCollection.get().compare(object1, object2);
if (ret != 0) return ret; if (ret != 0) return ret;

View File

@ -50,7 +50,7 @@ public class ComparatorCollection extends ComparatorAbstract<Object>
Collections.sort(elements2, ComparatorSmart.get()); Collections.sort(elements2, ComparatorSmart.get());
Iterator<Object> iterator1 = elements1.iterator(); Iterator<Object> iterator1 = elements1.iterator();
Iterator<Object> iterator2 = elements1.iterator(); Iterator<Object> iterator2 = elements2.iterator();
while (iterator1.hasNext()) while (iterator1.hasNext())
{ {

View File

@ -0,0 +1,50 @@
package com.massivecraft.massivecore.comparator;
import java.util.Map.Entry;
public class ComparatorEntry extends ComparatorAbstract<Object>
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static ComparatorEntry i = new ComparatorEntry();
public static ComparatorEntry get() { return i; }
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@SuppressWarnings("unchecked")
@Override
public int compareInner(Object object1, Object object2)
{
// Create
int ret = 0;
// Instance Of
Entry<Object, Object> entry1 = null;
Entry<Object, Object> entry2 = null;
if (object1 instanceof Entry<?, ?>) entry1 = (Entry<Object, Object>)object1;
if (object2 instanceof Entry<?, ?>) entry2 = (Entry<Object, Object>)object2;
ret = ComparatorNull.get().compare(entry1, entry2);
if (ret != 0) return ret;
if (entry1 == null && entry2 == null) return ret;
// Keys
Object key1 = entry1.getKey();
Object key2 = entry2.getKey();
ret = ComparatorSmart.get().compare(key1, key2);
if (ret != 0) return ret;
// Values
Object value1 = entry1.getValue();
Object value2 = entry2.getValue();
ret = ComparatorSmart.get().compare(value1, value2);
if (ret != 0) return ret;
// Return
return ret;
}
}