Package net.storm.api.query.results
Class QueryResults<T,R>
java.lang.Object
net.storm.api.query.results.QueryResults<T,R>
- Type Parameters:
T- the type of elements in the resultsR- the concrete result type (for method chaining)
- All Implemented Interfaces:
Iterable<T>,Collection<T>
- Direct Known Subclasses:
ItemQueryResults,SceneEntityQueryResults,WidgetQueryResults
Abstract base class for query result containers.
This class wraps a list of query results and provides various utility methods for
accessing, manipulating, and iterating over the results. It implements the Collection
interface to allow standard collection operations.
The class supports method chaining for fluent result manipulation, including sorting, limiting, reversing, and shuffling results.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionQueryResults(List<T> results) Constructs a new QueryResults wrapper around the specified list. -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanApplies a consumer to a targeted element from the results if it exists.booleanAdds an element to the results.booleanaddAll(Collection<? extends T> c) Adds all elements from the specified collection to the results.voidclear()Removes all elements from the results.booleanReturnstrueif the results contain the specified element.booleancontainsAll(Collection<?> c) Returnstrueif the results contain all elements in the specified collection.first()Returns the first element in the results, ornullif empty.get(int index) Returns the element at the specified position in the results.intReturns the index of the first occurrence of the specified element.booleanisEmpty()Returnstrueif this result set contains no elements.booleanReturnstrueif this result set contains at least one element.iterator()Returns an iterator over the elements in the results.final Tlast()Returns the last element in the results, ornullif empty.intlastIndexOf(T o) Returns the index of the last occurrence of the specified element.final Rlimit(int entries) Limits the results to the specified number of elements from the beginning.final Rlimit(int startIndex, int amount) Limits the results to a specified number of elements starting from a given index.list()Returns the underlying list of results.final Trandom()Returns a random element from the results, ornullif empty.booleanRemoves a single instance of the specified element from the results.booleanremoveAll(Collection<?> c) Removes all elements from the results that are contained in the specified collection.booleanretainAll(Collection<?> c) Retains only the elements in the results that are contained in the specified collection.final Rreversed()Reverses the order of elements in the results.final Rshuffled()Randomly shuffles the order of elements in the results.intsize()Returns the number of elements in the results.final Rsorted(Comparator<? super T> comparator) Sorts the results using the specified comparator.Object[]toArray()Returns an array containing all elements in the results.T[]Returns an array containing all elements in the results.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Collection
equals, hashCode, parallelStream, removeIf, spliterator, stream, toArray
-
Field Details
-
results
The underlying list of query results.
-
-
Constructor Details
-
QueryResults
Constructs a new QueryResults wrapper around the specified list.- Parameters:
results- the list of query results to wrap
-
-
Method Details
-
get
Returns the element at the specified position in the results.- Parameters:
index- the index of the element to return- Returns:
- the element at the specified position
- Throws:
IndexOutOfBoundsException- if the index is out of range
-
isEmpty
public boolean isEmpty()Returnstrueif this result set contains no elements.- Specified by:
isEmptyin interfaceCollection<T>- Returns:
trueif the results are empty,falseotherwise
-
isNotEmpty
public boolean isNotEmpty()Returnstrueif this result set contains at least one element.- Returns:
trueif the results are not empty,falseotherwise
-
sorted
Sorts the results using the specified comparator.This method modifies the underlying list in place.
- Parameters:
comparator- the comparator to determine the order of results- Returns:
- this result instance for method chaining
-
lastIndexOf
Returns the index of the last occurrence of the specified element.- Parameters:
o- the element to search for- Returns:
- the index of the last occurrence, or -1 if not found
-
addAll
Adds all elements from the specified collection to the results.- Specified by:
addAllin interfaceCollection<T>- Parameters:
c- the collection containing elements to add- Returns:
trueif the results changed as a result of the call
-
limit
Limits the results to a specified number of elements starting from a given index.Elements outside the specified range are removed from the results.
- Parameters:
startIndex- the index to start from (inclusive)amount- the maximum number of elements to retain- Returns:
- this result instance for method chaining
-
list
Returns the underlying list of results.- Returns:
- the list containing all results
-
clear
public void clear()Removes all elements from the results.- Specified by:
clearin interfaceCollection<T>
-
size
public int size()Returns the number of elements in the results.- Specified by:
sizein interfaceCollection<T>- Returns:
- the number of elements
-
removeAll
Removes all elements from the results that are contained in the specified collection.- Specified by:
removeAllin interfaceCollection<T>- Parameters:
c- the collection containing elements to remove- Returns:
trueif the results changed as a result of the call
-
remove
Removes a single instance of the specified element from the results.- Specified by:
removein interfaceCollection<T>- Parameters:
o- the element to remove- Returns:
trueif an element was removed
-
add
Adds an element to the results.- Specified by:
addin interfaceCollection<T>- Parameters:
t- the element to add- Returns:
trueif the element was added successfully
-
reversed
Reverses the order of elements in the results.- Returns:
- this result instance for method chaining
-
first
Returns the first element in the results, ornullif empty.- Returns:
- the first element, or
nullif no elements exist
-
indexOf
Returns the index of the first occurrence of the specified element.- Parameters:
o- the element to search for- Returns:
- the index of the first occurrence, or -1 if not found
-
accept
Applies a consumer to a targeted element from the results if it exists.This method allows for conditional execution of an action on a specific element extracted from the results using a target function.
- Parameters:
consumer- the consumer to apply to the targeted elementtarget- the function to extract the target element from results- Returns:
trueif the target element was found and the consumer was applied
-
random
Returns a random element from the results, ornullif empty.- Returns:
- a randomly selected element, or
nullif no elements exist
-
contains
Returnstrueif the results contain the specified element.- Specified by:
containsin interfaceCollection<T>- Parameters:
o- the element to check for- Returns:
trueif the element is present
-
shuffled
Randomly shuffles the order of elements in the results.- Returns:
- this result instance for method chaining
-
containsAll
Returnstrueif the results contain all elements in the specified collection.- Specified by:
containsAllin interfaceCollection<T>- Parameters:
c- the collection to check- Returns:
trueif all elements are present
-
iterator
Returns an iterator over the elements in the results. -
limit
Limits the results to the specified number of elements from the beginning.Elements beyond the specified limit are removed from the results.
- Parameters:
entries- the maximum number of elements to retain- Returns:
- this result instance for method chaining
-
last
Returns the last element in the results, ornullif empty.- Returns:
- the last element, or
nullif no elements exist
-
toArray
Returns an array containing all elements in the results.- Specified by:
toArrayin interfaceCollection<T>- Returns:
- an array containing all elements
-
toArray
Returns an array containing all elements in the results.- Specified by:
toArrayin interfaceCollection<T>- Parameters:
o- the array into which elements are to be stored- Returns:
- an array containing all elements
-
retainAll
Retains only the elements in the results that are contained in the specified collection.- Specified by:
retainAllin interfaceCollection<T>- Parameters:
c- the collection containing elements to retain- Returns:
trueif the results changed as a result of the call
-