Sorting contract must not be broken. Thus the only sane sorting is by id.
This commit is contained in:
parent
98ba8cda53
commit
593dd65e2e
@ -103,6 +103,19 @@ public class Coll<E> extends CollAbstract<E>
|
||||
protected Map<String, E> id2entity;
|
||||
protected Map<E, String> entity2id;
|
||||
|
||||
@Override
|
||||
public String fixId(Object oid)
|
||||
{
|
||||
if (oid == null) return null;
|
||||
|
||||
String ret = null;
|
||||
if (oid instanceof String) ret = (String) oid;
|
||||
else if (oid.getClass() == this.getEntityClass()) ret = this.entity2id.get(oid);
|
||||
if (ret == null) return null;
|
||||
|
||||
return this.isLowercasing() ? ret.toLowerCase() : ret;
|
||||
}
|
||||
|
||||
@Override public Map<String, E> getId2entity() { return Collections.unmodifiableMap(this.id2entity); }
|
||||
@Override
|
||||
public E getFixed(String id, boolean creative)
|
||||
@ -135,23 +148,6 @@ public class Coll<E> extends CollAbstract<E>
|
||||
{
|
||||
return Collections.unmodifiableCollection(this.entity2id.keySet());
|
||||
}
|
||||
@Override public List<E> getAll(Predictate<? super E> where) { return MStoreUtil.uglySQL(this.getAll(), where, null, null, null); }
|
||||
@Override public List<E> getAll(Predictate<? super E> where, Comparator<? super E> orderby) { return MStoreUtil.uglySQL(this.getAll(), where, orderby, null, null); }
|
||||
@Override public List<E> getAll(Predictate<? super E> where, Comparator<? super E> orderby, Integer limit) { return MStoreUtil.uglySQL(this.getAll(), where, orderby, limit, null); }
|
||||
@Override public List<E> getAll(Predictate<? super E> where, Comparator<? super E> orderby, Integer limit, Integer offset) { return MStoreUtil.uglySQL(this.getAll(), where, orderby, limit, offset); }
|
||||
|
||||
@Override
|
||||
public String fixId(Object oid)
|
||||
{
|
||||
if (oid == null) return null;
|
||||
|
||||
String ret = null;
|
||||
if (oid instanceof String) ret = (String) oid;
|
||||
else if (oid.getClass() == this.getEntityClass()) ret = this.entity2id.get(oid);
|
||||
if (ret == null) return null;
|
||||
|
||||
return this.isLowercasing() ? ret.toLowerCase() : ret;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// BEHAVIOR
|
||||
@ -816,7 +812,8 @@ public class Coll<E> extends CollAbstract<E>
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public Coll(String name, Class<E> entityClass, Db db, Plugin plugin, boolean creative, boolean lowercasing, Comparator<? super String> idComparator, Comparator<? super E> entityComparator)
|
||||
@SuppressWarnings("unchecked")
|
||||
public Coll(String name, Class<E> entityClass, Db db, Plugin plugin, boolean creative, boolean lowercasing)
|
||||
{
|
||||
// Setup the name and the parsed parts
|
||||
this.name = name;
|
||||
@ -842,8 +839,8 @@ public class Coll<E> extends CollAbstract<E>
|
||||
this.collDriverObject = db.createCollDriverObject(this);
|
||||
|
||||
// STORAGE
|
||||
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>();
|
||||
this.id2entity = new ConcurrentSkipListMap<String, E>(NaturalOrderComparator.get());
|
||||
this.entity2id = Entity.class.isAssignableFrom(entityClass) ? new ConcurrentSkipListMap<E, String>((Comparator<? super E>) ComparatorEntityId.get()) : new ConcurrentHashMap<E, String>();
|
||||
|
||||
// IDENTIFIED MODIFICATIONS
|
||||
this.identifiedModifications = new ConcurrentHashMap<String, Modification>();
|
||||
@ -859,11 +856,6 @@ public class Coll<E> extends CollAbstract<E>
|
||||
};
|
||||
}
|
||||
|
||||
public Coll(String name, Class<E> entityClass, Db db, Plugin plugin, boolean creative, boolean lowercasing)
|
||||
{
|
||||
this(name, entityClass, db, plugin, creative, lowercasing, null, null);
|
||||
}
|
||||
|
||||
public Coll(String name, Class<E> entityClass, Db db, Plugin plugin)
|
||||
{
|
||||
this(name, entityClass, db, plugin, false, false);
|
||||
|
@ -1,7 +1,10 @@
|
||||
package com.massivecraft.massivecore.store;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import com.massivecraft.massivecore.Predictate;
|
||||
import com.massivecraft.massivecore.xlib.gson.JsonElement;
|
||||
|
||||
|
||||
@ -21,6 +24,14 @@ public abstract class CollAbstract<E> implements CollInterface<E>
|
||||
// STORAGE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public String fixIdOrThrow(Object oid) throws IllegalArgumentException
|
||||
{
|
||||
String ret = this.fixId(oid);
|
||||
if (ret == null) throw new IllegalArgumentException(String.valueOf(oid) + " is not a valid id.");
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public E get(Object oid)
|
||||
{
|
||||
@ -45,13 +56,17 @@ public abstract class CollAbstract<E> implements CollInterface<E>
|
||||
return this.containsIdFixed(this.fixId(oid));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String fixIdOrThrow(Object oid) throws IllegalArgumentException
|
||||
{
|
||||
String ret = this.fixId(oid);
|
||||
if (ret == null) throw new IllegalArgumentException(String.valueOf(oid) + " is not a valid id.");
|
||||
return ret;
|
||||
}
|
||||
@Override public List<E> getAll(Predictate<? super E> where) { return MStoreUtil.uglySQL(this.getAll(), where, null, null, null); }
|
||||
@Override public List<E> getAll(Predictate<? super E> where, Comparator<? super E> orderby) { return MStoreUtil.uglySQL(this.getAll(), where, orderby, null, null); }
|
||||
@Override public List<E> getAll(Predictate<? super E> where, Comparator<? super E> orderby, Integer limit) { return MStoreUtil.uglySQL(this.getAll(), where, orderby, limit, null); }
|
||||
@Override public List<E> getAll(Predictate<? super E> where, Comparator<? super E> orderby, Integer limit, Integer offset) { return MStoreUtil.uglySQL(this.getAll(), where, orderby, limit, offset); }
|
||||
@Override public List<E> getAll(Predictate<? super E> where, Integer limit) { return MStoreUtil.uglySQL(this.getAll(), where, null, limit, null); }
|
||||
@Override public List<E> getAll(Predictate<? super E> where, Integer limit, Integer offset) { return MStoreUtil.uglySQL(this.getAll(), where, null, limit, offset); }
|
||||
@Override public List<E> getAll(Comparator<? super E> orderby) { return MStoreUtil.uglySQL(this.getAll(), null, orderby, null, null); }
|
||||
@Override public List<E> getAll(Comparator<? super E> orderby, Integer limit) { return MStoreUtil.uglySQL(this.getAll(), null, orderby, limit, null); }
|
||||
@Override public List<E> getAll(Comparator<? super E> orderby, Integer limit, Integer offset) { return MStoreUtil.uglySQL(this.getAll(), null, orderby, limit, offset); }
|
||||
@Override public List<E> getAll(Integer limit) { return MStoreUtil.uglySQL(this.getAll(), null, null, limit, null); }
|
||||
@Override public List<E> getAll(Integer limit, Integer offset) { return MStoreUtil.uglySQL(this.getAll(), null, null, limit, offset); }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// BEHAVIOR
|
||||
|
@ -16,6 +16,7 @@ public interface CollInterface<E>
|
||||
// -------------------------------------------- //
|
||||
// WHAT DO WE HANDLE?
|
||||
// -------------------------------------------- //
|
||||
|
||||
public String getName();
|
||||
public String getBasename();
|
||||
public String getUniverse();
|
||||
@ -24,6 +25,7 @@ public interface CollInterface<E>
|
||||
// -------------------------------------------- //
|
||||
// SUPPORTING SYSTEM
|
||||
// -------------------------------------------- //
|
||||
|
||||
public Plugin getPlugin();
|
||||
|
||||
public Db getDb();
|
||||
@ -32,6 +34,10 @@ public interface CollInterface<E>
|
||||
// -------------------------------------------- //
|
||||
// STORAGE
|
||||
// -------------------------------------------- //
|
||||
|
||||
public String fixId(Object oid);
|
||||
public String fixIdOrThrow(Object oid) throws IllegalArgumentException;
|
||||
|
||||
public Map<String, E> getId2entity();
|
||||
public E get(Object oid);
|
||||
public E get(Object oid, boolean creative);
|
||||
@ -45,14 +51,19 @@ public interface CollInterface<E>
|
||||
public Map<E, String> getEntity2id();
|
||||
public String getId(Object entity);
|
||||
public boolean containsEntity(Object entity);
|
||||
|
||||
public Collection<E> getAll();
|
||||
public List<E> getAll(Predictate<? super E> where);
|
||||
public List<E> getAll(Predictate<? super E> where, Comparator<? super E> orderby);
|
||||
public List<E> getAll(Predictate<? super E> where, Comparator<? super E> orderby, Integer limit);
|
||||
public List<E> getAll(Predictate<? super E> where, Comparator<? super E> orderby, Integer limit, Integer offset);
|
||||
|
||||
public String fixId(Object oid);
|
||||
public String fixIdOrThrow(Object oid) throws IllegalArgumentException;
|
||||
public List<E> getAll(Predictate<? super E> where, Integer limit);
|
||||
public List<E> getAll(Predictate<? super E> where, Integer limit, Integer offset);
|
||||
public List<E> getAll(Comparator<? super E> orderby);
|
||||
public List<E> getAll(Comparator<? super E> orderby, Integer limit);
|
||||
public List<E> getAll(Comparator<? super E> orderby, Integer limit, Integer offset);
|
||||
public List<E> getAll(Integer limit);
|
||||
public List<E> getAll(Integer limit, Integer offset);
|
||||
|
||||
// -------------------------------------------- //
|
||||
// BEHAVIOR
|
||||
|
@ -30,12 +30,10 @@ public class ComparatorEntityId implements Comparator<Entity<?>>
|
||||
String id2 = e2.getId();
|
||||
|
||||
int ret = NaturalOrderComparator.get().compare(id1, id2);
|
||||
if (ret != 0) return ret;
|
||||
|
||||
// Only return 0 if they are the same.
|
||||
// We avoid that with this ugly solution.
|
||||
if (ret == 0) ret = -1;
|
||||
|
||||
return ret;
|
||||
// We should only return 0 if the items actually are equal.
|
||||
return e2.hashCode() - e1.hashCode();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ package com.massivecraft.massivecore.store;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
@ -22,11 +21,6 @@ public class SenderColl<E extends SenderEntity<E>> extends Coll<E> implements Se
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public SenderColl(String name, Class<E> entityClass, Db db, Plugin plugin, boolean creative, boolean lowercasing, Comparator<? super String> idComparator, Comparator<? super E> entityComparator)
|
||||
{
|
||||
super(name, entityClass, db, plugin, creative, lowercasing, idComparator, entityComparator);
|
||||
}
|
||||
|
||||
public SenderColl(String name, Class<E> entityClass, Db db, Plugin plugin, boolean creative, boolean lowercasing)
|
||||
{
|
||||
super(name, entityClass, db, plugin, creative, lowercasing);
|
||||
|
Loading…
Reference in New Issue
Block a user