public final class Entities
extends java.lang.Object
Entity
related functionality (specifically around entity types).asType(Entity, Class)
) to
another entity type even if it does not have the defining data. This does not set the entity as
this type but entities can be marked as a type manually for easy filtering/processing (
Entity.markAsType(Class)
). When creating an entity and supplying an entity type (like
EntityContainer.newEntity(Class)
) this automatically marks the entity as the supplied
type - in fact all of the types in the entity type inheritance tree are added too (removable). An
entity can be marked as multiple entity types so filtering this way can become very useful for
processing similar entities. Modifier and Type | Field and Description |
---|---|
static EntityContainer |
EMPTY_ENTITYCONTAINER
An empty EntityContainer.
|
static EntityFactory |
EMPTY_ENTITYFACTORY
An empty EntityFactory.
|
Modifier and Type | Method and Description |
---|---|
static java.util.Optional<Entity> |
anyEntity(EntityContainer container)
Gets any entity within the container.
|
static <T extends Entity> |
anyEntityOfType(EntityContainer container,
java.lang.Class<T> type)
Gets any entity within the container marked with the specified type.
|
static <T extends Entity> |
asType(Entity entity,
java.lang.Class<T> type)
Wraps an Entity as the supplied Entity type.
|
static EntityContainer |
emptyEntityContainer()
Creates an immutable empty entity container.
|
static EntityFactory |
emptyEntityFactory()
Creates an immutable empty entity factory.
|
static boolean |
findEntityRecursively(EntityContainer container,
java.util.UUID id)
Walks through the entity tree looking for an entity.
|
static int |
getEntityCountRecursively(EntityContainer container)
Gets the total entity count (recursive).
|
static java.util.Set<java.util.UUID> |
getEntityIDsRecursively(EntityContainer container)
Gets the IDs of all the entities (recursive).
|
static EntityContainer |
getHighestParent(EntityContainer container)
Gets the highest level parent of this container.
|
static EntityProxyFactory |
getProxyFactory() |
static java.util.Set<java.lang.Class<? extends Entity>> |
getTypeAncestry(java.lang.Class<? extends Entity> type)
Gets all ancestors for the specified descendant type (not including
Entity ). |
static boolean |
isEntityOrSubtype(java.lang.Class<?> type)
Checks whether the type is an entity subtype.
|
static boolean |
isEntitySubtype(java.lang.Class<?> type)
Checks whether the type is an entity subtype.
|
static java.util.function.Predicate<Entity> |
isMarkedAsType(java.lang.Class<? extends Entity> type)
Checks to see if the entity has been tagged with the type.
|
static boolean |
isOrSubtype(java.lang.Class<? extends Entity> descendant,
java.lang.Class<? extends Entity> ancestor)
Checks if the specified type is equal to or a descendant from the specified ancestor type.
|
static boolean |
isSubtype(java.lang.Class<? extends Entity> descendant,
java.lang.Class<? extends Entity> ancestor)
Checks if the specified type is a descendant from the specified ancestor type.
|
static java.util.function.Predicate<Entity> |
notMarkedAsType(java.lang.Class<? extends Entity> type)
Checks to see if the entity has not been tagged with the type.
|
static java.util.Optional<Entity> |
randomEntity(EntityContainer container)
Gets a random entity from the container (if there is one).
|
static void |
setProxyFactory(EntityProxyFactory newFactory) |
static EntityContainer |
unmodifiableEntityContainer(EntityContainer container)
Creates an immutable read-only delegate entity container for the supplied container.
|
static EntityFactory |
unmodifiableEntityFactory(EntityFactory factory)
Creates an immutable read-only delegate entity factory for the supplied factory.
|
static void |
validateType(java.lang.Class<? extends Entity> type)
Validates the entity type.
|
static java.util.stream.Stream<Entity> |
walkEntities(EntityContainer container)
A lazy-walked stream of entities (recursive and breadth-first).
|
static java.util.stream.Stream<Entity> |
walkEntities(EntityContainer container,
int maxDepth)
A lazy-walked stream of entities (recursive and breadth-first).
|
static void |
walkEntityTree(EntityContainer container,
EntityVisitor visitor)
Walks through all entities (recursive and breadth-first).
|
static void |
walkEntityTree(EntityContainer container,
int maxDepth,
EntityVisitor visitor)
Walks through all entities (recursive and breadth-first).
|
static boolean |
withinSameTree(EntityContainer one,
EntityContainer two)
Checks to see if an container is in the same tree as the other container (checking highest
parent container).
|
public static EntityContainer EMPTY_ENTITYCONTAINER
public static EntityFactory EMPTY_ENTITYFACTORY
public static java.util.Optional<Entity> anyEntity(EntityContainer container)
container
- Entity container.public static <T extends Entity> java.util.Optional<T> anyEntityOfType(EntityContainer container, java.lang.Class<T> type)
container
- Entity container.type
- Entity type.Entity.markAsType(Class)
public static <T extends Entity> T asType(Entity entity, java.lang.Class<T> type)
EntityProxyFactory.proxyOfEntity(Entity, Class)
.entity
- Entity to wrap.type
- Entity type to wrap to.getProxyFactory()
public static EntityContainer emptyEntityContainer()
public static EntityFactory emptyEntityFactory()
public static boolean findEntityRecursively(EntityContainer container, java.util.UUID id)
container
- Entity container.id
- Entity ID to look for.walkEntityTree(EntityContainer, EntityVisitor)
public static int getEntityCountRecursively(EntityContainer container)
container
- Entity container.walkEntityTree(EntityContainer, EntityVisitor)
public static java.util.Set<java.util.UUID> getEntityIDsRecursively(EntityContainer container)
container
- Entity container.walkEntityTree(EntityContainer, EntityVisitor)
public static EntityContainer getHighestParent(EntityContainer container)
container
- Container to get parent for.public static EntityProxyFactory getProxyFactory()
public static java.util.Set<java.lang.Class<? extends Entity>> getTypeAncestry(java.lang.Class<? extends Entity> type)
Entity
).type
- Descendant type.Entity
.java.lang.IllegalArgumentException
- If the Entity type is invalidvalidateType(Class)
public static boolean isEntityOrSubtype(java.lang.Class<?> type)
type
- Type to check.public static boolean isEntitySubtype(java.lang.Class<?> type)
type
- Type to check.public static java.util.function.Predicate<Entity> isMarkedAsType(java.lang.Class<? extends Entity> type)
type
- Entity type to check for.true
if the entity is of the type or false
if it is not.public static boolean isOrSubtype(java.lang.Class<? extends Entity> descendant, java.lang.Class<? extends Entity> ancestor)
descendant
- Descendant type.ancestor
- Ancestor type.public static boolean isSubtype(java.lang.Class<? extends Entity> descendant, java.lang.Class<? extends Entity> ancestor)
descendant
- Descendant type.ancestor
- Ancestor type.public static java.util.function.Predicate<Entity> notMarkedAsType(java.lang.Class<? extends Entity> type)
type
- Entity type to check for.true
if the entity is not of the type or false
if it is.public static java.util.Optional<Entity> randomEntity(EntityContainer container)
container
- Source container.public static void setProxyFactory(EntityProxyFactory newFactory)
public static EntityContainer unmodifiableEntityContainer(EntityContainer container)
container
- Container to delegate for.public static EntityFactory unmodifiableEntityFactory(EntityFactory factory)
factory
- Factory to delegate for.public static void validateType(java.lang.Class<? extends Entity> type)
EntityProxyFactory.validateType(Class)
.type
- Type to validate.getProxyFactory()
public static java.util.stream.Stream<Entity> walkEntities(EntityContainer container)
walkEntities(container, Integer.MAX_VALUE)
container
- Entity container.public static java.util.stream.Stream<Entity> walkEntities(EntityContainer container, int maxDepth)
container
- Entity container.maxDepth
- Maximum depth of the walk.public static void walkEntityTree(EntityContainer container, EntityVisitor visitor)
walkEntityTree(container, Integer.MAX_VALUE, visitor)
container
- Entity container.visitor
- Entity visitor.EntityVisitor
public static void walkEntityTree(EntityContainer container, int maxDepth, EntityVisitor visitor)
container
- Entity container.maxDepth
- Maximum depth of the walk.visitor
- Entity visitor.EntityVisitor
public static boolean withinSameTree(EntityContainer one, EntityContainer two)
one
- Container to check.two
- Container to check.getHighestParent(EntityContainer)