Class Query<T,Q,R>
- Type Parameters:
T- the type of entity being queriedQ- the concrete query type (for method chaining)R- the result type returned by the query
- All Implemented Interfaces:
Predicate<T>
- Direct Known Subclasses:
ItemQuery,SceneEntityQuery,WidgetQuery
This class provides a foundation for implementing the builder pattern to construct queries with chainable filter methods. Subclasses define specific filter criteria for different entity types (NPCs, players, items, widgets, etc.).
The query system uses lazy evaluation - filters are accumulated and only applied
when results() is called to retrieve the matching entities.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAdds a custom filter predicate to the query.results()Executes the query and returns the results.protected abstract RWraps the filtered list of entities in the appropriate result container.protected Qself()Returns this query instance cast to the concrete query type.booleanTests whether an entity passes all accumulated filter criteria.
-
Field Details
-
supplier
The supplier that provides the initial collection of entities to query.
-
-
Constructor Details
-
Query
Constructs a new query with the specified entity supplier.- Parameters:
supplier- a supplier that provides the list of entities to query against
-
-
Method Details
-
results
Executes the query and returns the results.This method retrieves entities from the supplier, applies all accumulated filters, and wraps the matching entities in a result container.
- Returns:
- the query results containing all entities that match the filter criteria
-
filter
Adds a custom filter predicate to the query.Multiple filters can be added and will be combined using logical AND. This method supports method chaining for fluent query construction.
- Parameters:
filter- the predicate to filter entities by- Returns:
- this query instance for method chaining
-
test
Tests whether an entity passes all accumulated filter criteria.This method is called for each entity during query execution to determine if it should be included in the results.
-
results
Wraps the filtered list of entities in the appropriate result container.Subclasses must implement this method to return the correct result type.
- Parameters:
list- the list of entities that passed all filters- Returns:
- the results wrapped in the appropriate container type
-
self
Returns this query instance cast to the concrete query type.This method enables method chaining in subclasses by returning the properly typed query instance.
- Returns:
- this query instance as the concrete type Q
-