Don't sort Colls when not required
This commit is contained in:
parent
dbb79ba297
commit
7b9620d38b
@ -11,12 +11,11 @@ import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentSkipListMap;
|
||||
import java.util.concurrent.ConcurrentSkipListSet;
|
||||
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import com.massivecraft.massivecore.HashCodeComparator;
|
||||
import com.massivecraft.massivecore.MassiveCore;
|
||||
import com.massivecraft.massivecore.MassivePlugin;
|
||||
import com.massivecraft.massivecore.NaturalOrderComparator;
|
||||
@ -906,21 +905,16 @@ public class Coll<E> implements CollInterface<E>
|
||||
this.collDriverObject = db.createCollDriverObject(this);
|
||||
|
||||
// STORAGE
|
||||
if (entityComparator == null && !Comparable.class.isAssignableFrom(entityClass))
|
||||
{
|
||||
// Avoid "Classname cannot be cast to java.lang.Comparable" error in ConcurrentSkipListMap
|
||||
entityComparator = HashCodeComparator.get();
|
||||
}
|
||||
this.id2entity = new ConcurrentSkipListMap<String, E>(idComparator);
|
||||
this.entity2id = new ConcurrentSkipListMap<E, String>(entityComparator);
|
||||
this.id2entity = entityComparator != null ? new ConcurrentSkipListMap<String, E>(idComparator) : new ConcurrentHashMap<String, E>();
|
||||
this.entity2id = entityComparator != null ? new ConcurrentSkipListMap<E, String>(entityComparator) : new ConcurrentHashMap<E, String>();
|
||||
|
||||
// IDENTIFIED MODIFICATIONS
|
||||
this.identifiedModifications = new ConcurrentSkipListMap<String, Modification>(idComparator);
|
||||
this.identifiedModifications = new ConcurrentHashMap<String, Modification>();
|
||||
|
||||
// SYNCLOG
|
||||
this.lastMtime = new ConcurrentSkipListMap<String, Long>(idComparator);
|
||||
this.lastRaw = new ConcurrentSkipListMap<String, JsonElement>(idComparator);
|
||||
this.lastDefault = new ConcurrentSkipListSet<String>(idComparator);
|
||||
this.lastMtime = new ConcurrentHashMap<String, Long>();
|
||||
this.lastRaw = new ConcurrentHashMap<String, JsonElement>();
|
||||
this.lastDefault = Collections.newSetFromMap(new ConcurrentHashMap<String, Boolean>());
|
||||
|
||||
final Coll<E> me = this;
|
||||
this.tickTask = new Runnable()
|
||||
|
@ -0,0 +1,41 @@
|
||||
package com.massivecraft.massivecore.store;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
import com.massivecraft.massivecore.NaturalOrderComparator;
|
||||
|
||||
public class ComparatorEntityId implements Comparator<Entity<?>>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static ComparatorEntityId i = new ComparatorEntityId();
|
||||
public static ComparatorEntityId get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public int compare(Entity<?> e1, Entity<?> e2)
|
||||
{
|
||||
if (e1 == null && e2 == null) return 0;
|
||||
if (e1 == null) return -1;
|
||||
if (e2 == null) return +1;
|
||||
|
||||
if (e1.equals(e2)) return 0;
|
||||
|
||||
String id1 = e1.getId();
|
||||
String id2 = e2.getId();
|
||||
|
||||
int ret = NaturalOrderComparator.get().compare(id1, id2);
|
||||
|
||||
// Only return 0 if they are the same.
|
||||
// We avoid that with this ugly solution.
|
||||
if (ret == 0) ret = -1;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
@ -1,7 +1,6 @@
|
||||
package com.massivecraft.massivecore.store;
|
||||
|
||||
import com.massivecraft.massivecore.MassiveCore;
|
||||
import com.massivecraft.massivecore.NaturalOrderComparator;
|
||||
import com.massivecraft.massivecore.store.accessor.Accessor;
|
||||
import com.massivecraft.massivecore.xlib.gson.Gson;
|
||||
|
||||
@ -13,7 +12,7 @@ import com.massivecraft.massivecore.xlib.gson.Gson;
|
||||
|
||||
// Self referencing generic.
|
||||
// http://www.angelikalanger.com/GenericsFAQ/FAQSections/ProgrammingIdioms.html#FAQ206
|
||||
public abstract class Entity<E extends Entity<E>> implements Comparable<E>
|
||||
public abstract class Entity<E extends Entity<E>>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// COLL & ID
|
||||
@ -157,32 +156,6 @@ public abstract class Entity<E extends Entity<E>> implements Comparable<E>
|
||||
// STANDARDS
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public int compareTo(E that)
|
||||
{
|
||||
if (that == null) throw new NullPointerException("You cannot compare with null");
|
||||
|
||||
if (this.equals(that)) return 0;
|
||||
|
||||
String thisId = this.getId();
|
||||
String thatId = that.getId();
|
||||
|
||||
if (thisId == null) return -1;
|
||||
if (thatId == null) return +1;
|
||||
|
||||
int ret = NaturalOrderComparator.get().compare(thisId, thatId);
|
||||
|
||||
// The id's may be the same if these are objects from different collections
|
||||
// We avoid zero in an ugly way like this.
|
||||
// TODO: Improve by comparing collections and then databases.
|
||||
if (ret == 0)
|
||||
{
|
||||
ret = -1;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user