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 the Result interface.
All Implemented Interfaces:
Iterable<E>, Collection<E>
Direct Known Subclasses:
ResultSetImpl

public abstract class ResultSet<E extends Result> extends AbstractCollection<E>
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

    Fields
    Modifier and Type
    Field
    Description
    static final String
    The namespace that identifies Result Set Management functionality.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    applyRSMDirectives(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.Element
    Generates a Result Set Management 'set' element that describes the parto of the result set that was generated.
    abstract E
    get(int index)
    Returns the element denoted by the index.
    abstract List<E>
    get(int fromIndex, int maxAmount)
    Returns a list of results, starting with the result that's at the specified index.
    getAfter(E result, int maxAmount)
    Returns a List of results starting with the first result after the provided result (the returned List is exclusive).
    abstract List<E>
    getAfter(String uid, int maxAmount)
    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).
    getBefore(E result, int maxAmount)
    Returns a list of results ending with the element right before the provided result (the returned List is exclusive).
    abstract List<E>
    getBefore(String uid, int maxAmount)
    Returns a list of results ending with the element right before the element identified by the provided UID (the returned List is exclusive).
    abstract List<E>
    getFirst(int maxAmount)
    Returns the first elements from this result set.
    abstract List<E>
    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.
    int
    indexOf(E element)
    Returns the index in the full resultset of the supplied argument.
    abstract int
    Returns the index in the full resultset of the element identified by the UID in te supplied argument.
    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.
     

    Methods inherited from class java.lang.Object

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

    Methods inherited from interface java.util.Collection

    equals, hashCode, parallelStream, removeIf, spliterator, stream, toArray

    Methods inherited from interface java.lang.Iterable

    forEach
  • Field Details

    • NAMESPACE_RESULT_SET_MANAGEMENT

      public static final String NAMESPACE_RESULT_SET_MANAGEMENT
      The namespace that identifies Result Set Management functionality.
      See Also:
  • Constructor Details

    • ResultSet

      public ResultSet()
  • Method Details

    • getAfter

      public List<E> getAfter(E result, int maxAmount)
      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

      public abstract List<E> getAfter(String uid, int maxAmount)
      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

      public List<E> getBefore(E result, int maxAmount)
      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

      public abstract List<E> getBefore(String uid, int maxAmount)
      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

      public abstract List<E> getFirst(int maxAmount)
      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

      public abstract List<E> getLast(int maxAmount)
      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

      public abstract E get(int index)
      Returns the element denoted by the index.
      Parameters:
      index - Index of the element to be returned
      Returns:
      the Element at 'index'.
    • get

      public abstract List<E> get(int fromIndex, int maxAmount)
      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

      public String getUID(int index)
      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

      public abstract int indexOf(String uid)
      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

      public int indexOf(E element)
      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

      public Iterator<E> iterator()
      Specified by:
      iterator in interface Collection<E extends Result>
      Specified by:
      iterator in interface Iterable<E extends Result>
      Specified by:
      iterator in class AbstractCollection<E extends Result>
    • applyRSMDirectives

      public List<E> applyRSMDirectives(org.dom4j.Element rsmElement)
      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

      public org.dom4j.Element generateSetElementFromResults(List<E> returnedResults)
      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 by applyRSMDirectives(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.