org.inria.ns.reflex.util
Class CollectionsHelper

java.lang.Object
  extended by org.inria.ns.reflex.util.CollectionsHelper

public class CollectionsHelper
extends Object

Usefull stuff that deals with collections, such as few iterators, and others.

Author:
Philippe Poulard

Nested Class Summary
static class CollectionsHelper.ArrayIterator
          An iterator to browse an array.
static class CollectionsHelper.DeferredIterator
          A deferred Iterator.
static class CollectionsHelper.IteratorCumulator
          An Iterator that browse 2 or 3 Iterators.
static class CollectionsHelper.SingleObjectIterator
          An iterator that wraps a single object.
static class CollectionsHelper.TokenSet
          Stores a set of tokens in a hashtable for fast index retrieval.
static class CollectionsHelper.UnmodifiableIterator
          An unmodifiable Iterator.
 
Field Summary
static Iterator EMPTY_ITERATOR
          Empty iterator.
static NoSuchElementException NO_SUCH_ELEMENT_EXCEPTION
          No such element.
static UnsupportedOperationException UNSUPPORTED_OPERATION_EXCEPTION
          Unsupported Operation.
 
Constructor Summary
CollectionsHelper()
           
 
Method Summary
static String concatAll(Iterator items)
          Converts the items of a list in a single string.
static String concatAll(Iterator items, String separator)
          Converts the items of a list in a single string.
static String concatAll(List list)
          Converts the items of a list in a single string.
static String concatAll(List list, String separator)
          Converts the items of a list in a single string.
static Iterator getArrayIterator(Object[] array)
          Return an iterator that iterates on each item of an array.
static Iterator getEmptyIterator()
          Return an empty iterator.
static Object getItemAt(Object collection, int index)
          Lookup for an item of a collection at a specific position.
static Iterator getSingleObjectIterator(Object obj)
          Return an iterator that contains a single object.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

UNSUPPORTED_OPERATION_EXCEPTION

public static final UnsupportedOperationException UNSUPPORTED_OPERATION_EXCEPTION
Unsupported Operation.


NO_SUCH_ELEMENT_EXCEPTION

public static final NoSuchElementException NO_SUCH_ELEMENT_EXCEPTION
No such element.


EMPTY_ITERATOR

public static final Iterator EMPTY_ITERATOR
Empty iterator.

Constructor Detail

CollectionsHelper

public CollectionsHelper()
Method Detail

getEmptyIterator

public static Iterator getEmptyIterator()
Return an empty iterator.

Returns:
An empty iterator.

getSingleObjectIterator

public static Iterator getSingleObjectIterator(Object obj)
Return an iterator that contains a single object.

Parameters:
obj - The object to iterate on.
Returns:
An iterator that contains a single object.

getArrayIterator

public static Iterator getArrayIterator(Object[] array)
Return an iterator that iterates on each item of an array.

Parameters:
array - The array to iterate on.
Returns:
An iterator that iterates on each item of an array.

getItemAt

public static Object getItemAt(Object collection,
                               int index)
                        throws IndexOutOfBoundsException
Lookup for an item of a collection at a specific position.

Parameters:
collection - The collection that owns the item to find. Collections supported are :
  • Node
  • NodeList
  • Map
  • Collection
  • Iterator
  • XOperable
index - The position of the item in the collection, 1 is the first.
Returns:
The item that has the specific position.
Throws:
IndexOutOfBoundsException - If the position is out of range.
IllegalArgumentException - If the collection is not supported.

concatAll

public static String concatAll(List list)
Converts the items of a list in a single string.

Parameters:
list - The list to concat.
Returns:
The items concatenated.

concatAll

public static String concatAll(List list,
                               String separator)
Converts the items of a list in a single string.

Parameters:
list - The list to concat.
separator - The separator used between each item of the list.
Returns:
The items concatenated.

concatAll

public static String concatAll(Iterator items)
Converts the items of a list in a single string.

Parameters:
items - The items to concat.
Returns:
The items concatenated.

concatAll

public static String concatAll(Iterator items,
                               String separator)
Converts the items of a list in a single string.

Parameters:
items - The items to concat.
separator - The separator used between each item of the list.
Returns:
The items concatenated.