Package org.xmpp.resultsetmanagement
Class ResultSetImpl<E extends Result>
java.lang.Object
java.util.AbstractCollection<E>
org.xmpp.resultsetmanagement.ResultSet<E>
org.xmpp.resultsetmanagement.ResultSetImpl<E>
- Type Parameters:
E- Each result set should be a collection of instances of the exact same class. This class must implement theResultinterface.
- All Implemented Interfaces:
Iterable<E>,Collection<E>
A result set representation as described in XEP-0059. Note that this result
'set' actually makes use of a List implementations, as the Java Set
definition disallows duplicate elements, while the List definition supplies
most of the required indexing operations.
This ResultSet implementation loads all all results from the set into memory,
which might be undesirable for very large sets, or for sets where the
retrieval of a result is an expensive operation. sets.
As most methods are backed by the
List.subList(int, int) method,
non-structural changes in the returned lists are reflected in the ResultSet,
and vice-versa.- Author:
- Guus der Kinderen, guus.der.kinderen@gmail.com
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionA list of all results in this ResultSetA mapping of the UIDs of all results in resultList, to the index of those entries in that list.Fields inherited from class org.xmpp.resultsetmanagement.ResultSet
NAMESPACE_RESULT_SET_MANAGEMENT -
Constructor Summary
ConstructorsConstructorDescriptionResultSetImpl(Collection<E> results) Creates a new Result Set instance, based on a collection of Result implementing objects.ResultSetImpl(Collection<E> results, Comparator<E> comparator) Creates a new Result Set instance, based on a collection of Result implementing objects. -
Method Summary
Modifier and TypeMethodDescriptionget(int index) Returns the element denoted by the index.get(int fromIndex, int maxAmount) Returns a list of results, starting with the result that's at the specified index.Returns a List of results starting with the first result after the result that's identified by the provided UID (the returned List is exclusive).Returns a list of results ending with the element right before the element identified by the provided UID (the returned List is exclusive).getFirst(int maxAmount) Returns the first elements from this result set.getLast(int maxAmount) Returns the last elements from this result set.intReturns the index in the full resultset of the element identified by the UID in te supplied argument.intsize()Methods inherited from class org.xmpp.resultsetmanagement.ResultSet
applyRSMDirectives, generateSetElementFromResults, getAfter, getBefore, getUID, indexOf, isValidRSMRequest, iteratorMethods inherited from class java.util.AbstractCollection
add, addAll, clear, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
equals, hashCode, parallelStream, removeIf, spliterator, stream, toArray
-
Field Details
-
resultList
A list of all results in this ResultSet -
uidToIndex
A mapping of the UIDs of all results in resultList, to the index of those entries in that list.
-
-
Constructor Details
-
ResultSetImpl
Creates a new Result Set instance, based on a collection of Result implementing objects. The collection should contain elements of the exact same class only, and cannot contain 'null' elements. The order that's being used in the new ResultSet instance is the same order in whichCollection.iterator()iterates over the collection. Note that this constructor throws an IllegalArgumentException if the Collection that is provided contains Results that have duplicate UIDs.- Parameters:
results- The collection of Results that make up this result set.
-
ResultSetImpl
Creates a new Result Set instance, based on a collection of Result implementing objects. The collection should contain elements of the exact same class only, and cannot contain 'null' elements. The order that's being used in the new ResultSet instance is defined by the supplied Comparator class. Note that this constructor throws an IllegalArgumentException if the Collection that is provided contains Results that have duplicate UIDs.- Parameters:
results- The collection of Results that make up this result set.comparator- The Comparator that defines the order of the Results in this result set.
-
-
Method Details
-
size
public int size()- Specified by:
sizein interfaceCollection<E extends Result>- Specified by:
sizein classAbstractCollection<E extends Result>
-
getAfter
Description copied from class:ResultSetReturns a List of results starting with the first result after the result that's identified by the provided UID (the returned List is exclusive). The lenght of the list is equal to 'maxAmount', unless there are no more elements available (in which case the length of the result will be truncated).- Specified by:
getAfterin classResultSet<E extends Result>- Parameters:
uid- The UID of the element that is right before the first element in the result.maxAmount- The maximum number of elements to return.- Returns:
- A List of elements the are exactly after the element that is provided as a parameter.
-
getBefore
Description copied from class:ResultSetReturns a list of results ending with the element right before the element identified by the provided UID (the returned List is exclusive). At most 'maxAmount' elements are in the returned List, but the lenght of the result might be smaller if no more applicable elements are available. Note that the order of the result is equal to the order of the results of other methods of this class: the last element in the returned List immediately preceeds the element denoted by the 'result' parameter.- Specified by:
getBeforein classResultSet<E extends Result>- Parameters:
uid- The UID of the element preceding the last element returned by this function.maxAmount- The length of the List that is being returned.- Returns:
- A List of elements that are exactly before the element that's provided as a parameter.
-
get
Description copied from class:ResultSetReturns the element denoted by the index. -
getFirst
Description copied from class:ResultSetReturns the first elements from this result set. -
getLast
Description copied from class:ResultSetReturns the last elements from this result set. -
get
Description copied from class:ResultSetReturns a list of results, starting with the result that's at the specified index. If the difference between the startIndex and the index of the last element in the entire resultset is smaller than the size supplied in the 'amount' parameter, the length of the returned list will be smaller than the 'amount' paramater. If the supplied index is equal to, or larger than the size of the result set, an empty List is returned.- Specified by:
getin classResultSet<E extends Result>- Parameters:
fromIndex- The index of the first element to be returned.maxAmount- The maximum number of elements to return.- Returns:
- A list of elements starting with (inclusive) the element referenced by 'fromIndex'. An empty List if startIndex is equal to or bigger than the size of this entire result set.
-
indexOf
Description copied from class:ResultSetReturns the index in the full resultset of the element identified by the UID in te supplied argument.
-