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, toString
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
asType, getMarkedAsTypes, getOptContainer, hasContainer, hasEntityTypeListener
getEntities, getEntitiesAsType, getEntitiesOfType, getEntityAsType, getOptEntity, getOptEntityAsType, hasEntities, hasEntity, hasEntityListener, newEntity, newEntity, newEntity, newEntity, newEntity, newEntity, streamEntitiesAsType, streamEntitiesOfType, streamEntityIDs, transferAllEntities, transferEntities, transferEntities
equals, getID, getID, hashCode, is, not, toString
addAll, 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, setOptAttribute
scheduleForActor, scheduleForActor
protected 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)
AttributeContainer
addAttributeListener
in interface AttributeContainer
namedType
- Named attribute type.listener
- Listener to add.public boolean addEntityListener(EntityListener listener)
EntityContainer
addEntityListener
in interface EntityContainer
listener
- Listener to add.true
if container did not already contain this listener.ListenerSet.add(Object)
public boolean addEntityTypeListener(EntityTypeListener listener)
Entity
addEntityTypeListener
in interface Entity
listener
- Listener to add.true
if container did not already contain this listener.ListenerSet.add(Object)
public void cancelAllScheduledForActor()
ActionScheduler
cancelAllScheduledForActor
in interface ActionScheduler<Entity>
public <T> void fireAttributeChanged(NamedAttributeType<T> namedType)
AttributeContainer
fireAttributeChanged
in interface AttributeContainer
namedType
- Named attribute type name.public <T> T getAttribute(NamedAttributeType<T> namedType)
AttributeContainer
getAttribute
in interface AttributeContainer
namedType
- Named attribute type to check for.public int getAttributeCount()
AttributeContainer
getAttributeCount
in interface AttributeContainer
public <T> java.util.Set<? extends AttributeListener<T>> getAttributeListeners(NamedAttributeType<T> namedType)
AttributeContainer
getAttributeListeners
in interface AttributeContainer
namedType
- Named attribute type to check for.public java.util.Set<NamedAttributeType<?>> getAttributeListenerTypes()
AttributeContainer
getAttributeListenerTypes
in interface AttributeContainer
public java.util.Set<NamedAttributeType<?>> getAttributeTypes()
AttributeContainer
getAttributeTypes
in interface AttributeContainer
public EntityContainer getContainer()
Entity
getContainer
in interface Entity
protected ActionEngine getEngine()
public Entity getEntity(java.util.UUID id)
EntityContainer
getEntity
in interface EntityContainer
id
- Unique ID of the entity.public int getEntityCount()
EntityContainer
getEntityCount
in interface EntityContainer
public java.util.Set<java.util.UUID> getEntityIDs()
EntityContainer
getEntityIDs
in interface EntityContainer
public java.util.Set<? extends EntityListener> getEntityListeners()
EntityContainer
getEntityListeners
in interface EntityContainer
public java.util.Set<? extends EntityTypeListener> getEntityTypeListeners()
Entity
getEntityTypeListeners
in interface Entity
public boolean isAlive()
Entity
public boolean isMarkedAsType(java.lang.Class<? extends Entity> type)
Entity
isMarkedAsType
in interface Entity
type
- Entity type to check.public boolean kill()
Entity
public void killEntities()
EntityContainer
killEntities
in interface EntityContainer
public boolean killEntity(java.util.UUID id)
EntityContainer
killEntity
in interface EntityContainer
id
- Entity ID.protected boolean markAsAlive()
protected boolean markAsDead()
public boolean markAsType(java.lang.Class<? extends Entity> type)
Entity
markAsType
in interface Entity
type
- Entity type to add.public SchedulableActionContext<Entity> newContextForActor(Action<Entity> action)
ActionScheduler
newContextForActor
in interface ActionScheduler<Entity>
action
- Action to create context for.public Entity newEntity(java.util.UUID id, AttributeContainer sourceContainer)
EntityContainer
newEntity
in interface EntityContainer
id
- Entity ID.sourceContainer
- Source attribute container.public <T extends Entity> T newEntity(java.util.UUID id, java.lang.Class<T> type, AttributeContainer sourceContainer)
EntityContainer
newEntity
in interface EntityContainer
id
- Entity ID.type
- Entity type.sourceContainer
- Source attribute container.Entity.markAsType(Class)
,
Entities.asType(Entity, Class)
public boolean receiveEntity(Entity e)
EntityContainer
receiveEntity
in interface EntityContainer
e
- Entity to receive.EntityContainer.transferEntity(UUID, EntityContainer)
public <T> T removeAttribute(NamedAttributeType<T> namedType)
AttributeContainer
removeAttribute
in interface AttributeContainer
namedType
- Named attribute type to remove.public <T> boolean removeAttributeListener(NamedAttributeType<T> namedType, AttributeListener<T> listener)
AttributeContainer
removeAttributeListener
in interface AttributeContainer
namedType
- Named attribute type.listener
- Listener to remove.public void removeAttributeListeners()
AttributeContainer
removeAttributeListeners
in interface AttributeContainer
public <T> void removeAttributeListeners(NamedAttributeType<T> namedType)
AttributeContainer
removeAttributeListeners
in interface AttributeContainer
namedType
- Named attribute type.public void removeAttributes()
AttributeContainer
removeAttributes
in interface AttributeContainer
public boolean removeEntityListener(EntityListener listener)
EntityContainer
removeEntityListener
in interface EntityContainer
listener
- Listener to remove.true
if the listener was removed.ListenerSet.remove(Object)
public void removeEntityListeners()
EntityContainer
removeEntityListeners
in interface EntityContainer
public boolean removeEntityTypeListener(EntityTypeListener listener)
Entity
removeEntityTypeListener
in interface Entity
listener
- Listener to remove.true
if the listener was removed.ListenerSet.remove(Object)
public void removeEntityTypeListeners()
Entity
removeEntityTypeListeners
in interface Entity
public ActionContext<Entity> scheduleForActor(Action<Entity> action, long initialDelay, long period, java.util.concurrent.TimeUnit unit)
ActionScheduler
scheduleForActor
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)
AttributeContainer
setAttribute
in interface AttributeContainer
namedType
- 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()
AttributeContainer
streamAttributes
in interface AttributeContainer
public java.util.stream.Stream<Entity> streamEntities()
EntityContainer
streamEntities
in interface EntityContainer
public java.util.stream.Stream<java.lang.Class<? extends Entity>> streamMarkedAsTypes()
Entity
streamMarkedAsTypes
in interface Entity
public java.util.stream.Stream<Tag> streamTags()
Taggable
streamTags
in interface Taggable
public boolean transfer(EntityContainer destination)
Entity
public boolean transferEntity(java.util.UUID id, EntityContainer destination)
EntityContainer
transferEntity
in interface EntityContainer
id
- Entity ID.destination
- Target container.EntityContainer.receiveEntity(Entity)
public void unmarkAsAllTypes()
Entity
unmarkAsAllTypes
in interface Entity
public boolean unmarkAsType(java.lang.Class<? extends Entity> type)
Entity
unmarkAsType
in interface Entity
type
- Entity type to remove.