Not going to be lazy

This commit is contained in:
Olof Larsson 2015-03-05 00:14:09 +01:00
parent 5eaaeec680
commit 525d904f8f
3 changed files with 13 additions and 28 deletions

View File

@ -90,14 +90,11 @@ public class Coll<E> implements CollInterface<E>
// STORAGE // STORAGE
// -------------------------------------------- // // -------------------------------------------- //
// All
protected Set<String> ids;
// Loaded // Loaded
protected Map<String, E> id2entity; protected Map<String, E> id2entity;
protected Map<E, String> entity2id; protected Map<E, String> entity2id;
@Override public Collection<String> getIds() { return Collections.unmodifiableCollection(this.ids); } @Override public Collection<String> getIds() { return Collections.unmodifiableCollection(this.id2entity.keySet()); }
@Override public Map<String, E> getId2entity() { return Collections.unmodifiableMap(this.id2entity); } @Override public Map<String, E> getId2entity() { return Collections.unmodifiableMap(this.id2entity); }
@Override @Override
@ -127,7 +124,7 @@ public class Coll<E> implements CollInterface<E>
{ {
String id = this.fixId(oid); String id = this.fixId(oid);
if (id == null) return false; if (id == null) return false;
return this.ids.contains(id); return this.id2entity.containsKey(id);
} }
@Override public Map<E, String> getEntity2id() { return Collections.unmodifiableMap(this.entity2id); } @Override public Map<E, String> getEntity2id() { return Collections.unmodifiableMap(this.entity2id); }
@ -166,10 +163,6 @@ public class Coll<E> implements CollInterface<E>
// BEHAVIOR // BEHAVIOR
// -------------------------------------------- // // -------------------------------------------- //
protected boolean lazy;
@Override public boolean isLazy() { return this.lazy; }
@Override public void setLazy(boolean lazy) { this.lazy = lazy; }
protected boolean creative; protected boolean creative;
@Override public boolean isCreative() { return this.creative; } @Override public boolean isCreative() { return this.creative; }
@Override public void setCreative(boolean creative) { this.creative = creative; } @Override public void setCreative(boolean creative) { this.creative = creative; }
@ -331,7 +324,6 @@ public class Coll<E> implements CollInterface<E>
} }
// Attach // Attach
this.ids.add(id);
this.id2entity.put(id, entity); this.id2entity.put(id, entity);
this.entity2id.put(entity, id); this.entity2id.put(entity, id);
@ -514,8 +506,6 @@ public class Coll<E> implements CollInterface<E>
this.entity2id.remove(entity); this.entity2id.remove(entity);
this.ids.remove(id);
// Remove entity reference info // Remove entity reference info
if (entity instanceof Entity) if (entity instanceof Entity)
{ {
@ -830,7 +820,7 @@ public class Coll<E> implements CollInterface<E>
// Compile a list of all ids (both remote and local) // Compile a list of all ids (both remote and local)
Set<String> allids = new HashSet<String>(); Set<String> allids = new HashSet<String>();
allids.addAll(id2RemoteMtime.keySet()); allids.addAll(id2RemoteMtime.keySet());
allids.addAll(this.ids); allids.addAll(this.id2entity.keySet());
// Check for modifications // Check for modifications
for (String id : allids) for (String id : allids)
@ -876,7 +866,7 @@ public class Coll<E> implements CollInterface<E>
// CONSTRUCT // CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
public Coll(String name, Class<E> entityClass, Db db, Plugin plugin, boolean lazy, boolean creative, boolean lowercasing, Comparator<? super String> idComparator, Comparator<? super E> entityComparator) public Coll(String name, Class<E> entityClass, Db db, Plugin plugin, boolean creative, boolean lowercasing, Comparator<? super String> idComparator, Comparator<? super E> entityComparator)
{ {
// Setup the name and the parsed parts // Setup the name and the parsed parts
this.name = name; this.name = name;
@ -892,8 +882,7 @@ public class Coll<E> implements CollInterface<E>
} }
// WHAT DO WE HANDLE? // WHAT DO WE HANDLE?
this.entityClass = entityClass; this.entityClass = entityClass;
this.lazy = lazy;
this.creative = creative; this.creative = creative;
this.lowercasing = lowercasing; this.lowercasing = lowercasing;
@ -908,7 +897,6 @@ public class Coll<E> implements CollInterface<E>
// Avoid "Classname cannot be cast to java.lang.Comparable" error in ConcurrentSkipListMap // Avoid "Classname cannot be cast to java.lang.Comparable" error in ConcurrentSkipListMap
entityComparator = HashCodeComparator.get(); entityComparator = HashCodeComparator.get();
} }
this.ids = new ConcurrentSkipListSet<String>(idComparator);
this.id2entity = new ConcurrentSkipListMap<String, E>(idComparator); this.id2entity = new ConcurrentSkipListMap<String, E>(idComparator);
this.entity2id = new ConcurrentSkipListMap<E, String>(entityComparator); this.entity2id = new ConcurrentSkipListMap<E, String>(entityComparator);
@ -929,14 +917,14 @@ public class Coll<E> implements CollInterface<E>
}; };
} }
public Coll(String name, Class<E> entityClass, Db db, Plugin plugin, boolean lazy, boolean creative, boolean lowercasing) public Coll(String name, Class<E> entityClass, Db db, Plugin plugin, boolean creative, boolean lowercasing)
{ {
this(name, entityClass, db, plugin, lazy, creative, lowercasing, null, null); this(name, entityClass, db, plugin, creative, lowercasing, null, null);
} }
public Coll(String name, Class<E> entityClass, Db db, Plugin plugin) public Coll(String name, Class<E> entityClass, Db db, Plugin plugin)
{ {
this(name, entityClass, db, plugin, false, false, false); this(name, entityClass, db, plugin, false, false);
} }
@Override @Override

View File

@ -56,9 +56,6 @@ public interface CollInterface<E>
// BEHAVIOR // BEHAVIOR
// -------------------------------------------- // // -------------------------------------------- //
public boolean isLazy();
public void setLazy(boolean lazy);
public boolean isCreative(); public boolean isCreative();
public void setCreative(boolean creative); public void setCreative(boolean creative);

View File

@ -19,19 +19,19 @@ public class SenderColl<E extends SenderEntity<E>> extends Coll<E> implements Se
// CONSTRUCT // CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
public SenderColl(String name, Class<E> entityClass, Db db, Plugin plugin, boolean lazy, 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, Comparator<? super String> idComparator, Comparator<? super E> entityComparator)
{ {
super(name, entityClass, db, plugin, lazy, creative, lowercasing, idComparator, entityComparator); super(name, entityClass, db, plugin, creative, lowercasing, idComparator, entityComparator);
} }
public SenderColl(String name, Class<E> entityClass, Db db, Plugin plugin, boolean lazy, boolean creative, boolean lowercasing) public SenderColl(String name, Class<E> entityClass, Db db, Plugin plugin, boolean creative, boolean lowercasing)
{ {
super(name, entityClass, db, plugin, lazy, creative, lowercasing); super(name, entityClass, db, plugin, creative, lowercasing);
} }
public SenderColl(String name, Class<E> entityClass, Db db, Plugin plugin) public SenderColl(String name, Class<E> entityClass, Db db, Plugin plugin)
{ {
super(name, entityClass, db, plugin, true, true, true); super(name, entityClass, db, plugin, true, true);
} }
// -------------------------------------------- // // -------------------------------------------- //