Package org.xmpp.resultsetmanagement
Class ResultSet<E extends Result>
java.lang.Object
java.util.AbstractCollection<E>
org.xmpp.resultsetmanagement.ResultSet<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>
- Direct Known Subclasses:
ResultSetImpl
A result set representation as described in XEP-0059. A result set is a
collection of objects that each have a unique identifier (UID).
It's expected that some implementations will have the complete result set
loaded into memory, whereas more complex implementations might keep
references to partial sets only. This latter would have considerable
advantages if the result set is extremely large, or if the operation to get
all results in the set is expensive.
- Author:
- Guus der Kinderen, guus.der.kinderen@gmail.com
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe namespace that identifies Result Set Management functionality. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionapplyRSMDirectives(org.dom4j.Element rsmElement) Applies the 'result set management' directives to this result set, and returns a list of Results that matches the directives.org.dom4j.ElementgenerateSetElementFromResults(List<E> returnedResults) Generates a Result Set Management 'set' element that describes the parto of the result set that was generated.abstract Eget(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 provided result (the returned List is exclusive).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 provided result (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.getUID(int index) Returns the UID of the object at the specified index in this result set.intReturns the index in the full resultset of the supplied argument.abstract intReturns the index in the full resultset of the element identified by the UID in te supplied argument.static booleanisValidRSMRequest(org.dom4j.Element rsmElement) Checks if the Element that has been passed as an argument is a valid Result Set Management element, in a request context.iterator()Methods inherited from class java.util.AbstractCollection
add, addAll, clear, contains, containsAll, isEmpty, remove, removeAll, retainAll, size, 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
-
NAMESPACE_RESULT_SET_MANAGEMENT
The namespace that identifies Result Set Management functionality.- See Also:
-
-
Constructor Details
-
ResultSet
public ResultSet()
-
-
Method Details
-
getAfter
Returns a List of results starting with the first result after the provided result (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).- Parameters:
result- 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.
- Throws:
NullPointerException- if the result does not exist in the result set.
-
getAfter
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). 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).- 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.
- Throws:
NullPointerException- if there is no result in the result set that matches the UID.
-
getBefore
Returns a list of results ending with the element right before the provided result (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.- Parameters:
result- 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.
- Throws:
NullPointerException- if the result does not exist in the result set.
-
getBefore
Returns 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.- 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.
- Throws:
NullPointerException- if there is no result in the result set that matches the UID.
-
getFirst
Returns the first elements from this result set.- Parameters:
maxAmount- the number of elements to return.- Returns:
- the last 'maxAmount' elements of this result set.
-
getLast
Returns the last elements from this result set.- Parameters:
maxAmount- the number of elements to return.- Returns:
- the last 'maxAmount' elements of this result set.
-
get
Returns the element denoted by the index.- Parameters:
index- Index of the element to be returned- Returns:
- the Element at 'index'.
-
get
Returns 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.- 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.
-
getUID
Returns the UID of the object at the specified index in this result set.- Parameters:
index- The index of the UID to be returned.- Returns:
- UID of the object on the specified index.
-
indexOf
Returns the index in the full resultset of the element identified by the UID in te supplied argument.- Parameters:
uid- The UID of the element to search for- Returns:
- The index of the element.
- Throws:
NullPointerException- if there is no result in the result set that matches the UID.
-
indexOf
Returns the index in the full resultset of the supplied argument.- Parameters:
element- The element to search for- Returns:
- The index of the element.
-
iterator
-
applyRSMDirectives
Applies the 'result set management' directives to this result set, and returns a list of Results that matches the directives. Note that the orignal set is untouched. Instead, a new List is returned.- Parameters:
rsmElement- The XML element that contains the 'result set management' directives.- Returns:
- a list of Results that matches the directives.
-
generateSetElementFromResults
Generates a Result Set Management 'set' element that describes the parto of the result set that was generated. You typically would use the List that was returned byapplyRSMDirectives(Element)as an argument to this method.- Parameters:
returnedResults- The subset of Results that is returned by the current query.- Returns:
- An Element named 'set' that can be included in the result IQ stanza, which returns the subset of results.
-
isValidRSMRequest
public static boolean isValidRSMRequest(org.dom4j.Element rsmElement) Checks if the Element that has been passed as an argument is a valid Result Set Management element, in a request context.- Parameters:
rsmElement- The Element to check.- Returns:
- ''true'' if this is a valid RSM query representation, ''false'' otherwise.
-