org.xmpp.resultsetmanagement
Class ResultSet<E extends Result>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by 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:
java.lang.Iterable<E>, java.util.Collection<E>
Direct Known Subclasses:
ResultSetImpl

public abstract class ResultSet<E extends Result>
extends java.util.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
static java.lang.String NAMESPACE_RESULT_SET_MANAGEMENT
          The namespace that identifies Result Set Management functionality.
 
Constructor Summary
ResultSet()
           
 
Method Summary
 java.util.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.
 org.dom4j.Element generateSetElementFromResults(java.util.List<E> returnedResults)
          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  java.util.List<E> get(int fromIndex, int maxAmount)
          Returns a list of results, starting with the result that's at the specified index.
 java.util.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).
abstract  java.util.List<E> getAfter(java.lang.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).
 java.util.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).
abstract  java.util.List<E> getBefore(java.lang.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  java.util.List<E> getFirst(int maxAmount)
          Returns the first elements from this result set.
abstract  java.util.List<E> getLast(int maxAmount)
          Returns the last elements from this result set.
 java.lang.String 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 indexOf(java.lang.String uid)
          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.
 java.util.Iterator<E> iterator()
           
 
Methods inherited from class java.util.AbstractCollection
add, addAll, clear, contains, containsAll, isEmpty, remove, removeAll, retainAll, size, toArray, toArray, toString
 
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
 

Field Detail

NAMESPACE_RESULT_SET_MANAGEMENT

public static final java.lang.String NAMESPACE_RESULT_SET_MANAGEMENT
The namespace that identifies Result Set Management functionality.

See Also:
Constant Field Values
Constructor Detail

ResultSet

public ResultSet()
Method Detail

getAfter

public java.util.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:
java.lang.NullPointerException - if the result does not exist in the result set.

getAfter

public abstract java.util.List<E> getAfter(java.lang.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:
java.lang.NullPointerException - if there is no result in the result set that matches the UID.

getBefore

public java.util.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:
java.lang.NullPointerException - if the result does not exist in the result set.

getBefore

public abstract java.util.List<E> getBefore(java.lang.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:
java.lang.NullPointerException - if there is no result in the result set that matches the UID.

getFirst

public abstract java.util.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 java.util.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 java.util.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 java.lang.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(java.lang.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:
java.lang.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 java.util.Iterator<E> iterator()
Specified by:
iterator in interface java.lang.Iterable<E extends Result>
Specified by:
iterator in interface java.util.Collection<E extends Result>
Specified by:
iterator in class java.util.AbstractCollection<E extends Result>

applyRSMDirectives

public java.util.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(java.util.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.


Copyright © 2009-2010 Ignite Realtime. All Rights Reserved.