AbstractQuery
Results every search has: the first match, how many match, and none.
Abstract classRLPlugins API
public abstract class AbstractQuery<T, Q extends AbstractQuery<T, Q>>Extended by AbstractActorQuery, EntityQuery, InventoryQuery, ItemSpawnQuery, LocationQuery, NoticeBoardAPI.NoticeBoardQuery, SafespotQuery, ShopQuery, TileItemQuery, TileObjectQuery, WidgetQuery, WorldQuery
T is the result type and Q the query type.
Members
Constructors
- newAbstractQuery(List<T>)
Creates a AbstractQuery.
Methods
- Raggregate(Function<Stream<T>, R>)
Generic aggregation method for custom terminal operations Executes filters and allows custom stream processing.
- booleanall(Predicate<T>)
Check if all filtered results match the predicate.
- booleanany(Predicate<T>)
Check if any filtered result matches the predicate.
- List<T>collect()
Get the filtered/sorted list.
- Rcollect(Collector<T, ?, R>)
Execute filters and process with custom collector.
- intcount()
How many results match.
- Qdistinct()
Ensure results are distinct.
- Tfirst()
The first match.
- voidfirstIfPresent(Consumer<T>)
First if present.
- voidfirstOrElse(Consumer<T>, Runnable)
Perform action on the first element, or else run elseAction if no results.
- voidforEach(Consumer<T>)
Executes filters and performs an action on each result.
- booleanisEmpty()
Whether nothing matches.
- QkeepIf(Predicate<T>)
Lazily filter by predicate (keeps matching items).
- Tlast()
Get the last element from the filtered/sorted list.
- voidlastOrElse(Consumer<T>, Runnable)
Perform action on the last element, or else run elseAction if no results.
- Qlimit(int)
Limit the number of results.
- booleannone(Predicate<T>)
Check if no filtered results match the predicate.
- Qpeek(Consumer<T>)
Peek at each element during processing.
- QpostProcess(Function<List<T>, List<T>>)
Apply a post-processing function after sorting.
- Trandom()
Get a random element from the filtered/sorted list.
- QremoveIf(Predicate<T>)
Lazily filter by predicate (removes matching items).
- Qskip(int)
Skip a number of results.
- Qsort(Comparator<T>)
Lazily add sorting.
AbstractQuery(List<T>)
public AbstractQuery(List<T> cache)Creates a AbstractQuery.
Parameters
cache- Cache.
aggregate(Function<Stream<T>, R>)
public R aggregate(Function<Stream<T>, R> aggregator)Generic aggregation method for custom terminal operations Executes filters and allows custom stream processing.
Parameters
aggregator- Aggregator.
all(Predicate<T>)
public boolean all(Predicate<T> predicate)Check if all filtered results match the predicate.
Parameters
predicate- Predicate to test.
Returns
True if all match, false otherwise.
any(Predicate<T>)
public boolean any(Predicate<T> predicate)Check if any filtered result matches the predicate.
Parameters
predicate- Predicate to test.
Returns
True if any match, false otherwise.
collect()
public List<T> collect()Get the filtered/sorted list.
collect(Collector<T, ?, R>)
public R collect(Collector<T, ?, R> collector)Execute filters and process with custom collector.
Parameters
collector- Collector.
count()
public int count()How many results match.
Returns
The number of matches.
distinct()
public Q distinct()Ensure results are distinct.
Returns
The query instance.
first()
public T first()The first match.
The order is the game's own. Use AbstractActorQuery.nearest() for the closest one.
Returns
The first match, or null when nothing matches.
firstIfPresent(Consumer<T>)
public void firstIfPresent(Consumer<T> action)First if present.
Parameters
action- Action.
firstOrElse(Consumer<T>, Runnable)
public void firstOrElse(Consumer<T> action, Runnable elseAction)Perform action on the first element, or else run elseAction if no results.
Parameters
action- Action to perform on the first element.
elseAction- Action to perform if no results.
forEach(Consumer<T>)
public void forEach(Consumer<T> action)Executes filters and performs an action on each result.
Parameters
action- Action.
isEmpty()
public boolean isEmpty()Whether nothing matches.
Returns
true when there are no matches.
keepIf(Predicate<T>)
public Q keepIf(Predicate<T> predicate)Lazily filter by predicate (keeps matching items).
Parameters
predicate- Predicate.
Returns
The query instance.
last()
public T last()Get the last element from the filtered/sorted list.
lastOrElse(Consumer<T>, Runnable)
public void lastOrElse(Consumer<T> action, Runnable elseAction)Perform action on the last element, or else run elseAction if no results.
Parameters
action- Action to perform on the last element.
elseAction- Action to perform if no results.
limit(int)
public Q limit(int maxSize)Limit the number of results.
Parameters
maxSize- Max size.
Returns
The query instance.
none(Predicate<T>)
public boolean none(Predicate<T> predicate)Check if no filtered results match the predicate.
Parameters
predicate- Predicate to test.
Returns
True if none match, false otherwise.
peek(Consumer<T>)
public Q peek(Consumer<T> action)Peek at each element during processing.
Parameters
action- Action to perform on each element.
Returns
The query instance.
postProcess(Function<List<T>, List<T>>)
public Q postProcess(Function<List<T>, List<T>> processor)Apply a post-processing function after sorting.
Useful for reordering algorithms that can't be expressed as Comparators.
Parameters
processor- Function to transform the result list.
Returns
The query instance.
random()
public T random()Get a random element from the filtered/sorted list.
removeIf(Predicate<T>)
public Q removeIf(Predicate<T> predicate)Lazily filter by predicate (removes matching items).
Parameters
predicate- Predicate.
Returns
The query instance.
skip(int)
public Q skip(int count)Skip a number of results.
Parameters
count- Count.
Returns
The query instance.
sort(Comparator<T>)
public Q sort(Comparator<T> comparator)Lazily add sorting.
Parameters
comparator- Comparator.
Returns
The query instance.
Also allowed
Every class has these, as in plain Java.
equals, toString