public class DefaultEntity extends AbstractIdentifiable implements Entity
Entity implementation.markAsAlive()) or dead (markAsDead()).| Modifier and Type | Field and Description |
|---|---|
protected DefaultAttributeContainer |
attributes
Associated attributes.
|
protected EntityContainer |
container
Parent entity container.
|
protected DefaultEntityContainer |
entities
Child entities.
|
protected DefaultActionScheduler<Entity> |
scheduler
Self action scheduler.
|
protected TagTypeSet |
tags
Current state information.
|
id| Modifier | Constructor and Description |
|---|---|
protected |
DefaultEntity(java.util.UUID id,
EntityFactory factory,
EntityContainer container)
Creates a new default entity instance.
|
| Modifier and Type | Method and Description |
|---|---|
<T> boolean |
addAttributeListener(NamedAttributeType<T> namedType,
AttributeListener<T> listener)
Adds an attribute listener for the supplied named attribute type.
|
boolean |
addEntityListener(EntityListener listener)
Adds a listener for entities.
|
boolean |
addEntityTypeListener(EntityTypeListener listener)
Adds a listener for the entity.
|
void |
cancelAllScheduledForActor()
Cancels all tasks currently running/scheduled (scheduled by this).
|
<T> void |
fireAttributeChanged(NamedAttributeType<T> namedType)
Manually fires an attribute change for the supplied attribute type.
|
<T> T |
getAttribute(NamedAttributeType<T> namedType)
Gets the attribute matching the supplied type.
|
int |
getAttributeCount()
Gets the number of total attributes within the container.
|
<T> java.util.Set<? extends AttributeListener<T>> |
getAttributeListeners(NamedAttributeType<T> namedType)
Gets all attribute listeners associated to the supplied named attribute type.
|
java.util.Set<NamedAttributeType<?>> |
getAttributeListenerTypes()
Gets all of the named attribute types with listeners bound.
|
java.util.Set<NamedAttributeType<?>> |
getAttributeTypes()
Gets all of the named attribute types with attributes.
|
EntityContainer |
getContainer()
Gets the parent container.
|
protected ActionEngine |
getEngine()
Gets the associated action engine.
|
Entity |
getEntity(java.util.UUID id)
Gets the entity with the specified ID.
|
int |
getEntityCount()
Gets the direct entity count.
|
java.util.Set<java.util.UUID> |
getEntityIDs()
Gets the IDs of all the entities within the container.
|
java.util.Set<? extends EntityListener> |
getEntityListeners()
Gets all the entity listeners.
|
java.util.Set<? extends EntityTypeListener> |
getEntityTypeListeners()
Gets all the entity listeners.
|
boolean |
isAlive()
Checks if the entity is alive.
|
boolean |
isMarkedAsType(java.lang.Class<? extends Entity> type)
Checks whether the entity has the associated type.
|
boolean |
kill()
Kills the entity.
|
void |
killEntities()
Kills all entities.
|
boolean |
killEntity(java.util.UUID id)
Kills the specified entity.
|
protected boolean |
markAsAlive()
Marks the entity as alive.
|
protected boolean |
markAsDead()
Marks the entity as dead.
|
boolean |
markAsType(java.lang.Class<? extends Entity> type)
Adds the specified type to the entity.
|
SchedulableActionContext<Entity> |
newContextForActor(Action<Entity> action)
Creates a new mutable context for the supplied action and this actor.
|
Entity |
newEntity(java.util.UUID id,
AttributeContainer sourceContainer)
Creates new entity with the specified ID.
|
<T extends Entity> |
newEntity(java.util.UUID id,
java.lang.Class<T> type,
AttributeContainer sourceContainer)
Creates new entity with the specified ID.
|
boolean |
receiveEntity(Entity e)
Receives an entity (from a transfer).
|
<T> T |
removeAttribute(NamedAttributeType<T> namedType)
Removes the attribute matching the supplied type.
|
<T> boolean |
removeAttributeListener(NamedAttributeType<T> namedType,
AttributeListener<T> listener)
Removes an attribute listener assigned to the supplied attribute type.
|
void |
removeAttributeListeners()
Removes all listeners.
|
<T> void |
removeAttributeListeners(NamedAttributeType<T> namedType)
Removes all listeners for the supplied attribute types.
|
void |
removeAttributes()
Removes all attributes within the container (firing removal events).
|
boolean |
removeEntityListener(EntityListener listener)
Removes a entity listener.
|
void |
removeEntityListeners()
Removes all listeners for entities.
|
boolean |
removeEntityTypeListener(EntityTypeListener listener)
Removes a entity listener.
|
void |
removeEntityTypeListeners()
Removes all listeners for entities.
|
ActionContext<Entity> |
scheduleForActor(Action<Entity> action,
long initialDelay,
long period,
java.util.concurrent.TimeUnit unit)
Schedules an action for execution with a supplied initial delay and repeat period.
|
<T> T |
setAttribute(NamedAttributeType<T> namedType,
T attr)
Adds the supplied attribute to the collection.
|
protected void |
setContainer(EntityContainer container)
Sets the parent container for the entity.
|
protected void |
setEngine(ActionEngine engine)
Associates an engine to the entity for scheduling actions.
|
java.util.stream.Stream<?> |
streamAttributes()
Streams all of the attributes within the container.
|
java.util.stream.Stream<Entity> |
streamEntities()
Provides a stream of entities from the container.
|
java.util.stream.Stream<java.lang.Class<? extends Entity>> |
streamMarkedAsTypes()
Streams the types this entity has been marked as.
|
java.util.stream.Stream<Tag> |
streamTags()
Streams all tag state information.
|
boolean |
transfer(EntityContainer destination)
Transfers this entity to the specified destination container.
|
boolean |
transferEntity(java.util.UUID id,
EntityContainer destination)
Transfers the entity to the supplied destination container.
|
void |
unmarkAsAllTypes()
Removes all the types from the entity.
|
boolean |
unmarkAsType(java.lang.Class<? extends Entity> type)
Removes the specified type from the entity.
|
equals, getID, hashCode, toStringclone, finalize, getClass, notify, notifyAll, wait, wait, waitasType, getMarkedAsTypes, getOptContainer, hasContainer, hasEntityTypeListenergetEntities, getEntitiesAsType, getEntitiesOfType, getEntityAsType, getOptEntity, getOptEntityAsType, hasEntities, hasEntity, hasEntityListener, newEntity, newEntity, newEntity, newEntity, newEntity, newEntity, streamEntitiesAsType, streamEntitiesOfType, streamEntityIDs, transferAllEntities, transferEntities, transferEntitiesequals, getID, getID, hashCode, is, not, toStringaddAll, addAllAttributeListeners, addAllAttributes, addAttributeListener, fireAttributeChanged, getAttribute, getAttributeListenerNames, getAttributeListeners, getAttributeListenerTypes, getAttributeNames, getAttributes, getAttributeTypes, getOptAttribute, getOptAttribute, hasAttribute, hasAttribute, hasAttributeListener, hasAttributeListener, hasAttributeListeners, hasAttributeListeners, hasAttributes, removeAttribute, removeAttributeListener, removeAttributeListeners, removeOptAttribute, removeOptAttribute, setAttribute, setOptAttribute, setOptAttributescheduleForActor, scheduleForActorprotected EntityContainer container
protected final DefaultEntityContainer entities
protected final DefaultAttributeContainer attributes
protected final DefaultActionScheduler<Entity> scheduler
protected final TagTypeSet tags
protected DefaultEntity(java.util.UUID id,
EntityFactory factory,
EntityContainer container)
id - Entity ID.factory - Entity factory for creating/killing child entities.container - Parent entity container.public <T> boolean addAttributeListener(NamedAttributeType<T> namedType, AttributeListener<T> listener)
AttributeContaineraddAttributeListener in interface AttributeContainernamedType - Named attribute type.listener - Listener to add.public boolean addEntityListener(EntityListener listener)
EntityContaineraddEntityListener in interface EntityContainerlistener - Listener to add.true if container did not already contain this listener.ListenerSet.add(Object)public boolean addEntityTypeListener(EntityTypeListener listener)
EntityaddEntityTypeListener in interface Entitylistener - Listener to add.true if container did not already contain this listener.ListenerSet.add(Object)public void cancelAllScheduledForActor()
ActionSchedulercancelAllScheduledForActor in interface ActionScheduler<Entity>public <T> void fireAttributeChanged(NamedAttributeType<T> namedType)
AttributeContainerfireAttributeChanged in interface AttributeContainernamedType - Named attribute type name.public <T> T getAttribute(NamedAttributeType<T> namedType)
AttributeContainergetAttribute in interface AttributeContainernamedType - Named attribute type to check for.public int getAttributeCount()
AttributeContainergetAttributeCount in interface AttributeContainerpublic <T> java.util.Set<? extends AttributeListener<T>> getAttributeListeners(NamedAttributeType<T> namedType)
AttributeContainergetAttributeListeners in interface AttributeContainernamedType - Named attribute type to check for.public java.util.Set<NamedAttributeType<?>> getAttributeListenerTypes()
AttributeContainergetAttributeListenerTypes in interface AttributeContainerpublic java.util.Set<NamedAttributeType<?>> getAttributeTypes()
AttributeContainergetAttributeTypes in interface AttributeContainerpublic EntityContainer getContainer()
EntitygetContainer in interface Entityprotected ActionEngine getEngine()
public Entity getEntity(java.util.UUID id)
EntityContainergetEntity in interface EntityContainerid - Unique ID of the entity.public int getEntityCount()
EntityContainergetEntityCount in interface EntityContainerpublic java.util.Set<java.util.UUID> getEntityIDs()
EntityContainergetEntityIDs in interface EntityContainerpublic java.util.Set<? extends EntityListener> getEntityListeners()
EntityContainergetEntityListeners in interface EntityContainerpublic java.util.Set<? extends EntityTypeListener> getEntityTypeListeners()
EntitygetEntityTypeListeners in interface Entitypublic boolean isAlive()
Entitypublic boolean isMarkedAsType(java.lang.Class<? extends Entity> type)
EntityisMarkedAsType in interface Entitytype - Entity type to check.public boolean kill()
Entitypublic void killEntities()
EntityContainerkillEntities in interface EntityContainerpublic boolean killEntity(java.util.UUID id)
EntityContainerkillEntity in interface EntityContainerid - Entity ID.protected boolean markAsAlive()
protected boolean markAsDead()
public boolean markAsType(java.lang.Class<? extends Entity> type)
EntitymarkAsType in interface Entitytype - Entity type to add.public SchedulableActionContext<Entity> newContextForActor(Action<Entity> action)
ActionSchedulernewContextForActor in interface ActionScheduler<Entity>action - Action to create context for.public Entity newEntity(java.util.UUID id, AttributeContainer sourceContainer)
EntityContainernewEntity in interface EntityContainerid - Entity ID.sourceContainer - Source attribute container.public <T extends Entity> T newEntity(java.util.UUID id, java.lang.Class<T> type, AttributeContainer sourceContainer)
EntityContainernewEntity in interface EntityContainerid - Entity ID.type - Entity type.sourceContainer - Source attribute container.Entity.markAsType(Class),
Entities.asType(Entity, Class)public boolean receiveEntity(Entity e)
EntityContainerreceiveEntity in interface EntityContainere - Entity to receive.EntityContainer.transferEntity(UUID, EntityContainer)public <T> T removeAttribute(NamedAttributeType<T> namedType)
AttributeContainerremoveAttribute in interface AttributeContainernamedType - Named attribute type to remove.public <T> boolean removeAttributeListener(NamedAttributeType<T> namedType, AttributeListener<T> listener)
AttributeContainerremoveAttributeListener in interface AttributeContainernamedType - Named attribute type.listener - Listener to remove.public void removeAttributeListeners()
AttributeContainerremoveAttributeListeners in interface AttributeContainerpublic <T> void removeAttributeListeners(NamedAttributeType<T> namedType)
AttributeContainerremoveAttributeListeners in interface AttributeContainernamedType - Named attribute type.public void removeAttributes()
AttributeContainerremoveAttributes in interface AttributeContainerpublic boolean removeEntityListener(EntityListener listener)
EntityContainerremoveEntityListener in interface EntityContainerlistener - Listener to remove.true if the listener was removed.ListenerSet.remove(Object)public void removeEntityListeners()
EntityContainerremoveEntityListeners in interface EntityContainerpublic boolean removeEntityTypeListener(EntityTypeListener listener)
EntityremoveEntityTypeListener in interface Entitylistener - Listener to remove.true if the listener was removed.ListenerSet.remove(Object)public void removeEntityTypeListeners()
EntityremoveEntityTypeListeners in interface Entitypublic ActionContext<Entity> scheduleForActor(Action<Entity> action, long initialDelay, long period, java.util.concurrent.TimeUnit unit)
ActionSchedulerscheduleForActor in interface ActionScheduler<Entity>action - Action to schedule.initialDelay - Initial delay before schedule (can be 0).period - Period for repeating (can be 0).unit - Time unit of initial delay and period.public <T> T setAttribute(NamedAttributeType<T> namedType, T attr)
AttributeContainersetAttribute in interface AttributeContainernamedType - Named attribute type.attr - Attribute to add.protected void setContainer(EntityContainer container)
container - New parent container (can be null);protected void setEngine(ActionEngine engine)
engine - Engine to set.public java.util.stream.Stream<?> streamAttributes()
AttributeContainerstreamAttributes in interface AttributeContainerpublic java.util.stream.Stream<Entity> streamEntities()
EntityContainerstreamEntities in interface EntityContainerpublic java.util.stream.Stream<java.lang.Class<? extends Entity>> streamMarkedAsTypes()
EntitystreamMarkedAsTypes in interface Entitypublic java.util.stream.Stream<Tag> streamTags()
TaggablestreamTags in interface Taggablepublic boolean transfer(EntityContainer destination)
Entitypublic boolean transferEntity(java.util.UUID id,
EntityContainer destination)
EntityContainertransferEntity in interface EntityContainerid - Entity ID.destination - Target container.EntityContainer.receiveEntity(Entity)public void unmarkAsAllTypes()
EntityunmarkAsAllTypes in interface Entitypublic boolean unmarkAsType(java.lang.Class<? extends Entity> type)
EntityunmarkAsType in interface Entitytype - Entity type to remove.