Interface EntityManager
-
public interface EntityManager
Entity manager holds, manages and indexes a collection of entities. Methods that find entities by various parameters will always return a view that will not be updated on changes. Usually every composite entity has it's own entity manager.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
cleanAll()
Removes dirty flag from all entities, e.g.<T extends AbstractEntity>
Tcopy(T entity, boolean copyEntityId)
Copies an entityList<AbstractEntity>
copyAll()
Copies all entities at onceAbstractEntity
create(AbstractEntityDef entityDef)
Create a new entity by a given entity definition.<T extends AbstractEntity>
Tcreate(Class<T> clazz, AbstractEntityDef entityDef)
Create a new entity by a given entity definition, already cast to a certain clazz.void
delete(AbstractEntity entity)
Deletes an entity from this entity managervoid
delete(UUID entityId)
Deletes an entity from this entity managervoid
deleteAll()
Deletes all entities from this entity managervoid
dirty(AbstractEntity entity)
Sets dirty flag on an entity - it is important to set dirty flag on the server side after every change.void
executeAtPosition(CoordI2 entityPos, Consumer<AbstractEntity> consumer)
Calls a consumer for any entity that exists at a certain position.boolean
existsByPosition(CoordI2 entityPos)
Checks whether any entity exists at a certain position.boolean
existsByPosition(CoordI2 entityPos, Predicate<AbstractEntity> filter)
Checks whether any entity exists at a certain position matching filter.List<AbstractEntity>
findAll()
Returns all entitiesAbstractEntity
findBy(UUID uuid)
Returns an entity by UUID or null if it is not registered.List<AbstractEntity>
findByCategory(String category)
Get entity by category.Iterator<AbstractEntity>
findByCategoryFast(String category)
Get entity by category.List<AbstractEntity>
findByDef(int entityDefId)
Finds entities related to a given entity definition indexList<AbstractEntity>
findByDef(Class<? extends AbstractEntityDef> clazz)
Finds entities related to a given entity definitionList<AbstractEntity>
findByDef(String entityDefName)
Finds entities related to a given name of an entity definitionList<AbstractEntity>
findByDef(UUID entityDefUUID)
Finds entities related to a given entity definition UUIDList<AbstractEntity>
findByPosition(CoordI2 entityPos)
Finds all entities at a given position.Iterator<AbstractEntity>
findByPositionFast(CoordI2 entityPos)
Finds all entities at a given position.<T> List<T>
findByType(Class<T> clazz)
Returns all entities of a certain type (also entities deriving from this type).List<UUID>
findDeleted()
Set<String>
getModNames()
int
getSize()
boolean
isEntitiesDirty()
boolean
matchByType(Predicate<Class<?>> matchBucket, Predicate<AbstractEntity> matchEntity)
Advanced matching of entities.void
move(AbstractEntity entity, CoordI2 entityPos)
Moves an entity to a new spatial position entityPos - It is VERY important to always use this method to move entities instead of setting the position property directly, because entity manager indexes entities for faster spatial lookups.void
put(AbstractEntity entity)
Puts an entity to the entity manager.void
put(Iterable<? extends AbstractEntity> entities, boolean clone)
Puts a collection of entities at once to the entity manager.void
resetAll()
Resets all entities, setting default values on all propertiesvoid
setParentCompositeEntity(UUID parentCompositeEntity)
-
-
-
Method Detail
-
create
AbstractEntity create(AbstractEntityDef entityDef)
Create a new entity by a given entity definition. After creating an entity, the usual process is to set additional properties (this is the only case where you are allowed to set the position directly on an entity), then add it to entity manager with #put
-
create
<T extends AbstractEntity> T create(Class<T> clazz, AbstractEntityDef entityDef)
Create a new entity by a given entity definition, already cast to a certain clazz. Compatibility to the target type is checked, throws an exception if not compatible. After creating an entity, the usual process is to set additional properties, then add it to entity manager with #put
-
put
void put(AbstractEntity entity)
Puts an entity to the entity manager. Entity manager distinguishes between new entities, updated entities (instance already known to entity manager) and updated external entities (instance not known but update by UUID) and handles it accordingly.
-
put
void put(Iterable<? extends AbstractEntity> entities, boolean clone)
Puts a collection of entities at once to the entity manager. This has some performance advantages over calling it for each entity separately. Entity manager distinguishes between new entities, updated entities (instance already known to entity manager) and updated external entities (instance not known but update by UUID) and handles it accordingly.
-
delete
void delete(AbstractEntity entity)
Deletes an entity from this entity manager
-
delete
void delete(UUID entityId)
Deletes an entity from this entity manager
-
deleteAll
void deleteAll()
Deletes all entities from this entity manager
-
move
void move(AbstractEntity entity, CoordI2 entityPos)
Moves an entity to a new spatial position entityPos - It is VERY important to always use this method to move entities instead of setting the position property directly, because entity manager indexes entities for faster spatial lookups.
-
copy
<T extends AbstractEntity> T copy(T entity, boolean copyEntityId)
Copies an entity
-
copyAll
List<AbstractEntity> copyAll()
Copies all entities at once
-
cleanAll
void cleanAll()
Removes dirty flag from all entities, e.g. on server side after changes have been sent to the clients
-
resetAll
void resetAll()
Resets all entities, setting default values on all properties
-
dirty
void dirty(AbstractEntity entity)
Sets dirty flag on an entity - it is important to set dirty flag on the server side after every change. Reason is the server only sends out incremental changes each turn to the clients.
-
isEntitiesDirty
boolean isEntitiesDirty()
-
findBy
AbstractEntity findBy(UUID uuid)
Returns an entity by UUID or null if it is not registered.
-
findByPosition
List<AbstractEntity> findByPosition(CoordI2 entityPos)
Finds all entities at a given position. The lookup is indexed. More resources needed than findByPositionFast but result is not affected by comodification of entities. A shallow copy is returned.
-
findByPositionFast
Iterator<AbstractEntity> findByPositionFast(CoordI2 entityPos)
Finds all entities at a given position. The lookup is indexed. Faster than findByPosition but iterator has fail-fast behavior when entities are comodified. Returned iterator is read-only.
-
findByType
<T> List<T> findByType(Class<T> clazz)
Returns all entities of a certain type (also entities deriving from this type).
-
findByDef
List<AbstractEntity> findByDef(Class<? extends AbstractEntityDef> clazz)
Finds entities related to a given entity definition
-
findByDef
List<AbstractEntity> findByDef(String entityDefName)
Finds entities related to a given name of an entity definition
-
findByDef
List<AbstractEntity> findByDef(int entityDefId)
Finds entities related to a given entity definition index
-
findByDef
List<AbstractEntity> findByDef(UUID entityDefUUID)
Finds entities related to a given entity definition UUID
-
findAll
List<AbstractEntity> findAll()
Returns all entities
-
findByCategory
List<AbstractEntity> findByCategory(String category)
Get entity by category. Categories are free to define by entityDef, for builtins see de.extio.spacecraft.shared.model.entity.EntityDefCategoryBuiltinTypes Returns a view (shallow copy).
-
findByCategoryFast
Iterator<AbstractEntity> findByCategoryFast(String category)
Get entity by category. Categories are free to define by entityDef, for builtins see de.extio.spacecraft.shared.model.entity.EntityDefCategoryBuiltinTypes Returns an iterator that is read-only.
-
existsByPosition
boolean existsByPosition(CoordI2 entityPos)
Checks whether any entity exists at a certain position. Faster than #findBy
-
existsByPosition
boolean existsByPosition(CoordI2 entityPos, Predicate<AbstractEntity> filter)
Checks whether any entity exists at a certain position matching filter. Faster than #findBy
-
executeAtPosition
void executeAtPosition(CoordI2 entityPos, Consumer<AbstractEntity> consumer)
Calls a consumer for any entity that exists at a certain position. Faster than #findBy
-
matchByType
boolean matchByType(Predicate<Class<?>> matchBucket, Predicate<AbstractEntity> matchEntity)
Advanced matching of entities. It first create buckets of entities by type (matchBucket) and then checks relevant buckets for a match (matchEntity). Can be faster than returning a shallow copy of all entities with #findAll and then filtering manually in your code.
-
getSize
int getSize()
-
setParentCompositeEntity
void setParentCompositeEntity(UUID parentCompositeEntity)
-
-