Moving lowercasing logic to Coll and alter constructors to get rid of uuid as default and troll myself.

This commit is contained in:
Olof Larsson 2013-04-16 09:23:55 +02:00
parent 135e2ce27b
commit 8e633ceb2b
6 changed files with 64 additions and 45 deletions

View File

@ -14,7 +14,7 @@ public class MCoreConfColl extends Coll<MCoreConf>
public static MCoreConfColl get() { return i; }
private MCoreConfColl()
{
super(MStore.getDb(ConfServer.dburi), MCore.get(), "uuid", "mcore_conf", MCoreConf.class, true);
super("mcore_conf", MCoreConf.class, MStore.getDb(ConfServer.dburi), MCore.get(), true, false);
}
// -------------------------------------------- //

View File

@ -130,18 +130,35 @@ public class Coll<E> implements CollInterface<E>
public String fixId(Object oid)
{
if (oid == null) return null;
if (oid instanceof String) return (String)oid;
if (oid.getClass() == this.entityClass) return this.entity2id.get(oid);
return null;
String ret = null;
if (oid instanceof String)
{
ret = (String)oid;
}
else if (oid.getClass() == this.entityClass)
{
ret = this.entity2id.get(oid);
}
if (ret == null) return null;
return this.isLowercasing() ? ret.toLowerCase() : ret;
}
// -------------------------------------------- //
// BAHAVIOR
// BEHAVIOR
// -------------------------------------------- //
protected boolean creative;
@Override public boolean isCreative() { return this.creative; }
@Override public void setCreative(boolean val) { this.creative = val; }
@Override public void setCreative(boolean creative) { this.creative = creative; }
// "Lowercasing" means that the ids are always converted to lower case when fixed.
// This is highly recommended for sender colls.
// The senderIds are case insensitive by nature and some times you simply can't know the correct casing.
protected boolean lowercasing;
@Override public boolean isLowercasing() { return this.lowercasing; }
@Override public void setLowercasing(boolean lowercasing) { this.lowercasing = lowercasing; }
// Should that instance be saved or not?
// If it is default it should not be saved.
@ -589,7 +606,7 @@ public class Coll<E> implements CollInterface<E>
// CONSTRUCT
// -------------------------------------------- //
public Coll(Db<?> db, Plugin plugin, String idStrategyName, String name, Class<E> entityClass, boolean creative, Comparator<? super String> idComparator, Comparator<? super E> entityComparator)
public Coll(String name, Class<E> entityClass, Db<?> db, Plugin plugin, boolean creative, boolean lowercasing, String idStrategyName, Comparator<? super String> idComparator, Comparator<? super E> entityComparator)
{
// Setup the name and the parsed parts
this.name = name;
@ -607,6 +624,7 @@ public class Coll<E> implements CollInterface<E>
// WHAT DO WE HANDLE?
this.entityClass = entityClass;
this.creative = creative;
this.lowercasing = lowercasing;
// SUPPORTING SYSTEM
this.plugin = plugin;
@ -645,14 +663,14 @@ public class Coll<E> implements CollInterface<E>
};
}
public Coll(Db<?> db, Plugin plugin, String idStrategyName, String name, Class<E> entityClass, boolean creative)
public Coll(String name, Class<E> entityClass, Db<?> db, Plugin plugin, boolean creative, boolean lowercasing)
{
this(db, plugin, idStrategyName, name, entityClass, creative, null, null);
this(name, entityClass, db, plugin, creative, lowercasing, "uuid", null, null);
}
public Coll(Plugin plugin, String idStrategyName, String name, Class<E> entityClass, boolean creative)
public Coll(String name, Class<E> entityClass, Db<?> db, Plugin plugin)
{
this(MCore.getDb(), plugin, idStrategyName, name, entityClass, creative);
this(name, entityClass, db, plugin, false, false);
}
@Override

View File

@ -53,11 +53,15 @@ public interface CollInterface<E>
public String fixId(Object oid);
// -------------------------------------------- //
// BAHAVIOR
// BEHAVIOR
// -------------------------------------------- //
public boolean isCreative();
public void setCreative(boolean val);
public boolean isLowercasing();
public void setLowercasing(boolean val);
// A default entity will not be saved.
// This is often used together with creative collections to save disc space.
public boolean isDefault(E entity);

View File

@ -14,24 +14,10 @@ import com.massivecraft.mcore.util.MUtil;
public class SenderColl<E extends SenderEntity<E>> extends Coll<E> implements SenderIdSource
{
// -------------------------------------------- //
// CONSTANTS
// -------------------------------------------- //
public final static boolean DEFAULT_LOWERCASING = true;
public final static boolean DEFAULT_CREATIVE = true;
// -------------------------------------------- //
// FIELDS
// -------------------------------------------- //
// "Lowercasing" means that the ids are always converted to lower case when fixed.
// This is highly recommended for sender colls.
// The senderIds are case insensitive by nature and some times you simply can't know the correct casing.
protected boolean lowercasing;
public boolean isLowercasing() { return this.lowercasing; }
protected final SenderIdSource mixinedIdSource = new SenderIdSourceCombined(this, SenderIdSourceMixinAllSenderIds.get());
public SenderIdSource getMixinedIdSource() { return this.mixinedIdSource; }
@ -39,25 +25,19 @@ public class SenderColl<E extends SenderEntity<E>> extends Coll<E> implements Se
// CONSTRUCT
// -------------------------------------------- //
public SenderColl(Db<?> db, Plugin plugin, String name, Class<E> entityClass, boolean creative, boolean lowercasing, Comparator<? super String> idComparator, Comparator<? super E> entityComparator)
public SenderColl(String name, Class<E> entityClass, Db<?> db, Plugin plugin, boolean creative, boolean lowercasing, String idStrategyName, Comparator<? super String> idComparator, Comparator<? super E> entityComparator)
{
super(db, plugin, "uuid", name, entityClass, creative, idComparator, entityComparator);
this.lowercasing = lowercasing;
super(name, entityClass, db, plugin, creative, lowercasing, idStrategyName, idComparator, entityComparator);
}
public SenderColl(Db<?> db, Plugin plugin, String name, Class<E> entityClass, boolean creative, boolean lowercasing)
{
this(db, plugin, name, entityClass, creative, lowercasing, null, null);
public SenderColl(String name, Class<E> entityClass, Db<?> db, Plugin plugin, boolean creative, boolean lowercasing)
{
super(name, entityClass, db, plugin, creative, lowercasing);
}
public SenderColl(Db<?> db, Plugin plugin, String name, Class<E> entityClass, boolean creative)
{
this(db, plugin, name, entityClass, creative, DEFAULT_LOWERCASING);
}
public SenderColl(Db<?> db, Plugin plugin, String name, Class<E> entityClass)
{
this(db, plugin, name, entityClass, DEFAULT_CREATIVE);
public SenderColl(String name, Class<E> entityClass, Db<?> db, Plugin plugin)
{
super(name, entityClass, db, plugin, true, true);
}
// -------------------------------------------- //
@ -87,9 +67,24 @@ public class SenderColl<E extends SenderEntity<E>> extends Coll<E> implements Se
public String fixId(Object oid)
{
if (oid == null) return null;
String ret = MUtil.extract(String.class, "senderId", oid);
if (ret == null) return ret;
return this.lowercasing ? ret.toLowerCase() : ret;
String ret = null;
if (oid instanceof String)
{
ret = (String)oid;
}
else if (oid.getClass() == this.entityClass)
{
ret = this.entity2id.get(oid);
}
else
{
ret = MUtil.extract(String.class, "senderId", oid);
}
if (ret == null) return null;
return this.isLowercasing() ? ret.toLowerCase() : ret;
}
public Collection<E> getAllOnline()

View File

@ -5,6 +5,7 @@ import java.util.List;
import com.massivecraft.mcore.MCore;
import com.massivecraft.mcore.store.Coll;
import com.massivecraft.mcore.store.MStore;
public class AspectColl extends Coll<Aspect>
{
@ -16,7 +17,7 @@ public class AspectColl extends Coll<Aspect>
public static AspectColl get() { return i; }
private AspectColl()
{
super(MCore.get(), "uuid", "mcore_aspect", Aspect.class, false);
super("mcore_aspect", Aspect.class, MStore.getDb("default"), MCore.get());
}
// -------------------------------------------- //

View File

@ -2,6 +2,7 @@ package com.massivecraft.mcore.usys;
import com.massivecraft.mcore.MCore;
import com.massivecraft.mcore.store.Coll;
import com.massivecraft.mcore.store.MStore;
public class MultiverseColl extends Coll<Multiverse>
{
@ -13,7 +14,7 @@ public class MultiverseColl extends Coll<Multiverse>
public static MultiverseColl get() { return i; }
private MultiverseColl()
{
super(MCore.get(), "uuid", "mcore_multiverse", Multiverse.class, false);
super("mcore_multiverse", Multiverse.class, MStore.getDb("default"), MCore.get());
}
// -------------------------------------------- //