Class Query<T,Q,R>

java.lang.Object
net.storm.api.query.Query<T,Q,R>
Type Parameters:
T - the type of entity being queried
Q - 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

public abstract class Query<T,Q,R> extends Object implements Predicate<T>
Abstract base class for building fluent queries against collections of game entities.

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
    Modifier and Type
    Field
    Description
    protected final Supplier<List<T>>
    The supplier that provides the initial collection of entities to query.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Query(Supplier<List<T>> supplier)
    Constructs a new query with the specified entity supplier.
  • Method Summary

    Modifier and Type
    Method
    Description
    filter(Predicate<T> filter)
    Adds a custom filter predicate to the query.
    Executes the query and returns the results.
    protected abstract R
    results(List<T> list)
    Wraps the filtered list of entities in the appropriate result container.
    protected Q
    Returns this query instance cast to the concrete query type.
    boolean
    test(T t)
    Tests whether an entity passes all accumulated filter criteria.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface java.util.function.Predicate

    and, negate, or
  • Field Details

    • supplier

      protected final Supplier<List<T>> supplier
      The supplier that provides the initial collection of entities to query.
  • Constructor Details

    • Query

      protected Query(Supplier<List<T>> supplier)
      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

      public R 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

      public Q filter(Predicate<T> 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

      public boolean test(T t)
      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.

      Specified by:
      test in interface Predicate<T>
      Parameters:
      t - the entity to test
      Returns:
      true if the entity passes all filters, false otherwise
    • results

      protected abstract R results(List<T> list)
      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

      protected Q 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