public interface EntityContainer
Entity collection. Entities can only be added to a container by creating them
and remove them by killing them. Entity creation and death can be listened for using
EntityListener and EntityEvent.| Modifier and Type | Method and Description |
|---|---|
boolean |
addEntityListener(EntityListener listener)
Adds a listener for entities.
|
default java.util.Set<Entity> |
getEntities()
Gets all the entities within the containers.
|
default <T extends Entity> |
getEntitiesAsType(java.lang.Class<T> type)
Gets all the entities as the specified type.
|
default <T extends Entity> |
getEntitiesOfType(java.lang.Class<T> type)
Gets all the entities marked with the specified type.
|
Entity |
getEntity(java.util.UUID id)
Gets the entity with the specified ID.
|
default <T extends Entity> |
getEntityAsType(java.util.UUID id,
java.lang.Class<T> type)
This is a convenience method for getting an entity (no optional).
|
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.
|
default java.util.Optional<Entity> |
getOptEntity(java.util.UUID id)
This is a convenience method for getting an entity (optional).
|
default <T extends Entity> |
getOptEntityAsType(java.util.UUID id,
java.lang.Class<T> type)
This is a convenience method for getting an entity (optional).The entity is wrapped with the
supplied entity type.
|
default boolean |
hasEntities()
Checks whether the container has any entities.
|
default boolean |
hasEntity(java.util.UUID id)
Checks whether the entity is contained.
|
default boolean |
hasEntityListener(EntityListener listener)
Checks whether the container contains a particular listener.
|
void |
killEntities()
Kills all entities.
|
boolean |
killEntity(java.util.UUID id)
Kills the specified entity.
|
default Entity |
newEntity()
Creates a new entity with a random ID.
|
default Entity |
newEntity(AttributeContainer sourceContainer)
Creates a new entity with a random ID.
|
default <T extends Entity> |
newEntity(java.lang.Class<T> type)
Creates a new entity with a random ID.
|
default <T extends Entity> |
newEntity(java.lang.Class<T> type,
AttributeContainer sourceContainer)
Creates a new entity with a random ID.
|
default Entity |
newEntity(java.util.UUID id)
Creates new entity with the specified ID.
|
Entity |
newEntity(java.util.UUID id,
AttributeContainer sourceContainer)
Creates new entity with the specified ID.
|
default <T extends Entity> |
newEntity(java.util.UUID id,
java.lang.Class<T> type)
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).
|
boolean |
removeEntityListener(EntityListener listener)
Removes a entity listener.
|
void |
removeEntityListeners()
Removes all listeners for entities.
|
java.util.stream.Stream<Entity> |
streamEntities()
Provides a stream of entities from the container.
|
default <T extends Entity> |
streamEntitiesAsType(java.lang.Class<T> type)
Gets a stream of as the specified type.
|
default <T extends Entity> |
streamEntitiesOfType(java.lang.Class<T> type)
Gets a stream of entities marked with the specified type.
|
default java.util.stream.Stream<java.util.UUID> |
streamEntityIDs()
Streams IDs of all the entities within the container.
|
default java.util.Set<java.util.UUID> |
transferAllEntities(EntityContainer destination)
Transfers all entities to the destination.
|
default java.util.Set<java.util.UUID> |
transferEntities(java.util.function.Predicate<Entity> predicate,
EntityContainer destination)
Transfers all entities to the destination.
|
default java.util.Set<java.util.UUID> |
transferEntities(java.util.Set<java.util.UUID> entityIDs,
EntityContainer destination)
Transfers a number of entities
|
boolean |
transferEntity(java.util.UUID id,
EntityContainer destination)
Transfers the entity to the supplied destination container.
|
boolean addEntityListener(EntityListener listener)
listener - Listener to add.true if container did not already contain this listener.java.lang.NullPointerException - if listener is null.ListenerSet.add(Object)default java.util.Set<Entity> getEntities()
streamEntities()default <T extends Entity> java.util.Set<T> getEntitiesAsType(java.lang.Class<T> type)
type - Entity type to check for.streamEntitiesAsType(Class)default <T extends Entity> java.util.Set<T> getEntitiesOfType(java.lang.Class<T> type)
type - Entity type to check for.streamEntitiesOfType(Class)Entity getEntity(java.util.UUID id)
id - Unique ID of the entity.default <T extends Entity> T getEntityAsType(java.util.UUID id, java.lang.Class<T> type)
id - Unique ID of the entity.type - Entity type to wrap to.Entities.asType(Entity, Class)int getEntityCount()
java.util.Set<java.util.UUID> getEntityIDs()
java.util.Set<? extends EntityListener> getEntityListeners()
default java.util.Optional<Entity> getOptEntity(java.util.UUID id)
id - Unique ID of the entity.java.lang.NullPointerException - If the ID is null.default <T extends Entity> java.util.Optional<T> getOptEntityAsType(java.util.UUID id, java.lang.Class<T> type)
id - Unique ID of the entity.type - Entity type to wrap to.java.lang.NullPointerException - If type is null.Entities.asType(Entity, Class)default boolean hasEntities()
default boolean hasEntity(java.util.UUID id)
id - Entity ID.default boolean hasEntityListener(EntityListener listener)
listener - The EntityListener to check for.void killEntities()
boolean killEntity(java.util.UUID id)
id - Entity ID.default Entity newEntity()
java.lang.IllegalStateException - If the entity limit has been reached.UUID.randomUUID()default Entity newEntity(AttributeContainer sourceContainer)
sourceContainer - Source attribute container.java.lang.IllegalStateException - If the entity limit has been reached.UUID.randomUUID()default <T extends Entity> T newEntity(java.lang.Class<T> type)
type - Entity type.java.lang.IllegalStateException - If the entity limit has been reached.UUID.randomUUID(),
Entity.markAsType(Class),
Entities.asType(Entity, Class)default <T extends Entity> T newEntity(java.lang.Class<T> type, AttributeContainer sourceContainer)
type - Entity type.sourceContainer - Source attribute container.java.lang.IllegalStateException - If the entity limit has been reached.UUID.randomUUID(),
Entity.markAsType(Class),
Entities.asType(Entity, Class)default Entity newEntity(java.util.UUID id)
id - Entity ID.java.lang.IllegalStateException - If the entity limit has been reached.java.lang.IllegalArgumentException - If the entity ID is already assigned.Entity newEntity(java.util.UUID id, AttributeContainer sourceContainer)
id - Entity ID.sourceContainer - Source attribute container.java.lang.IllegalStateException - If the entity limit has been reached.java.lang.IllegalArgumentException - If the entity ID is already assigned.default <T extends Entity> T newEntity(java.util.UUID id, java.lang.Class<T> type)
id - Entity ID.type - Entity type.java.lang.IllegalStateException - If the entity limit has been reached.java.lang.IllegalArgumentException - If the entity ID is already assigned.Entity.markAsType(Class),
Entities.asType(Entity, Class)<T extends Entity> T newEntity(java.util.UUID id, java.lang.Class<T> type, AttributeContainer sourceContainer)
id - Entity ID.type - Entity type.sourceContainer - Source attribute container.java.lang.IllegalStateException - If the entity limit has been reached.java.lang.IllegalArgumentException - If the entity ID is already assigned.Entity.markAsType(Class),
Entities.asType(Entity, Class)boolean receiveEntity(Entity e)
e - Entity to receive.transferEntity(UUID, EntityContainer)boolean removeEntityListener(EntityListener listener)
listener - Listener to remove.true if the listener was removed.java.lang.NullPointerException - if listener is null.ListenerSet.remove(Object)void removeEntityListeners()
java.util.stream.Stream<Entity> streamEntities()
default <T extends Entity> java.util.stream.Stream<T> streamEntitiesAsType(java.lang.Class<T> type)
type - Entity type to check for.Entity.asType(Class),
streamEntities()default <T extends Entity> java.util.stream.Stream<T> streamEntitiesOfType(java.lang.Class<T> type)
type - Entity type to check for.Entity.isMarkedAsType(Class),
Entity.asType(Class),
streamEntities()default java.util.stream.Stream<java.util.UUID> streamEntityIDs()
default java.util.Set<java.util.UUID> transferAllEntities(EntityContainer destination)
destination - Destination to transfer to.transferEntities(Set, EntityContainer)default java.util.Set<java.util.UUID> transferEntities(java.util.function.Predicate<Entity> predicate, EntityContainer destination)
predicate - Predicate to filter entities.destination - Destination to transfer to.default java.util.Set<java.util.UUID> transferEntities(java.util.Set<java.util.UUID> entityIDs,
EntityContainer destination)
entityIDs - Entities to transfer.destination - Destination to transfer to.boolean transferEntity(java.util.UUID id,
EntityContainer destination)
id - Entity ID.destination - Target container.receiveEntity(Entity)