java conventions and lombok

This commit is contained in:
Olof Larsson 2012-10-01 16:32:18 +02:00
parent 6fbc4b9a7a
commit 38aad961cc
40 changed files with 295 additions and 294 deletions

View File

@ -75,7 +75,7 @@ public abstract class MPlugin extends JavaPlugin implements Listener
// Collection shutdowns for new system.
for (Coll<?, ?> coll : Coll.instances)
{
if (coll.mplugin() != this) continue;
if (coll.getMplugin() != this) continue;
coll.examineThread().interrupt();
coll.syncAll(); // TODO: Save outwards only? We may want to avoid loads at this stage...
Coll.instances.remove(coll);

View File

@ -14,10 +14,8 @@ import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
import com.massivecraft.mcore4.store.accessor.Accessor;
import com.massivecraft.mcore4.util.Txt;
import com.massivecraft.mcore4.xlib.gson.annotations.SerializedName;
@ -46,7 +44,7 @@ public class PS implements Cloneable
// Field: worldName
@SerializedName("w")
@Getter @Setter protected String worldName;
@Getter @Setter protected String worldName = null;
// FakeField: world
public World getWorld()
@ -54,17 +52,16 @@ public class PS implements Cloneable
if (this.worldName == null) return null;
return Bukkit.getWorld(this.worldName);
}
public PS setWorld(World val)
public void setWorld(World val)
{
this.worldName = val.getName();
return this;
}
// ---------------------
// Field: blockX
@SerializedName("bx")
@Getter @Setter protected Integer blockX;
@Getter @Setter protected Integer blockX = null;
public Integer calcBlockX()
{
return calcBlock(this.locationX, this.blockX, this.chunkX);
@ -72,7 +69,7 @@ public class PS implements Cloneable
// Field: blockY
@SerializedName("by")
@Getter @Setter protected Integer blockY;
@Getter @Setter protected Integer blockY = null;
public Integer calcBlockY()
{
return calcBlock(this.locationY, this.blockY, null);
@ -80,7 +77,7 @@ public class PS implements Cloneable
// Field: blockZ
@SerializedName("bz")
@Getter @Setter protected Integer blockZ;
@Getter @Setter protected Integer blockZ = null;
public Integer calcBlockZ()
{
return calcBlock(this.locationZ, this.blockZ, this.chunkZ);
@ -98,7 +95,7 @@ public class PS implements Cloneable
// Field: locationX
@SerializedName("lx")
@Getter @Setter protected Double locationX;
@Getter @Setter protected Double locationX = null;
public Double calcLocationX()
{
return calcLocation(this.locationX, this.blockX, this.chunkX);
@ -106,7 +103,7 @@ public class PS implements Cloneable
// Field: locationY
@SerializedName("ly")
@Getter @Setter protected Double locationY;
@Getter @Setter protected Double locationY = null;
public Double calcLocationY()
{
return calcLocation(this.locationY, this.blockY, null);
@ -114,7 +111,7 @@ public class PS implements Cloneable
// Field: locationZ
@SerializedName("lz")
@Getter @Setter protected Double locationZ;
@Getter @Setter protected Double locationZ = null;
public Double calclocationZ()
{
return calcLocation(this.locationZ, this.blockZ, this.chunkZ);
@ -132,7 +129,7 @@ public class PS implements Cloneable
// Field: chunkX
@SerializedName("cx")
@Getter @Setter protected Integer chunkX;
@Getter @Setter protected Integer chunkX = null;
public Integer calcChunkX()
{
return calcChunk(this.locationX, this.blockX, this.chunkX);
@ -140,7 +137,7 @@ public class PS implements Cloneable
// Field: chunkZ
@SerializedName("xz")
@Getter @Setter protected Integer chunkZ;
@Getter @Setter protected Integer chunkZ = null;
public Integer calcChunkZ()
{
return calcChunk(this.locationZ, this.blockZ, this.chunkZ);
@ -158,8 +155,8 @@ public class PS implements Cloneable
// Field: pitch
@SerializedName("p")
@Getter protected Float pitch;
public PS setPitch(Float val)
@Getter protected Float pitch = null;
public void setPitch(Float val)
{
if (val == null)
{
@ -169,18 +166,17 @@ public class PS implements Cloneable
{
this.pitch = (val + 360F) % 360F;
}
return this;
}
// Field: yaw
@SerializedName("y")
@Getter @Setter protected Float yaw;
@Getter @Setter protected Float yaw = null;
// ---------------------
// Field: velocityX
@SerializedName("vx")
@Getter @Setter protected Double velocityX;
@Getter @Setter protected Double velocityX = null;
public Double calcVelocityX()
{
return calcVelocity(this.locationX, this.blockX, this.chunkX, this.velocityX);
@ -188,7 +184,7 @@ public class PS implements Cloneable
// Field: velocityY
@SerializedName("vy")
@Getter @Setter protected Double velocityY;
@Getter @Setter protected Double velocityY = null;
public Double calcVelocityY()
{
return calcVelocity(this.locationY, this.blockY, 0, this.velocityY);
@ -196,7 +192,7 @@ public class PS implements Cloneable
// Field: velocityZ
@SerializedName("vz")
@Getter @Setter protected Double velocityZ;
@Getter @Setter protected Double velocityZ = null;
public Double calcVelocityZ()
{
return calcVelocity(this.locationZ, this.blockZ, this.chunkZ, this.velocityZ);
@ -212,7 +208,7 @@ public class PS implements Cloneable
}
//----------------------------------------------//
// CONVERTERS
// GET / CALC
//----------------------------------------------//
public synchronized Location getLocation()
@ -248,7 +244,7 @@ public class PS implements Cloneable
{
return this.innerBlock(this.calcBlockX(), this.calcBlockY(), this.calcBlockZ());
}
public synchronized Block innerBlock(Integer x, Integer y, Integer z)
protected synchronized Block innerBlock(Integer x, Integer y, Integer z)
{
World world = this.getWorld();
if (world == null) return null;
@ -268,7 +264,7 @@ public class PS implements Cloneable
{
return this.innerChunk(this.calcChunkX(), this.calcChunkZ());
}
public synchronized Chunk innerChunk(Integer x, Integer z)
protected synchronized Chunk innerChunk(Integer x, Integer z)
{
World world = this.getWorld();
if (world == null) return null;
@ -287,7 +283,7 @@ public class PS implements Cloneable
{
return this.innerVelocity(this.calcVelocityX(), this.calcVelocityY(), this.calcVelocityZ());
}
public synchronized Vector innerVelocity(Double x, Double y, Double z)
protected synchronized Vector innerVelocity(Double x, Double y, Double z)
{
if (x == null) return null;
if (y == null) return null;
@ -296,10 +292,10 @@ public class PS implements Cloneable
}
//----------------------------------------------//
// READERS
// SET
//----------------------------------------------//
public synchronized PS readDefault()
public synchronized void setDefault()
{
this.worldName = null;
@ -320,30 +316,63 @@ public class PS implements Cloneable
this.velocityX = null;
this.velocityY = null;
this.velocityZ = null;
}
public synchronized void setPSTransparent(PS ps)
{
if (ps.worldName != null) this.worldName = ps.worldName;
return this;
if (ps.blockX != null) this.blockX = ps.blockX;
if (ps.blockY != null) this.blockY = ps.blockY;
if (ps.blockZ != null) this.blockZ = ps.blockZ;
if (ps.locationX != null) this.locationX = ps.locationX;
if (ps.locationY != null) this.locationY = ps.locationY;
if (ps.locationZ != null) this.locationZ = ps.locationZ;
if (ps.chunkX != null) this.chunkX = ps.chunkX;
if (ps.chunkZ != null) this.chunkZ = ps.chunkZ;
if (ps.pitch != null) this.pitch = ps.pitch;
if (ps.yaw != null) this.yaw = ps.yaw;
if (ps.velocityX != null) this.velocityX = ps.velocityX;
if (ps.velocityY != null) this.velocityY = ps.velocityY;
if (ps.velocityZ != null) this.velocityZ = ps.velocityZ;
}
public synchronized PS readTransparent(PS ps)
public synchronized void setPS(PS ps)
{
Accessor.get(PS.class).copy(ps, this, true);
return this;
}
public synchronized PS read(PS ps)
{
Accessor.get(PS.class).copy(ps, this);
return this;
this.worldName = ps.worldName;
this.blockX = ps.blockX;
this.blockY = ps.blockY;
this.blockZ = ps.blockZ;
this.locationX = ps.locationX;
this.locationY = ps.locationY;
this.locationZ = ps.locationZ;
this.chunkX = ps.chunkX;
this.chunkZ = ps.chunkZ;
this.pitch = ps.pitch;
this.yaw = ps.yaw;
this.velocityX = ps.velocityX;
this.velocityY = ps.velocityY;
this.velocityZ = ps.velocityZ;
}
// ---------------------
public synchronized PS read(Location location)
public synchronized void setLocation(Location location)
{
return this.readDefault().readTransparent(location);
this.setDefault();
this.setLocationTransparent(location);
}
public synchronized PS readTransparent(Location location)
public synchronized void setLocationTransparent(Location location)
{
this.worldName = location.getWorld().getName();
this.locationX = location.getX();
@ -351,79 +380,77 @@ public class PS implements Cloneable
this.locationZ = location.getZ();
this.setPitch(location.getPitch());
this.yaw = location.getYaw();
return this;
}
// ---------------------
public synchronized PS read(Vector vector)
public synchronized void setVelocity(Vector vector)
{
return this.readDefault().readTransparent(vector);
this.setDefault();
this.setVelocityTransparent(vector);
}
public synchronized PS readTransparent(Vector vector)
public synchronized void setVelocityTransparent(Vector vector)
{
this.velocityX = vector.getX();
this.velocityY = vector.getY();
this.velocityZ = vector.getZ();
return this;
}
// ---------------------
public synchronized PS read(Player player)
public synchronized void setEntity(Entity entity)
{
return this.readDefault().readTransparent(player);
this.setDefault();
this.setEntityTransparent(entity);
}
public synchronized PS readTransparent(Player player)
public synchronized void setEntityTransparent(Entity entity)
{
this.readTransparent(player.getLocation());
this.readTransparent(player.getVelocity());
return this;
this.setLocationTransparent(entity.getLocation());
this.setVelocityTransparent(entity.getVelocity());
}
// ---------------------
public synchronized PS read(Block block)
public synchronized void setBlock(Block block)
{
return this.readDefault().readTransparent(block);
this.setDefault();
this.setBlockTransparent(block);
}
public synchronized PS readTransparent(Block block)
public synchronized void setBlockTransparent(Block block)
{
this.worldName = block.getWorld().getName();
this.blockX = block.getX();
this.blockY = block.getY();
this.blockZ = block.getZ();
return this;
}
// ---------------------
public synchronized PS read(Chunk chunk)
public synchronized void setChunk(Chunk chunk)
{
return this.readDefault().readTransparent(chunk);
this.setDefault();
this.setChunkTransparent(chunk);
}
public synchronized PS readTransparent(Chunk chunk)
public synchronized void setChunkTransparent(Chunk chunk)
{
this.worldName = chunk.getWorld().getName();
this.chunkX = chunk.getX();
this.chunkZ = chunk.getZ();
return this;
}
// ---------------------
// TODO: This should be removed later on when my converting phase is complete.
public synchronized PS read(String str)
public synchronized void setOldString(String str)
{
return this.readDefault().readTransparent(str);
this.setDefault();
this.setOldStringTransparent(str);
}
public synchronized PS readTransparent(String str)
public synchronized void setOldStringTransparent(String str)
{
String[] parts = str.split("\\|");
@ -443,8 +470,6 @@ public class PS implements Cloneable
this.pitch = Float.parseFloat(parts[4]);
this.yaw = Float.parseFloat(parts[5]);
}
return this;
}
@ -468,32 +493,37 @@ public class PS implements Cloneable
public PS(PS ps)
{
this.read(ps);
this.setPS(ps);
}
public PS(Location location)
{
this.read(location);
this.setLocationTransparent(location);
}
public PS(Vector vector)
public PS(Vector velocity)
{
this.read(vector);
this.setVelocityTransparent(velocity);
}
public PS(Player player)
public PS(Entity entity)
{
this.read(player);
this.setEntityTransparent(entity);
}
public PS(Block block)
{
this.read(block);
this.setBlockTransparent(block);
}
public PS(Chunk chunk)
{
this.read(chunk);
this.setChunkTransparent(chunk);
}
public PS(String oldString)
{
this.setOldStringTransparent(oldString);
}
//----------------------------------------------//

View File

@ -22,7 +22,7 @@ public class PSAdapter implements JsonDeserializer<PS>
{
if (json.isJsonPrimitive())
{
return new PS().read(json.getAsString());
return new PS(json.getAsString());
}
return new Gson().fromJson(json, typeOfT);
}

View File

@ -4,6 +4,9 @@ import java.util.*;
import java.util.Map.Entry;
import java.util.logging.Level;
import lombok.Getter;
import lombok.Setter;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.SimpleCommandMap;
@ -29,9 +32,7 @@ public abstract class MCommand
// FIELD: subCommands
// The sub-commands to this command
protected List<MCommand> subCommands;
public List<MCommand> getSubCommands() { return this.subCommands; }
public void setSubCommands(List<MCommand> val) { this.subCommands = val; }
@Getter @Setter protected List<MCommand> subCommands;
public void addSubCommand(MCommand subCommand)
{
subCommand.commandChain.addAll(this.commandChain);
@ -41,24 +42,18 @@ public abstract class MCommand
// FIELD: aliases
// The different names this commands will react to
protected List<String> aliases;
public List<String> getAliases() { return this.aliases; }
public void setAliases(List<String> val) { this.aliases = val; }
@Getter @Setter protected List<String> aliases;
public void addAliases(String... aliases) { this.aliases.addAll(Arrays.asList(aliases)); }
public void addAliases(List<String> aliases) { this.aliases.addAll(aliases); }
// FIELD: requiredArgs
// These args must always be sent
protected List<String> requiredArgs;
public List<String> getRequiredArgs() { return this.requiredArgs; }
public void setRequiredArgs(List<String> val) { this.requiredArgs = val; }
@Getter @Setter protected List<String> requiredArgs;
public void addRequiredArg(String arg) { this.requiredArgs.add(arg); }
// FIELD: optionalArgs
// These args are optional
protected Map<String, String> optionalArgs;
public Map<String, String> getOptionalArgs() { return this.optionalArgs; }
public void setOptionalArgs(Map<String, String> val) { this.optionalArgs = val; }
@Getter @Setter protected Map<String, String> optionalArgs;
public void addOptionalArg(String arg, String def) { this.optionalArgs.put(arg, def); }
// FIELD: errorOnToManyArgs
@ -69,16 +64,13 @@ public abstract class MCommand
// FIELD: requirements
// All these requirements must be met for the command to be executable;
protected List<IReq> requirements;
public List<IReq> getRequirements() { return this.requirements; }
public void setRequirements(List<IReq> val) { this.requirements = val; }
@Getter @Setter protected List<IReq> requirements;
public void addRequirements(IReq... requirements) { this.requirements.addAll(Arrays.asList(requirements)); }
// FIELD: desc
// This field may be left blank and will in such case be loaded from the permissions node instead.
// Thus make sure the permissions node description is an action description like "eat hamburgers" or "do admin stuff".
protected String desc = null;
public void setDesc(String val) { this.desc = val; }
@Setter protected String desc = null;
public String getDesc()
{
if (this.desc != null) return this.desc;
@ -98,7 +90,7 @@ public abstract class MCommand
// FIELD: descPermission
// This permission node IS NOT TESTED AT ALL. It is rather used in the method above.
protected String descPermission;
@Setter protected String descPermission;
public String getDescPermission()
{
if (this.descPermission != null) return this.descPermission;
@ -110,7 +102,6 @@ public abstract class MCommand
}
return null;
}
public void setDescPermission(String val) { this.descPermission = val; }
// FIELD: help
// This is a multi-line help text for the command.
@ -120,9 +111,7 @@ public abstract class MCommand
public List<String> getHelp() { return this.help; }
// FIELD: visibilityMode
protected VisibilityMode visibilityMode;
public VisibilityMode getVisibilityMode() { return this.visibilityMode; }
public void setVisibilityMode(VisibilityMode val) { this.visibilityMode = val; }
@Getter @Setter protected VisibilityMode visibilityMode;
// -------------------------------------------- //
// EXECUTION INFO
@ -130,15 +119,11 @@ public abstract class MCommand
// FIELD: args
// Will contain the arguments, or and empty list if there are none.
protected List<String> args;
public List<String> getArgs() { return this.args; }
public void setArgs(List<String> val) { this.args = val; }
@Getter @Setter protected List<String> args;
// FIELD: commandChain
// The command chain used to execute this command
protected List<MCommand> commandChain = new ArrayList<MCommand>();
public List<MCommand> getCommandChain() { return this.commandChain; }
public void setCommandChain(List<MCommand> val) { this.commandChain = val; }
@Getter @Setter protected List<MCommand> commandChain = new ArrayList<MCommand>();
// FIELDS: sender, me, senderIsConsole
public CommandSender sender;

View File

@ -30,7 +30,7 @@ public class ARAspect extends ARAbstractSelect<Aspect>
@Override
public Collection<String> altNames(MCommand mcommand)
{
return AspectColl.i.ids();
return AspectColl.i.getIds();
}
// -------------------------------------------- //

View File

@ -30,7 +30,7 @@ public class ARMultiverse extends ARAbstractSelect<Multiverse>
@Override
public Collection<String> altNames(MCommand mcommand)
{
return MultiverseColl.i.ids();
return MultiverseColl.i.getIds();
}
// -------------------------------------------- //

View File

@ -4,24 +4,16 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import lombok.Getter;
import lombok.Setter;
public class ArgResult<T>
{
// -------------------------------------------- //
// FIELD: RESULT
// -------------------------------------------- //
protected T result = null;
public T getResult()
{
return this.result;
}
public void setResult(T val)
{
this.result = val;
}
@Getter @Setter protected T result = null;
public boolean hasResult()
{
return this.getResult() != null;
@ -31,12 +23,7 @@ public class ArgResult<T>
// FIELD: ERRORS
// -------------------------------------------- //
protected List<String> errors = new ArrayList<String>();
public List<String> getErrors()
{
return this.errors;
}
@Getter protected List<String> errors = new ArrayList<String>();
public void setErrors(List<String> val)
{

View File

@ -22,7 +22,7 @@ public class AHAspect extends AHBase<Aspect>
this.error.add("<b>No aspect called \"<p>"+str+"<b>\".");
if (Permission.USYS_ASPECT_LIST.has(sender, false))
{
this.error.add("<i>Use "+Txt.implodeCommaAndDot(AspectColl.i.ids(), "<h>%s", "<i>, ", " <i>or ", "<i>."));
this.error.add("<i>Use "+Txt.implodeCommaAndDot(AspectColl.i.getIds(), "<h>%s", "<i>, ", " <i>or ", "<i>."));
}
}

View File

@ -23,7 +23,7 @@ public class AHMultiverse extends AHBase<Multiverse>
this.error.add("<b>No multiverse called \"<p>"+str+"<b>\".");
if (Permission.USYS_MULTIVERSE_LIST.has(sender, false))
{
this.error.add("<i>Use "+Txt.implodeCommaAndDot(MultiverseColl.i.ids(), "<h>%s", "<i>, ", " <i>or ", "<i>."));
this.error.add("<i>Use "+Txt.implodeCommaAndDot(MultiverseColl.i.getIds(), "<h>%s", "<i>, ", " <i>or ", "<i>."));
}
}

View File

@ -1,5 +1,8 @@
package com.massivecraft.mcore4.cmd.req;
import lombok.Getter;
import lombok.Setter;
import org.bukkit.command.CommandSender;
import com.massivecraft.mcore4.cmd.MCommand;
@ -7,9 +10,7 @@ import com.massivecraft.mcore4.util.Perm;
public class ReqHasPerm implements IReq
{
private String perm;
public String getPerm() { return this.perm; }
public void setPerm(String val) { this.perm = val; }
@Getter @Setter private String perm;
public ReqHasPerm(String perm)
{

View File

@ -1,5 +1,7 @@
package com.massivecraft.mcore4.event;
import lombok.Getter;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
@ -20,14 +22,11 @@ public class MCoreAfterPlayerRespawnEvent extends Event implements Runnable
// FIELD
// -------------------------------------------- //
protected Location deathLocation;
public Location getDeathLocation() { return this.deathLocation; }
@Getter protected final Location deathLocation;
protected PlayerRespawnEvent bukkitEvent;
public PlayerRespawnEvent getBukkitEvent() { return this.bukkitEvent; }
@Getter protected final PlayerRespawnEvent bukkitEvent;
public Location getRespawnLocation() { return this.bukkitEvent.getRespawnLocation(); }
public Player getPlayer() { return this.bukkitEvent.getPlayer(); }
// -------------------------------------------- //

View File

@ -1,5 +1,7 @@
package com.massivecraft.mcore4.event;
import lombok.Getter;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
@ -21,8 +23,7 @@ public class MCoreAfterPlayerTeleportEvent extends Event implements Runnable
// FIELD
// -------------------------------------------- //
protected PlayerTeleportEvent bukkitEvent;
public PlayerTeleportEvent getBukkitEvent() { return this.bukkitEvent; }
@Getter protected final PlayerTeleportEvent bukkitEvent;
public Location getFrom() { return this.bukkitEvent.getFrom(); }
public Location getTo() { return this.bukkitEvent.getTo(); }

View File

@ -3,6 +3,8 @@ package com.massivecraft.mcore4.event;
import java.util.HashMap;
import java.util.Map;
import lombok.Getter;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
@ -31,20 +33,16 @@ public class MCorePlayerLeaveEvent extends Event implements Runnable
// FIELD
// -------------------------------------------- //
protected Player player;
public Player getPlayer() { return this.player; }
@Getter protected final Player player;
protected boolean preDisconnect;
public boolean isPreDisconnect() { return this.preDisconnect; }
@Getter protected final boolean preDisconnect;
public boolean isPostDisconnect() { return !this.isPreDisconnect(); }
protected String caller;
public String getCaller() { return this.caller; }
@Getter protected final String caller;
public boolean isQuit() { return "quit".equals(caller); }
public boolean isKick() { return "kick".equals(caller); }
protected String message;
public String getMessage() { return this.message; }
@Getter protected final String message;
// -------------------------------------------- //
// CONSTRUCT

View File

@ -1,5 +1,7 @@
package com.massivecraft.mcore4.integration;
import lombok.Getter;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@ -20,8 +22,7 @@ public class Integration implements Listener
protected MPlugin ourPlugin;
protected IntegrationFeatures features;
protected boolean active = false;
public boolean active() { return this.active; }
@Getter protected boolean active = false;
// -------------------------------------------- //
// CONSTRUCT

View File

@ -31,52 +31,52 @@ public class Coll<E, L> implements CollInterface<E, L>
// -------------------------------------------- //
protected final String name;
@Override public String name() { return this.name; }
@Override public String getName() { return this.name; }
protected final String basename;
@Override public String basename() { return this.basename; }
@Override public String getBasename() { return this.basename; }
protected final String universe;
@Override public String universe() { return this.universe; }
@Override public String getUniverse() { return this.universe; }
protected final Class<E> entityClass;
@Override public Class<E> entityClass() { return this.entityClass; }
@Override public Class<E> getEntityClass() { return this.entityClass; }
protected final Class<L> idClass;
@Override public Class<L> idClass() { return this.idClass; }
@Override public Class<L> getIdClass() { return this.idClass; }
// -------------------------------------------- //
// SUPPORTING SYSTEM
// -------------------------------------------- //
protected MPlugin mplugin;
@Override public MPlugin mplugin() { return this.mplugin; }
@Override public MPlugin getMplugin() { return this.mplugin; }
protected Db<?> db;
@Override public Db<?> db() { return this.db; }
@Override public Driver<?> driver() { return this.db.driver(); }
@Override public Db<?> getDb() { return this.db; }
@Override public Driver<?> getDriver() { return this.db.getDriver(); }
protected IdStrategy<L, ?> idStrategy;
@Override public IdStrategy<L, ?> idStrategy() { return this.idStrategy; }
@Override public IdStrategy<L, ?> getIdStrategy() { return this.idStrategy; }
protected StoreAdapter storeAdapter;
@Override public StoreAdapter storeAdapter() { return this.storeAdapter; }
@Override public StoreAdapter getStoreAdapter() { return this.storeAdapter; }
protected Object collDriverObject;
@Override public Object collDriverObject() { return this.collDriverObject; }
@Override public Object getCollDriverObject() { return this.collDriverObject; }
// -------------------------------------------- //
// STORAGE
// -------------------------------------------- //
protected Set<L> ids = Collections.newSetFromMap(new ConcurrentHashMap<L, Boolean>());
@Override public Collection<L> ids() { return Collections.unmodifiableCollection(this.ids); }
@Override public Collection<L> idsRemote() { return this.db().driver().ids(this); }
@Override public Collection<L> getIds() { return Collections.unmodifiableCollection(this.ids); }
@Override public Collection<L> getIdsRemote() { return this.getDb().getDriver().getIds(this); }
@Override public boolean containsEntity(E entity) { return this.entities.contains(entity); };
@Override
public boolean containsId(Object oid)
{
L id = this.idFix(oid);
L id = this.fixId(oid);
if (id == null) return false;
return this.ids.contains(id);
}
@ -90,11 +90,11 @@ public class Coll<E, L> implements CollInterface<E, L>
@Override public Collection<E> getAll(Predictate<E> where, Comparator<E> orderby, Integer limit, Integer offset) { return MStoreUtil.uglySQL(this.getAll(), where, orderby, limit, offset); }
protected Map<L, E> id2entity = new ConcurrentHashMap<L, E>();
@Override public Map<L, E> id2entity() { return Collections.unmodifiableMap(this.id2entity); }
@Override public Map<L, E> getId2entity() { return Collections.unmodifiableMap(this.id2entity); }
@Override
public E get(Object oid)
{
return this.get(oid, this.creative());
return this.get(oid, this.isCreative());
}
@Override
public E get(Object oid, boolean creative)
@ -103,7 +103,7 @@ public class Coll<E, L> implements CollInterface<E, L>
}
protected E get(Object oid, boolean creative, boolean noteChange)
{
L id = this.idFix(oid);
L id = this.fixId(oid);
if (id == null) return null;
E ret = this.id2entity.get(id);
if (ret != null) return ret;
@ -113,11 +113,11 @@ public class Coll<E, L> implements CollInterface<E, L>
// Get the id for this entity.
protected Map<E, L> entity2id = new ConcurrentHashMap<E, L>();
@Override public Map<E, L> entity2id() { return Collections.unmodifiableMap(this.entity2id); }
@Override public L id(E entity) { return this.entity2id.get(entity); }
@Override public Map<E, L> getEntity2id() { return Collections.unmodifiableMap(this.entity2id); }
@Override public L getId(E entity) { return this.entity2id.get(entity); }
@Override
public L idFix(Object oid)
public L fixId(Object oid)
{
if (oid == null) return null;
if (oid.getClass() == this.idClass) return this.idClass.cast(oid);
@ -130,8 +130,8 @@ public class Coll<E, L> implements CollInterface<E, L>
// -------------------------------------------- //
protected boolean creative;
@Override public boolean creative() { return this.creative; }
@Override public void creative(boolean val) { this.creative = val; }
@Override public boolean isCreative() { return this.creative; }
@Override public void setCreative(boolean val) { this.creative = val; }
// Should that instance be saved or not?
// If it is default it should not be saved.
@ -152,7 +152,7 @@ public class Coll<E, L> implements CollInterface<E, L>
}
else
{
Accessor.get(this.entityClass()).copy(ofrom, oto);
Accessor.get(this.getEntityClass()).copy(ofrom, oto);
}
}
@ -213,17 +213,17 @@ public class Coll<E, L> implements CollInterface<E, L>
{
// Check entity
if (entity == null) return null;
L id = this.id(entity);
L id = this.getId(entity);
if (id != null) return id;
// Check/Fix id
if (oid == null)
{
id = this.idStrategy().generate(this);
id = this.getIdStrategy().generate(this);
}
else
{
id = this.idFix(oid);
id = this.fixId(oid);
if (id == null) return null;
if (this.ids.contains(id)) return null;
}
@ -266,7 +266,7 @@ public class Coll<E, L> implements CollInterface<E, L>
}
else
{
id = this.idFix(o);
id = this.fixId(o);
}
if (id == null)
{
@ -339,7 +339,7 @@ public class Coll<E, L> implements CollInterface<E, L>
this.clearIdentifiedChanges(id);
this.clearSynclog(id);
this.db().driver().delete(this, id);
this.getDb().getDriver().delete(this, id);
}
@Override
@ -351,17 +351,17 @@ public class Coll<E, L> implements CollInterface<E, L>
E entity = this.id2entity.get(id);
if (entity == null) return;
Object raw = this.storeAdapter().read(this, entity);
Object raw = this.getStoreAdapter().read(this, entity);
this.lastRaw.put(id, raw);
if (this.isDefault(entity))
{
this.db.driver().delete(this, id);
this.db.getDriver().delete(this, id);
this.lastDefault.add(id);
}
else
{
Long mtime = this.db.driver().save(this, id, raw);
Long mtime = this.db.getDriver().save(this, id, raw);
if (mtime == null) return; // This fail should not happen often. We could handle it better though.
this.lastMtime.put(id, mtime);
}
@ -372,7 +372,7 @@ public class Coll<E, L> implements CollInterface<E, L>
{
this.clearIdentifiedChanges(id);
Entry<?, Long> entry = this.db().driver().load(this, id);
Entry<?, Long> entry = this.getDb().getDriver().load(this, id);
if (entry == null) return;
Object raw = entry.getKey();
@ -383,10 +383,10 @@ public class Coll<E, L> implements CollInterface<E, L>
E entity = this.get(id, true, false);
this.storeAdapter().write(this, raw, entity);
this.getStoreAdapter().write(this, raw, entity);
// Store adapter again since result of a database read may be "different" from entity read.
this.lastRaw.put(id, this.storeAdapter().read(this, entity));
this.lastRaw.put(id, this.getStoreAdapter().read(this, entity));
this.lastMtime.put(id, mtime);
this.lastDefault.remove(id);
}
@ -415,7 +415,7 @@ public class Coll<E, L> implements CollInterface<E, L>
E localEntity = this.id2entity.get(id);
if ( ! remoteMtimeSupplied)
{
remoteMtime = this.driver().mtime(this, id);
remoteMtime = this.getDriver().getMtime(this, id);
}
boolean existsLocal = (localEntity != null);
@ -500,7 +500,7 @@ public class Coll<E, L> implements CollInterface<E, L>
{
// Find all ids
Set<L> allids = new HashSet<L>(this.ids);
allids.addAll(this.driver().ids(this));
allids.addAll(this.getDriver().getIds(this));
for (L id : allids)
{
this.syncId(id);
@ -511,7 +511,7 @@ public class Coll<E, L> implements CollInterface<E, L>
public void findSuspects()
{
// Get remote id and mtime snapshot
Map<L, Long> id2RemoteMtime = this.db().driver().id2mtime(this);
Map<L, Long> id2RemoteMtime = this.getDb().getDriver().getId2mtime(this);
// Compile a list of all ids (both remote and local)
Set<L> allids = new HashSet<L>();
@ -524,7 +524,7 @@ public class Coll<E, L> implements CollInterface<E, L>
Long remoteMtime = id2RemoteMtime.get(id);
ModificationState state = this.examineId(id, remoteMtime);
//mplugin.log("findSuspects: It seems", id, "has state", state);
if (state.modified())
if (state.isModified())
{
//System.out.println("It seems "+id+" has state "+state);
this.changedIds.add(id);
@ -537,7 +537,7 @@ public class Coll<E, L> implements CollInterface<E, L>
// -------------------------------------------- //
protected Runnable tickTask;
@Override public Runnable tickTask() { return this.tickTask; }
@Override public Runnable getTickTask() { return this.tickTask; }
@Override
public void onTick()
{
@ -572,15 +572,15 @@ public class Coll<E, L> implements CollInterface<E, L>
this.mplugin = mplugin;
this.db = db;
this.storeAdapter = this.db.driver().getStoreAdapter();
this.idStrategy = this.db.driver().getIdStrategy(idStrategyName);
this.storeAdapter = this.db.getDriver().getStoreAdapter();
this.idStrategy = this.db.getDriver().getIdStrategy(idStrategyName);
if (this.idStrategy == null)
{
throw new IllegalArgumentException("UNKNOWN: The id stragegy \""+idStrategyName+"\" is unknown to the driver \""+db.driver().name()+"\".");
throw new IllegalArgumentException("UNKNOWN: The id stragegy \""+idStrategyName+"\" is unknown to the driver \""+db.getDriver().getName()+"\".");
}
else if (this.idStrategy.getLocalClass() != idClass)
{
throw new IllegalArgumentException("MISSMATCH: The id stragegy \""+idStrategyName+"\" for the driver \""+db.driver().name()+"\" uses \""+this.idStrategy.getLocalClass().getSimpleName()+"\" but the collection "+this.name+"/"+this.getClass().getSimpleName()+" uses \""+idClass.getSimpleName()+"\".");
throw new IllegalArgumentException("MISSMATCH: The id stragegy \""+idStrategyName+"\" for the driver \""+db.getDriver().getName()+"\" uses \""+this.idStrategy.getLocalClass().getSimpleName()+"\" but the collection "+this.name+"/"+this.getClass().getSimpleName()+" uses \""+idClass.getSimpleName()+"\".");
}
this.collDriverObject = db.getCollDriverObject(this);

View File

@ -14,28 +14,28 @@ public interface CollInterface<E, L>
// -------------------------------------------- //
// WHAT DO WE HANDLE?
// -------------------------------------------- //
public String name();
public String basename();
public String universe();
public Class<E> entityClass();
public Class<L> idClass();
public String getName();
public String getBasename();
public String getUniverse();
public Class<E> getEntityClass();
public Class<L> getIdClass();
// -------------------------------------------- //
// SUPPORTING SYSTEM
// -------------------------------------------- //
public MPlugin mplugin();
public MPlugin getMplugin();
public Db<?> db();
public Driver<?> driver();
public StoreAdapter storeAdapter();
public IdStrategy<L, ?> idStrategy();
public Object collDriverObject();
public Db<?> getDb();
public Driver<?> getDriver();
public StoreAdapter getStoreAdapter();
public IdStrategy<L, ?> getIdStrategy();
public Object getCollDriverObject();
// -------------------------------------------- //
// STORAGE
// -------------------------------------------- //
public Collection<L> ids();
public Collection<L> idsRemote();
public Collection<L> getIds();
public Collection<L> getIdsRemote();
public boolean containsId(Object oid);
public boolean containsEntity(E entity);
@ -45,19 +45,19 @@ public interface CollInterface<E, L>
public Collection<E> getAll(Predictate<E> where, Comparator<E> orderby, Integer limit);
public Collection<E> getAll(Predictate<E> where, Comparator<E> orderby, Integer limit, Integer offset);
public Map<L, E> id2entity();
public Map<L, E> getId2entity();
public E get(Object oid);
public E get(Object oid, boolean creative);
public Map<E, L> entity2id();
public L id(E entity);
public L idFix(Object oid);
public Map<E, L> getEntity2id();
public L getId(E entity);
public L fixId(Object oid);
// -------------------------------------------- //
// BAHAVIOR
// -------------------------------------------- //
public boolean creative();
public void creative(boolean val);
public boolean isCreative();
public void setCreative(boolean val);
// A default entity will not be saved.
// This is often used together with creative collections to save disc space.
@ -133,7 +133,7 @@ public interface CollInterface<E, L>
// -------------------------------------------- //
// The tickTask simply runs the onTick method.
public Runnable tickTask();
public Runnable getTickTask();
public void onTick();
public Thread examineThread();

View File

@ -13,8 +13,8 @@ public abstract class Colls<C extends Coll<E, L>, E, L>
{
protected Map<String, C> name2coll = new HashMap<String, C>();
public abstract Aspect aspect();
public abstract String basename();
public abstract Aspect getAspect();
public abstract String getBasename();
public abstract C createColl(String name);
// -------------------------------------------- //
@ -29,7 +29,7 @@ public abstract class Colls<C extends Coll<E, L>, E, L>
public List<C> getColls()
{
List<C> ret = new ArrayList<C>();
Aspect a = this.aspect();
Aspect a = this.getAspect();
Multiverse m = a.multiverse();
for (String universe : m.getUniverses())
{
@ -44,14 +44,14 @@ public abstract class Colls<C extends Coll<E, L>, E, L>
public String collnameForUniverse(String universe)
{
return this.basename() + "@" + universe;
return this.getBasename() + "@" + universe;
}
public String universeFromWorldName(String worldName)
{
if (worldName == null) throw new IllegalArgumentException("worldName may not be null.");
return this.aspect().multiverse().getUniverseForWorldName(worldName);
return this.getAspect().multiverse().getUniverseForWorldName(worldName);
}
// -------------------------------------------- //

View File

@ -4,13 +4,13 @@ import java.util.Set;
public interface Db<R>
{
public String name();
public String getName();
public boolean drop();
public Set<String> collnames();
public Set<String> getCollnames();
public Driver<R> driver();
public Driver<R> getDriver();
public Object getCollDriverObject(Coll<?, ?> coll);
}

View File

@ -5,8 +5,8 @@ import java.util.Set;
public abstract class DbAbstract<R> implements Db<R>
{
@Override
public Set<String> collnames()
public Set<String> getCollnames()
{
return this.driver().collnames(this);
return this.getDriver().getCollnames(this);
}
}

View File

@ -14,7 +14,7 @@ public class DbGson extends DbAbstract<JsonElement>
public File dir;
protected DriverGson driver;
@Override public DriverGson driver() { return driver; }
@Override public DriverGson getDriver() { return driver; }
// -------------------------------------------- //
// CONSTRUCTORS
@ -31,7 +31,7 @@ public class DbGson extends DbAbstract<JsonElement>
// -------------------------------------------- //
@Override
public String name()
public String getName()
{
return dir.getAbsolutePath();
}
@ -52,6 +52,6 @@ public class DbGson extends DbAbstract<JsonElement>
@Override
public Object getCollDriverObject(Coll<?, ?> coll)
{
return new File(dir, coll.name());
return new File(dir, coll.getName());
}
}

View File

@ -12,7 +12,7 @@ public class DbMongo extends DbAbstract<BasicDBObject>
public DB db;
protected DriverMongo driver;
@Override public DriverMongo driver() { return driver; }
@Override public DriverMongo getDriver() { return driver; }
// -------------------------------------------- //
// CONSTRUCTORS
@ -29,7 +29,7 @@ public class DbMongo extends DbAbstract<BasicDBObject>
// -------------------------------------------- //
@Override
public String name()
public String getName()
{
return db.getName();
}
@ -51,6 +51,6 @@ public class DbMongo extends DbAbstract<BasicDBObject>
@Override
public Object getCollDriverObject(Coll<?, ?> coll)
{
return db.getCollection(coll.name());
return db.getCollection(coll.getName());
}
}

View File

@ -11,7 +11,7 @@ import com.massivecraft.mcore4.store.storeadapter.StoreAdapter;
public interface Driver<R>
{
// Returns the name of the driver.
public String name();
public String getName();
// This is the rawdata format this driver works with.
// Could for example be JsonElement or DBObject
@ -25,22 +25,22 @@ public interface Driver<R>
public StoreAdapter getStoreAdapter();
// Get a database instance from the driver
public Db<R> db(String uri);
public Db<R> getDb(String uri);
// What collections are in the database?
public Set<String> collnames(Db<?> db);
public Set<String> getCollnames(Db<?> db);
// Is id X in the collection?
public <L> boolean containsId(Coll<?, L> coll, L id);
// When was X last altered?
public <L> Long mtime(Coll<?, L> coll, L id);
public <L> Long getMtime(Coll<?, L> coll, L id);
// What ids are in the collection?
public <L> Collection<L> ids(Coll<?, L> coll);
public <L> Collection<L> getIds(Coll<?, L> coll);
// Return a map of all ids with their corresponding mtimes
public <L> Map<L, Long> id2mtime(Coll<?, L> coll);
public <L> Map<L, Long> getId2mtime(Coll<?, L> coll);
// Load the raw data for X. The second part of the entry is the remote mtime at the load.
public <L> Entry<R, Long> load(Coll<?, L> coll, L id);

View File

@ -13,7 +13,7 @@ public abstract class DriverAbstract<R> implements Driver<R>
}
protected String name;
@Override public String name() { return this.name; }
@Override public String getName() { return this.name; }
protected Map<String, IdStrategy<?, ?>> idStrategies = new HashMap<String, IdStrategy<?, ?>>();
@Override

View File

@ -37,7 +37,7 @@ public class DriverGson extends DriverAbstract<JsonElement>
}
@Override
public Db<JsonElement> db(String uri)
public Db<JsonElement> getDb(String uri)
{
// "gson://" is 7 chars
File folder = new File(uri.substring(7));
@ -46,7 +46,7 @@ public class DriverGson extends DriverAbstract<JsonElement>
}
@Override
public Set<String> collnames(Db<?> db)
public Set<String> getCollnames(Db<?> db)
{
Set<String> ret = new LinkedHashSet<String>();
@ -66,7 +66,7 @@ public class DriverGson extends DriverAbstract<JsonElement>
}
@Override
public <L> Long mtime(Coll<?, L> coll, L id)
public <L> Long getMtime(Coll<?, L> coll, L id)
{
File file = fileFromId(coll, id);
if ( ! file.isFile()) return null;
@ -74,7 +74,7 @@ public class DriverGson extends DriverAbstract<JsonElement>
}
@Override
public <L> Collection<L> ids(Coll<?, L> coll)
public <L> Collection<L> getIds(Coll<?, L> coll)
{
List<L> ret = new ArrayList<L>();
@ -85,7 +85,7 @@ public class DriverGson extends DriverAbstract<JsonElement>
{
// Then convert them to what they should be
String remoteId = idFromFile(file);
L localId = coll.idStrategy().remoteToLocal(remoteId);
L localId = coll.getIdStrategy().remoteToLocal(remoteId);
ret.add(localId);
}
@ -93,7 +93,7 @@ public class DriverGson extends DriverAbstract<JsonElement>
}
@Override
public <L> Map<L, Long> id2mtime(Coll<?, L> coll)
public <L> Map<L, Long> getId2mtime(Coll<?, L> coll)
{
Map<L, Long> ret = new HashMap<L, Long>();
@ -104,7 +104,7 @@ public class DriverGson extends DriverAbstract<JsonElement>
{
// Then convert them to what they should be
String remoteId = idFromFile(file);
L localId = coll.idStrategy().remoteToLocal(remoteId);
L localId = coll.getIdStrategy().remoteToLocal(remoteId);
ret.put(localId, file.lastModified());
}
@ -128,7 +128,7 @@ public class DriverGson extends DriverAbstract<JsonElement>
public <L> Long save(Coll<?, L> coll, L id, Object rawData)
{
File file = fileFromId(coll, id);
String content = coll.mplugin().gson.toJson((JsonElement)rawData);
String content = coll.getMplugin().gson.toJson((JsonElement)rawData);
if (DiscUtil.writeCatch(file, content) == false) return null;
return file.lastModified();
}
@ -146,7 +146,7 @@ public class DriverGson extends DriverAbstract<JsonElement>
protected static File getCollDir(Coll<?, ?> coll)
{
return (File) coll.collDriverObject();
return (File) coll.getCollDriverObject();
}
protected static String idFromFile(File file)
@ -159,7 +159,7 @@ public class DriverGson extends DriverAbstract<JsonElement>
protected static <L> File fileFromId(Coll<?, L> coll, L id)
{
File collDir = getCollDir(coll);
String idString = (String)coll.idStrategy().localToRemote(id);
String idString = (String)coll.getIdStrategy().localToRemote(id);
File idFile = new File(collDir, idString+DOTJSON);
return idFile;
}

View File

@ -47,14 +47,14 @@ public class DriverMongo extends DriverAbstract<BasicDBObject>
}
@Override
public Db<BasicDBObject> db(String uri)
public Db<BasicDBObject> getDb(String uri)
{
DB db = this.getDbInner(uri);
return new DbMongo(this, db);
}
@Override
public Set<String> collnames(Db<?> db)
public Set<String> getCollnames(Db<?> db)
{
return ((DbMongo)db).db.getCollectionNames();
}
@ -63,22 +63,22 @@ public class DriverMongo extends DriverAbstract<BasicDBObject>
public <L> boolean containsId(Coll<?, L> coll, L id)
{
DBCollection dbcoll = fixColl(coll);
DBCursor cursor = dbcoll.find(new BasicDBObject(ID_FIELD, coll.idStrategy().localToRemote(id)));
DBCursor cursor = dbcoll.find(new BasicDBObject(ID_FIELD, coll.getIdStrategy().localToRemote(id)));
return cursor.count() != 0;
}
@Override
public <L> Long mtime(Coll<?, L> coll, L id)
public <L> Long getMtime(Coll<?, L> coll, L id)
{
DBCollection dbcoll = fixColl(coll);
BasicDBObject found = (BasicDBObject)dbcoll.findOne(new BasicDBObject(ID_FIELD, coll.idStrategy().localToRemote(id)), dboKeysMtime);
BasicDBObject found = (BasicDBObject)dbcoll.findOne(new BasicDBObject(ID_FIELD, coll.getIdStrategy().localToRemote(id)), dboKeysMtime);
if (found == null) return null;
if ( ! found.containsField(MTIME_FIELD)) return null; // This should not happen! But better to ignore than crash?
return found.getLong(MTIME_FIELD);
}
@Override
public <L> Collection<L> ids(Coll<?, L> coll)
public <L> Collection<L> getIds(Coll<?, L> coll)
{
List<L> ret = null;
@ -91,7 +91,7 @@ public class DriverMongo extends DriverAbstract<BasicDBObject>
while(cursor.hasNext())
{
Object remoteId = cursor.next().get(ID_FIELD);
L localId = coll.idStrategy().remoteToLocal(remoteId);
L localId = coll.getIdStrategy().remoteToLocal(remoteId);
ret.add(localId);
}
}
@ -104,7 +104,7 @@ public class DriverMongo extends DriverAbstract<BasicDBObject>
}
@Override
public <L> Map<L, Long> id2mtime(Coll<?, L> coll)
public <L> Map<L, Long> getId2mtime(Coll<?, L> coll)
{
Map<L, Long> ret = null;
@ -118,7 +118,7 @@ public class DriverMongo extends DriverAbstract<BasicDBObject>
{
BasicDBObject raw = (BasicDBObject)cursor.next();
Object remoteId = raw.get(ID_FIELD);
L localId = coll.idStrategy().remoteToLocal(remoteId);
L localId = coll.getIdStrategy().remoteToLocal(remoteId);
if ( ! raw.containsField(MTIME_FIELD)) continue; // This should not happen! But better to ignore than crash?
Long mtime = raw.getLong(MTIME_FIELD);
ret.put(localId, mtime);
@ -136,7 +136,7 @@ public class DriverMongo extends DriverAbstract<BasicDBObject>
public <L> Entry<BasicDBObject, Long> load(Coll<?, L> coll, L id)
{
DBCollection dbcoll = fixColl(coll);
BasicDBObject raw = (BasicDBObject)dbcoll.findOne(new BasicDBObject(ID_FIELD, coll.idStrategy().localToRemote(id)));
BasicDBObject raw = (BasicDBObject)dbcoll.findOne(new BasicDBObject(ID_FIELD, coll.getIdStrategy().localToRemote(id)));
if (raw == null) return null;
Long mtime = (Long) raw.removeField(MTIME_FIELD);
return new SimpleEntry<BasicDBObject, Long>(raw, mtime);
@ -153,7 +153,7 @@ public class DriverMongo extends DriverAbstract<BasicDBObject>
Long mtime = System.currentTimeMillis();
data.put(MTIME_FIELD, mtime);
Object remoteId = coll.idStrategy().localToRemote(id);
Object remoteId = coll.getIdStrategy().localToRemote(id);
dbcoll.update(new BasicDBObject(ID_FIELD, remoteId), data, true, false);
return mtime;
@ -162,7 +162,7 @@ public class DriverMongo extends DriverAbstract<BasicDBObject>
@Override
public <L> void delete(Coll<?, L> coll, L id)
{
fixColl(coll).remove(new BasicDBObject(ID_FIELD, coll.idStrategy().localToRemote(id)));
fixColl(coll).remove(new BasicDBObject(ID_FIELD, coll.getIdStrategy().localToRemote(id)));
}
//----------------------------------------------//
@ -171,7 +171,7 @@ public class DriverMongo extends DriverAbstract<BasicDBObject>
protected static DBCollection fixColl(Coll<?, ?> coll)
{
return (DBCollection) coll.collDriverObject();
return (DBCollection) coll.getCollDriverObject();
}
protected DB getDbInner(String uri)

View File

@ -28,7 +28,7 @@ public abstract class Entity<E extends Entity<E, L>, L>
Coll<E, L> coll = this.getColl();
if (coll == null) return null;
return coll.universe();
return coll.getUniverse();
}
public L attach(Coll<E, L> coll)
@ -61,7 +61,7 @@ public abstract class Entity<E extends Entity<E, L>, L>
{
Coll<E, L> coll = this.getColl();
if (coll == null) return null;
return coll.id(this.getThis());
return coll.getId(this.getThis());
}
public void changed()
@ -100,7 +100,7 @@ public abstract class Entity<E extends Entity<E, L>, L>
{
Gson gson = MCore.gson;
Coll<E, L> coll = this.getColl();
if (coll != null) gson = coll.mplugin().gson;
if (coll != null) gson = coll.getMplugin().gson;
return this.getClazz().getSimpleName()+gson.toJson(this, this.getClazz());
}

View File

@ -7,7 +7,7 @@ public class ExamineThread<E, L> extends Thread
public ExamineThread(Coll<E, L> coll)
{
this.coll = coll;
this.setName("ExamineThread for "+coll.name());
this.setName("ExamineThread for "+coll.getName());
}
// TODO: Implement logging and/or auto adjusting system for how long the sleep should be?

View File

@ -13,8 +13,8 @@ public class MStore
protected static Map<String, Driver<?>> drivers = new HashMap<String, Driver<?>>();
public static boolean registerDriver(Driver<?> driver)
{
if (drivers.containsKey(driver.name())) return false;
drivers.put(driver.name(), driver);
if (drivers.containsKey(driver.getName())) return false;
drivers.put(driver.getName(), driver);
return true;
}
public static Driver<?> getDriver(String id)
@ -42,7 +42,7 @@ public class MStore
String scheme = uri.getScheme();
Driver<?> driver = getDriver(scheme);
if (driver == null) return null;
return driver.db(uri.toString());
return driver.getDb(uri.toString());
}
static

View File

@ -13,11 +13,11 @@ public enum ModificationState
;
private final boolean modified;
public boolean modified() { return this.modified; }
public boolean isModified() { return this.modified; }
private final boolean local;
public boolean local() { return this.local; }
public boolean remote() { return this.local == false; }
public boolean isLocal() { return this.local; }
public boolean isRemote() { return this.local == false; }
private ModificationState(boolean modified, boolean local)
{

View File

@ -67,7 +67,7 @@ public class PlayerColl<E extends PlayerEntity<E>> extends Coll<E, String>
// -------------------------------------------- //
@Override
public String idFix(Object oid)
public String fixId(Object oid)
{
if (oid == null) return null;
String ret = MUtil.extract(String.class, "playerName", oid);
@ -105,8 +105,8 @@ public class PlayerColl<E extends PlayerEntity<E>> extends Coll<E, String>
protected Collection<Collection<String>> forgeAltColls()
{
Collection<Collection<String>> ret = new ArrayList<Collection<String>>();
ret.add(this.ids());
if (this.creative()) ret.add(PlayerUtil.getAllVisitorNames());
ret.add(this.getIds());
if (this.isCreative()) ret.add(PlayerUtil.getAllVisitorNames());
return ret;
}

View File

@ -5,7 +5,7 @@ import java.util.Collection;
public abstract class EntityAccessorAbstract implements EntityAccessor
{
protected final Class<?> clazz;
public Class<?> clazz() { return this.clazz; }
public Class<?> getClazz() { return this.clazz; }
public EntityAccessorAbstract(Class<?> clazz)
{

View File

@ -7,8 +7,8 @@ import java.util.Map;
public class EntityAccessorPerProperty extends EntityAccessorAbstract
{
protected Map<String, PropertyAccessor> propertyAccessors;
public Map<String, PropertyAccessor> propertyAccessors() { return this.propertyAccessors; }
public PropertyAccessor propertyAccessor(String name)
public Map<String, PropertyAccessor> getPropertyAccessors() { return this.propertyAccessors; }
public PropertyAccessor getPropertyAccessor(String name)
{
PropertyAccessor ret = this.propertyAccessors.get(name);
if (ret == null)
@ -17,7 +17,7 @@ public class EntityAccessorPerProperty extends EntityAccessorAbstract
}
return ret;
}
public void propertyAccessor(String name, PropertyAccessor val)
public void setPropertyAccessor(String name, PropertyAccessor val)
{
this.propertyAccessors.put(name, val);
}
@ -66,14 +66,14 @@ public class EntityAccessorPerProperty extends EntityAccessorAbstract
@Override
public void set(Object entity, String property, Object val)
{
PropertyAccessor pa = this.propertyAccessor(property);
PropertyAccessor pa = this.getPropertyAccessor(property);
pa.set(entity, val);
}
@Override
public Object get(Object entity, String property)
{
PropertyAccessor pa = this.propertyAccessor(property);
PropertyAccessor pa = this.getPropertyAccessor(property);
return pa.get(entity);
}

View File

@ -26,7 +26,7 @@ public abstract class IdStrategyAbstract<L, R> implements IdStrategy<L, R>
@Override
public L generate(CollInterface<?, L> coll)
{
Collection<L> alreadyInUse = coll.ids();
Collection<L> alreadyInUse = coll.getIds();
L ret = null;
do
{

View File

@ -61,8 +61,8 @@ public class IdStrategyAiGson extends IdStrategyAbstract<String, String>
protected File getAiFile(CollInterface<?, String> coll)
{
DbGson cdb = (DbGson)coll.db();
return new File(cdb.dir, coll.name() + "_ai.txt");
DbGson cdb = (DbGson)coll.getDb();
return new File(cdb.dir, coll.getName() + "_ai.txt");
}
protected boolean ensureFileExists(File file)

View File

@ -39,8 +39,8 @@ public class IdStrategyAiMongo extends IdStrategyAbstract<String, String>
@Override
public String generateAttempt(CollInterface<?, String> coll)
{
String sequenseName = coll.name();
DBCollection sequenseCollection = ((DbMongo)coll.db()).db.getCollection(SEC);
String sequenseName = coll.getName();
DBCollection sequenseCollection = ((DbMongo)coll.getDb()).db.getCollection(SEC);
// this object represents your "query", its analogous to a WHERE clause in SQL
DBObject query = new BasicDBObject();

View File

@ -13,13 +13,13 @@ public class StoreAdapterGson extends StoreAdapterAbstract
@Override
public Object read(Coll<?, ?> coll, Object entity)
{
return coll.mplugin().gson.toJsonTree(entity, coll.entityClass());
return coll.getMplugin().gson.toJsonTree(entity, coll.getEntityClass());
}
@Override
public void write(Coll<?, ?> coll, Object raw, Object entity)
{
Object temp = coll.mplugin().gson.fromJson((JsonElement)raw, coll.entityClass());
Object temp = coll.getMplugin().gson.fromJson((JsonElement)raw, coll.getEntityClass());
coll.copy(temp, entity);
}

View File

@ -4,6 +4,9 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import lombok.Getter;
import lombok.Setter;
import com.massivecraft.mcore4.MCore;
import com.massivecraft.mcore4.store.Entity;
import com.massivecraft.mcore4.xlib.gson.annotations.SerializedName;
@ -29,23 +32,19 @@ public class Aspect extends Entity<Aspect, String>
// TRANSIENT FIELDS
// -------------------------------------------- //
protected transient boolean registered = false;
public boolean registered() { return this.registered; }
@Getter protected transient boolean registered = false;
public void register() { this.registered = true; }
protected transient Collection<String> desc = new ArrayList<String>();
public Collection<String> desc() { return this.desc; }
public void desc(Collection<String> val) { this.desc = val; }
public void desc(String... val) { this.desc = Arrays.asList(val); }
@Getter protected transient Collection<String> desc = new ArrayList<String>();
public void setDesc(Collection<String> val) { this.desc = val; }
public void setDesc(String... val) { this.desc = Arrays.asList(val); }
// -------------------------------------------- //
// STORED FIELDS
// -------------------------------------------- //
@SerializedName("mid")
protected String multiverseId;
public String multiverseId() { return this.multiverseId; }
public void multiverseId(String val) { this.multiverseId = val; }
@Getter @Setter protected String multiverseId;
public Multiverse multiverse()
{
Multiverse ret = MultiverseColl.i.get(this.multiverseId);

View File

@ -28,7 +28,7 @@ public class AspectColl extends Coll<Aspect, String>
List<Aspect> ret = new ArrayList<Aspect>();
for (Aspect aspect : this.getAll())
{
if(aspect.registered() == false) continue;
if(aspect.isRegistered() == false) continue;
ret.add(aspect);
}
return ret;
@ -39,7 +39,7 @@ public class AspectColl extends Coll<Aspect, String>
List<Aspect> ret = new ArrayList<Aspect>();
for (Aspect aspect : this.getAll())
{
if(aspect.registered() == false) continue;
if(aspect.isRegistered() == false) continue;
if((aspect.multiverse() != multiverse) == normal) continue;
ret.add(aspect);
}

View File

@ -25,7 +25,7 @@ public class CmdUsysAspectShow extends UsysCommand
msg(Txt.titleize("Aspect: "+aspect.getId()));
msg("<k>using multiverse: <v>%s",aspect.multiverse().getId());
for (String descLine : aspect.desc())
for (String descLine : aspect.getDesc())
{
msg(descLine);
}

View File

@ -19,7 +19,7 @@ public class CmdUsysMultiverseNew extends UsysCommand
{
String id = this.arg(0);
if (MultiverseColl.i.ids().contains(id))
if (MultiverseColl.i.getIds().contains(id))
{
msg("<b>The multiverse <h>%s<b> alread exists.", id);
return;