Detaching entities and ids using separate methods. Made ids sort naturally as well.

This commit is contained in:
Olof Larsson 2013-01-09 09:51:53 +01:00
parent 514162387f
commit 3d0d0c1862
3 changed files with 14 additions and 24 deletions

View File

@ -70,7 +70,7 @@ public class Coll<E, L extends Comparable<? super L>> implements CollInterface<E
// STORAGE // STORAGE
// -------------------------------------------- // // -------------------------------------------- //
protected Set<L> ids = Collections.newSetFromMap(new ConcurrentHashMap<L, Boolean>()); protected Set<L> ids = new ConcurrentSkipListSet<L>();
@Override public Collection<L> getIds() { return Collections.unmodifiableCollection(this.ids); } @Override public Collection<L> getIds() { return Collections.unmodifiableCollection(this.ids); }
@Override public Collection<L> getIdsRemote() { return this.getDb().getDriver().getIds(this); } @Override public Collection<L> getIdsRemote() { return this.getDb().getDriver().getIds(this); }
@Override public boolean containsEntity(Object entity) { return this.entities.contains(entity); }; @Override public boolean containsEntity(Object entity) { return this.entities.contains(entity); };
@ -252,28 +252,17 @@ public class Coll<E, L extends Comparable<? super L>> implements CollInterface<E
return id; return id;
} }
@SuppressWarnings("unchecked")
@Override @Override
public synchronized E detach(Object o) public E detachEntity(Object entity)
{ {
// What id is this? return this.detachId(this.getId(entity));
L id = null; }
if (this.idClass.isInstance(o))
{ @Override
id = (L)o; public E detachId(Object oid)
} {
else if (this.entityClass.isInstance(o)) L id = this.fixId(oid);
{ if (id == null) return null;
id = this.entity2id.get(o);
}
else
{
id = this.fixId(o);
}
if (id == null)
{
return null;
}
// Remove @ local // Remove @ local
E ret = this.removeAtLocal(id); E ret = this.removeAtLocal(id);

View File

@ -83,7 +83,8 @@ public interface CollInterface<E, L extends Comparable<? super L>>
// -------------------------------------------- // // -------------------------------------------- //
public L attach(E entity); public L attach(E entity);
public L attach(E entity, Object oid); public L attach(E entity, Object oid);
public E detach(Object o); public E detachEntity(Object entity);
public E detachId(Object oid);
// -------------------------------------------- // // -------------------------------------------- //
// IDENTIFIED CHANGES // IDENTIFIED CHANGES

View File

@ -10,7 +10,7 @@ import com.massivecraft.mcore5.xlib.gson.Gson;
* Entity class. It just contains a set of shortcut methods. * Entity class. It just contains a set of shortcut methods.
*/ */
// Self referencing generic using the "getThis trick". // Self referencing generic.
// http://www.angelikalanger.com/GenericsFAQ/FAQSections/ProgrammingIdioms.html#FAQ206 // http://www.angelikalanger.com/GenericsFAQ/FAQSections/ProgrammingIdioms.html#FAQ206
public abstract class Entity<E extends Entity<E, L>, L extends Comparable<? super L>> implements Comparable<E> public abstract class Entity<E extends Entity<E, L>, L extends Comparable<? super L>> implements Comparable<E>
{ {
@ -37,7 +37,7 @@ public abstract class Entity<E extends Entity<E, L>, L extends Comparable<? supe
Coll<E, L> coll = this.getColl(); Coll<E, L> coll = this.getColl();
if (coll == null) return null; if (coll == null) return null;
return coll.detach(this); return coll.detachEntity(this);
} }
public boolean attached() public boolean attached()