Class EntityQuery<T>
- Type Parameters:
T- The type of value selected by this query.
public final class EntityQuery<T>
A reusable, fluent query for selecting entities without game-specific collection boilerplate.
Filters are cumulative. Calling sorted(Comparator) or nearestTo(Point2D) replaces any
previously selected ordering. Terminal operations evaluate the current contents of the source
collection; list() returns an unmodifiable snapshot.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionalive()Excludes dead combat entities while retaining values that are not combat entities.longcount()Counts matching values without applying the configured ordering.dead()Keeps only dead combat entities.enemyOf(ICombatEntity entity) Keeps combat entities whose team differs from the reference entity's team.first()Finds the first matching value in configured or source order.static <T> EntityQuery<T> in(Environment environment, Class<? extends T> type) Creates a query over all entities of a type in an environment.booleanisEmpty()Tests whether this query has no matching values.list()Evaluates this query and returns its matching values.Adds a predicate to the filters already configured on this query.Keeps entities whose name equals the specified name.Orders entities by increasing distance from a point.sorted(Comparator<T> order) Replaces the current ordering with a comparator.Keeps entities that have the specified tag.team(int team) Keeps only combat entities assigned to a team.Keeps entities whose center is at most the specified distance from a point.
-
Constructor Details
-
EntityQuery
Creates a query over a collection.- Parameters:
source- The live source collection, ornullfor an empty query.
-
-
Method Details
-
matching
Adds a predicate to the filters already configured on this query.- Parameters:
filter- The predicate to add.- Returns:
- This query.
- Throws:
NullPointerException- iffilterisnull.
-
tagged
Keeps entities that have the specified tag.- Parameters:
tag- The tag to match.- Returns:
- This query.
-
named
Keeps entities whose name equals the specified name.- Parameters:
name- The name to match; may benull.- Returns:
- This query.
-
alive
Excludes dead combat entities while retaining values that are not combat entities.- Returns:
- This query.
-
dead
-
team
Keeps only combat entities assigned to a team.- Parameters:
team- The team identifier to match.- Returns:
- This query.
-
enemyOf
Keeps combat entities whose team differs from the reference entity's team.- Parameters:
entity- The entity whose team is considered friendly.- Returns:
- This query.
- Throws:
NullPointerException- ifentityisnull.
-
within
Keeps entities whose center is at most the specified distance from a point.- Parameters:
point- The center of the search area in map coordinates.distance- The inclusive maximum distance in map units.- Returns:
- This query.
- Throws:
NullPointerException- ifpointisnull.IllegalArgumentException- ifdistanceis negative.
-
nearestTo
Orders entities by increasing distance from a point.
Values that are not entities sort after all entities.
- Parameters:
point- The reference point in map coordinates.- Returns:
- This query.
- Throws:
NullPointerException- ifpointisnull.
-
sorted
Replaces the current ordering with a comparator.- Parameters:
order- The comparator to use.- Returns:
- This query.
- Throws:
NullPointerException- iforderisnull.
-
list
-
first
-
count
public long count()Counts matching values without applying the configured ordering.- Returns:
- The number of matching values.
-
isEmpty
public boolean isEmpty()Tests whether this query has no matching values.- Returns:
truewhen no value matches.
-
in
Creates a query over all entities of a type in an environment.- Type Parameters:
T- The requested entity type.- Parameters:
environment- The environment to query.type- The requested entity type.- Returns:
- A query over the environment's matching entities.
- Throws:
NullPointerException- ifenvironmentortypeisnull.
-