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.Map.Entry;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.ConcurrentSkipListMap;
|
import java.util.concurrent.ConcurrentSkipListMap;
|
||||||
import java.util.concurrent.ConcurrentSkipListSet;
|
|
||||||
|
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
import com.massivecraft.massivecore.HashCodeComparator;
|
|
||||||
import com.massivecraft.massivecore.MassiveCore;
|
import com.massivecraft.massivecore.MassiveCore;
|
||||||
import com.massivecraft.massivecore.MassivePlugin;
|
import com.massivecraft.massivecore.MassivePlugin;
|
||||||
import com.massivecraft.massivecore.NaturalOrderComparator;
|
import com.massivecraft.massivecore.NaturalOrderComparator;
|
||||||
@ -906,21 +905,16 @@ public class Coll<E> implements CollInterface<E>
|
|||||||
this.collDriverObject = db.createCollDriverObject(this);
|
this.collDriverObject = db.createCollDriverObject(this);
|
||||||
|
|
||||||
// STORAGE
|
// STORAGE
|
||||||
if (entityComparator == null && !Comparable.class.isAssignableFrom(entityClass))
|
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>();
|
||||||
// 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);
|
|
||||||
|
|
||||||
// IDENTIFIED MODIFICATIONS
|
// IDENTIFIED MODIFICATIONS
|
||||||
this.identifiedModifications = new ConcurrentSkipListMap<String, Modification>(idComparator);
|
this.identifiedModifications = new ConcurrentHashMap<String, Modification>();
|
||||||
|
|
||||||
// SYNCLOG
|
// SYNCLOG
|
||||||
this.lastMtime = new ConcurrentSkipListMap<String, Long>(idComparator);
|
this.lastMtime = new ConcurrentHashMap<String, Long>();
|
||||||
this.lastRaw = new ConcurrentSkipListMap<String, JsonElement>(idComparator);
|
this.lastRaw = new ConcurrentHashMap<String, JsonElement>();
|
||||||
this.lastDefault = new ConcurrentSkipListSet<String>(idComparator);
|
this.lastDefault = Collections.newSetFromMap(new ConcurrentHashMap<String, Boolean>());
|
||||||
|
|
||||||
final Coll<E> me = this;
|
final Coll<E> me = this;
|
||||||
this.tickTask = new Runnable()
|
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;
|
package com.massivecraft.massivecore.store;
|
||||||
|
|
||||||
import com.massivecraft.massivecore.MassiveCore;
|
import com.massivecraft.massivecore.MassiveCore;
|
||||||
import com.massivecraft.massivecore.NaturalOrderComparator;
|
|
||||||
import com.massivecraft.massivecore.store.accessor.Accessor;
|
import com.massivecraft.massivecore.store.accessor.Accessor;
|
||||||
import com.massivecraft.massivecore.xlib.gson.Gson;
|
import com.massivecraft.massivecore.xlib.gson.Gson;
|
||||||
|
|
||||||
@ -13,7 +12,7 @@ import com.massivecraft.massivecore.xlib.gson.Gson;
|
|||||||
|
|
||||||
// Self referencing generic.
|
// Self referencing generic.
|
||||||
// http://www.angelikalanger.com/GenericsFAQ/FAQSections/ProgrammingIdioms.html#FAQ206
|
// 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
|
// COLL & ID
|
||||||
@ -156,33 +155,7 @@ public abstract class Entity<E extends Entity<E>> implements Comparable<E>
|
|||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// STANDARDS
|
// 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
|
@Override
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user