Detaching entities and ids using separate methods. Made ids sort naturally as well.
This commit is contained in:
		
							parent
							
								
									514162387f
								
							
						
					
					
						commit
						3d0d0c1862
					
				| @ -70,7 +70,7 @@ public class Coll<E, L extends Comparable<? super L>> implements CollInterface<E | ||||
| 	// 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> getIdsRemote() { return this.getDb().getDriver().getIds(this); } | ||||
| 	@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; | ||||
| 	} | ||||
| 		 | ||||
| 	@SuppressWarnings("unchecked") | ||||
| 	@Override | ||||
| 	public synchronized E detach(Object o) | ||||
| 	public E detachEntity(Object entity) | ||||
| 	{ | ||||
| 		// What id is this? | ||||
| 		L id = null; | ||||
| 		if (this.idClass.isInstance(o)) | ||||
| 		{ | ||||
| 			id = (L)o; | ||||
| 		return this.detachId(this.getId(entity)); | ||||
| 	} | ||||
| 		else if (this.entityClass.isInstance(o)) | ||||
| 	 | ||||
| 	@Override | ||||
| 	public E detachId(Object oid) | ||||
| 	{ | ||||
| 			id = this.entity2id.get(o); | ||||
| 		} | ||||
| 		else | ||||
| 		{ | ||||
| 			id = this.fixId(o); | ||||
| 		} | ||||
| 		if (id == null) | ||||
| 		{ | ||||
| 			return null; | ||||
| 		} | ||||
| 		L id = this.fixId(oid); | ||||
| 		if (id == null) return null; | ||||
| 		 | ||||
| 		// Remove @ local | ||||
| 		E ret = this.removeAtLocal(id); | ||||
|  | ||||
| @ -83,7 +83,8 @@ public interface CollInterface<E, L extends Comparable<? super L>> | ||||
| 	// -------------------------------------------- // | ||||
| 	public L attach(E entity); | ||||
| 	public L attach(E entity, Object oid); | ||||
| 	public E detach(Object o); | ||||
| 	public E detachEntity(Object entity); | ||||
| 	public E detachId(Object oid); | ||||
| 	 | ||||
| 	// -------------------------------------------- // | ||||
| 	// IDENTIFIED CHANGES | ||||
|  | ||||
| @ -10,7 +10,7 @@ import com.massivecraft.mcore5.xlib.gson.Gson; | ||||
|  * 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 | ||||
| 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(); | ||||
| 		if (coll == null) return null; | ||||
| 		 | ||||
| 		return coll.detach(this); | ||||
| 		return coll.detachEntity(this); | ||||
| 	} | ||||
| 	 | ||||
| 	public boolean attached() | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user