From e4942a2eb8dbef2a879d451702b41df7f0c9c0c4 Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Wed, 16 Jan 2013 12:33:16 +0100 Subject: [PATCH] The two sets were of course redundant. The two maps covered those two cases. --- src/com/massivecraft/mcore5/store/Coll.java | 50 ++++++++----------- .../mcore5/store/CollInterface.java | 13 +++-- 2 files changed, 26 insertions(+), 37 deletions(-) diff --git a/src/com/massivecraft/mcore5/store/Coll.java b/src/com/massivecraft/mcore5/store/Coll.java index 0ffd099b..247b8977 100644 --- a/src/com/massivecraft/mcore5/store/Coll.java +++ b/src/com/massivecraft/mcore5/store/Coll.java @@ -70,27 +70,6 @@ public class Coll> implements CollInterface ids; - @Override public Collection getIds() { return Collections.unmodifiableCollection(this.ids); } - @Override public Collection getIdsRemote() { return this.getDb().getDriver().getIds(this); } - @Override public boolean containsEntity(Object entity) { return this.entities.contains(entity); }; - @Override - public boolean containsId(Object oid) - { - L id = this.fixId(oid); - if (id == null) return false; - return this.ids.contains(id); - } - - // We use a ConcurrentSkipListSet here in order for the entities to keep their natural ordering - // You may want to have your entities implement the Comparable interface - protected Set entities; - @Override public Collection getAll() { return Collections.unmodifiableCollection(this.entities); } - @Override public Collection getAll(Predictate where) { return MStoreUtil.uglySQL(this.getAll(), where, null, null, null); } - @Override public Collection getAll(Predictate where, Comparator orderby) { return MStoreUtil.uglySQL(this.getAll(), where, orderby, null, null); } - @Override public Collection getAll(Predictate where, Comparator orderby, Integer limit) { return MStoreUtil.uglySQL(this.getAll(), where, orderby, limit, null); } - @Override public Collection getAll(Predictate where, Comparator orderby, Integer limit, Integer offset) { return MStoreUtil.uglySQL(this.getAll(), where, orderby, limit, offset); } - protected Map id2entity; @Override public Map getId2entity() { return Collections.unmodifiableMap(this.id2entity); } @Override @@ -113,10 +92,27 @@ public class Coll> implements CollInterface getIds() { return Collections.unmodifiableCollection(this.id2entity.keySet()); } + @Override public Collection getIdsRemote() { return this.getDb().getDriver().getIds(this); } + @Override + public boolean containsId(Object oid) + { + L id = this.fixId(oid); + if (id == null) return false; + return this.id2entity.containsKey(id); + } + // Get the id for this entity. protected Map entity2id; @Override public Map getEntity2id() { return Collections.unmodifiableMap(this.entity2id); } @Override public L getId(Object entity) { return this.entity2id.get(entity); } + @Override public boolean containsEntity(Object entity) { return this.entity2id.containsKey(entity); }; + + @Override public Collection getAll() { return Collections.unmodifiableCollection(this.entity2id.keySet()); } + @Override public Collection getAll(Predictate where) { return MStoreUtil.uglySQL(this.getAll(), where, null, null, null); } + @Override public Collection getAll(Predictate where, Comparator orderby) { return MStoreUtil.uglySQL(this.getAll(), where, orderby, null, null); } + @Override public Collection getAll(Predictate where, Comparator orderby, Integer limit) { return MStoreUtil.uglySQL(this.getAll(), where, orderby, limit, null); } + @Override public Collection getAll(Predictate where, Comparator orderby, Integer limit, Integer offset) { return MStoreUtil.uglySQL(this.getAll(), where, orderby, limit, offset); } @Override public L fixId(Object oid) @@ -227,7 +223,7 @@ public class Coll> implements CollInterface> implements CollInterface> implements CollInterface> implements CollInterface allids = new HashSet(this.ids); + Set allids = new HashSet(this.id2entity.keySet()); allids.addAll(this.getDriver().getIds(this)); for (L id : allids) { @@ -520,7 +512,7 @@ public class Coll> implements CollInterface allids = new HashSet(); allids.addAll(id2RemoteMtime.keySet()); - allids.addAll(this.ids); + allids.addAll(this.id2entity.keySet()); // Check for modifications for (L id : allids) @@ -591,8 +583,6 @@ public class Coll> implements CollInterface(idComparator); - this.entities = new ConcurrentSkipListSet(entityComparator); this.id2entity = new ConcurrentSkipListMap(idComparator); this.entity2id = new ConcurrentSkipListMap(entityComparator); diff --git a/src/com/massivecraft/mcore5/store/CollInterface.java b/src/com/massivecraft/mcore5/store/CollInterface.java index acfbb28e..dd163b94 100644 --- a/src/com/massivecraft/mcore5/store/CollInterface.java +++ b/src/com/massivecraft/mcore5/store/CollInterface.java @@ -34,23 +34,22 @@ public interface CollInterface> // -------------------------------------------- // // STORAGE // -------------------------------------------- // + public Map getId2entity(); + public E get(Object oid); + public E get(Object oid, boolean creative); public Collection getIds(); public Collection getIdsRemote(); public boolean containsId(Object oid); - public boolean containsEntity(Object entity); + public Map getEntity2id(); + public L getId(Object entity); + public boolean containsEntity(Object entity); public Collection getAll(); public Collection getAll(Predictate where); public Collection getAll(Predictate where, Comparator orderby); public Collection getAll(Predictate where, Comparator orderby, Integer limit); public Collection getAll(Predictate where, Comparator orderby, Integer limit, Integer offset); - public Map getId2entity(); - public E get(Object oid); - public E get(Object oid, boolean creative); - - public Map getEntity2id(); - public L getId(Object entity); public L fixId(Object oid); // -------------------------------------------- //