Prev Class | Next Class | Frames | No Frames |
Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
java.lang.Object
org.apache.commons.collections.IteratorUtils
public class IteratorUtils
extends java.lang.Object
Iterator
instances. The implementations are provided in the
org.apache.commons.collections.iterators
subpackage.
Field Summary | |
static Iterator |
|
static ListIterator |
|
Method Summary | |
static Iterator |
|
static Iterator |
|
static Iterator |
|
static Enumeration |
|
static Iterator |
|
static Iterator |
|
static Iterator |
|
static Iterator |
|
static Iterator |
|
static Iterator |
|
static Iterator |
|
static Iterator |
|
static Iterator |
|
static ListIterator |
|
static Iterator |
|
static ListIterator |
|
static Iterator |
|
static Iterator |
|
static ListIterator |
|
static Object[] |
|
static Object[] |
|
static List |
|
static List |
|
static ListIterator |
|
static Iterator |
|
public static final Iterator EMPTY_ITERATOR
Deprecated. Use
EmptyIterator.INSTANCE
An iterator over no elements.
public static final ListIterator EMPTY_LIST_ITERATOR
Deprecated. Use
EmptyListIterator.INSTANCE
A list iterator over no elements
public static Iterator arrayIterator(Object[] array)
Deprecated. Use
new ArrayIterator(array)
Gets an iterator over an array.
- Parameters:
array
- the array over which to iterate
- Returns:
- an iterator over the array
public static Iterator arrayIterator(Object[] array, int start)
Deprecated. Use
new ArrayIterator(array,start)
Gets an iterator over the end part of an array.
- Parameters:
array
- the array over which to iteratestart
- the index to start iterating at
- Returns:
- an iterator over part of the array
public static Iterator arrayIterator(Object[] array, int start, int end)
Deprecated. Use
new ArrayIterator(array,start,end)
Gets an iterator over part of an array.
- Parameters:
array
- the array over which to iteratestart
- the index to start iterating atend
- the index to finish iterating at
- Returns:
- an iterator over part of the array
public static Enumeration asEnumeration(Iterator iterator)
Gets an enumeration that wraps an iterator.
- Parameters:
iterator
- the iterator to use, not null
public static Iterator asIterator(Enumeration enumeration)
Gets an iterator that provides an iterator view of the given enumeration.
- Parameters:
enumeration
- the enumeration to use
public static Iterator asIterator(Enumeration enumeration, Collection removeCollection)
Gets an iterator that provides an iterator view of the given enumeration that will remove elements from the specified collection.
- Parameters:
enumeration
- the enumeration to use
public static Iterator chainedIterator(Collection iterators)
Gets an iterator that iterates through a collections ofIterator
s one after another.
- Parameters:
iterators
- the iterators to use, not null or empty or contain nulls
- Returns:
- a combination iterator over the iterators
public static Iterator chainedIterator(Iterator iterator1, Iterator iterator2)
Gets an iterator that iterates through twoIterator
s one after another.
- Parameters:
iterator1
- the first iterators to use, not nulliterator2
- the first iterators to use, not null
- Returns:
- a combination iterator over the iterators
public static Iterator chainedIterator(Iterator[] iterators)
Gets an iterator that iterates through an array ofIterator
s one after another.
- Parameters:
iterators
- the iterators to use, not null or empty or contain nulls
- Returns:
- a combination iterator over the iterators
public static Iterator collatedIterator(Comparator comparator, Collection iterators)
Gets an iterator that provides an ordered iteration over the elements contained in a collection ofIterator
s. Given two orderedIterator
sA
andB
, theIterator.next()
method will return the lesser ofA.next()
andB.next()
and so on. The comparator is optional. If null is specified then natural order is used.
- Parameters:
comparator
- the comparator to use, may be null for natural orderiterators
- the iterators to use, not null or empty or contain nulls
- Returns:
- a combination iterator over the iterators
public static Iterator collatedIterator(Comparator comparator, Iterator iterator1, Iterator iterator2)
Gets an iterator that provides an ordered iteration over the elements contained in a collection of orderedIterator
s. Given two orderedIterator
sA
andB
, theIterator.next()
method will return the lesser ofA.next()
andB.next()
. The comparator is optional. If null is specified then natural order is used.
- Parameters:
comparator
- the comparator to use, may be null for natural orderiterator1
- the first iterators to use, not nulliterator2
- the first iterators to use, not null
- Returns:
- a combination iterator over the iterators
public static Iterator collatedIterator(Comparator comparator, Iterator[] iterators)
Gets an iterator that provides an ordered iteration over the elements contained in an array ofIterator
s. Given two orderedIterator
sA
andB
, theIterator.next()
method will return the lesser ofA.next()
andB.next()
and so on. The comparator is optional. If null is specified then natural order is used.
- Parameters:
comparator
- the comparator to use, may be null for natural orderiterators
- the iterators to use, not null or empty or contain nulls
- Returns:
- a combination iterator over the iterators
public static Iterator emptyIterator()
Deprecated. Use
EmptyIterator.INSTANCE
Gets an empty iterator. This iterator is a valid iterator object that will iterate over nothing.
- Returns:
- an iterator over nothing
public static ListIterator emptyListIterator()
Deprecated. Use
EmptyListIterator.INSTANCE
Gets an empty list iterator. This iterator is a valid list iterator object that will iterate over nothing.
- Returns:
- a list iterator over nothing
public static Iterator filteredIterator(Iterator iterator, Predicate predicate)
Gets an iterator that filters another iterator. The returned iterator will only return objects that match the specified filtering predicate.
- Parameters:
iterator
- the iterator to use, not nullpredicate
- the predicate to use as a filter, not null
public static ListIterator filteredListIterator(ListIterator listIterator, Predicate predicate)
Gets a list iterator that filters another list iterator. The returned iterator will only return objects that match the specified filtering predicate.
- Parameters:
listIterator
- the list iterator to use, not nullpredicate
- the predicate to use as a filter, not null
public static Iterator getIterator(Object obj)
Gets a suitable Iterator for the given object. This method can handles objects as follows
- null - empty iterator
- Iterator - returned directly
- Enumeration - wrapped
- Collection - iterator from collection returned
- Map - values iterator returned
- Dictionary - values (elements) enumeration returned as iterator
- array - iterator over array returned
- object with iterator() public method accessed by reflection
- object - singleton iterator
- Parameters:
obj
- the object to convert to an iterator
- Returns:
- a suitable iterator, never null
public static Iterator singletonIterator(Object object)
Deprecated. Use
new SingletonIterator(object)
Gets a singleton iterator. This iterator is a valid iterator object that will iterate over the specified object.
- Parameters:
object
- the single object over which to iterate
- Returns:
- a singleton iterator over the object
public static ListIterator singletonListIterator(Object object)
Gets a singleton list iterator. This iterator is a valid list iterator object that will iterate over the specified object.
- Parameters:
object
- the single object over which to iterate
- Returns:
- a singleton list iterator over the object
public static Object[] toArray(Iterator iterator)
Gets an array based on an iterator. As the wrapped Iterator is traversed, an ArrayList of its values is created. At the end, this is converted to an array.
- Parameters:
iterator
- the iterator to use, not null
public static Object[] toArray(Iterator iterator, Class arrayClass)
Gets an array based on an iterator. As the wrapped Iterator is traversed, an ArrayList of its values is created. At the end, this is converted to an array.
- Parameters:
iterator
- the iterator to use, not nullarrayClass
- the class of array to create
public static List toList(Iterator iterator)
Gets a list based on an iterator. As the wrapped Iterator is traversed, an ArrayList of its values is created. At the end, the list is returned.
- Parameters:
iterator
- the iterator to use, not null
public static List toList(Iterator iterator, int estimatedSize)
Gets a list based on an iterator. As the wrapped Iterator is traversed, an ArrayList of its values is created. At the end, the list is returned.
- Parameters:
iterator
- the iterator to use, not nullestimatedSize
- the initial size of the ArrayList
public static ListIterator toListIterator(Iterator iterator)
Gets a list iterator based on a simple iterator. As the wrapped Iterator is traversed, a LinkedList of its values is cached, permitting all required operations of ListIterator.
- Parameters:
iterator
- the iterator to use, not null
public static Iterator transformedIterator(Iterator iterator, Transformer transform)
Gets an iterator that transforms the elements of another iterator. The transformation occurs during the next() method and the underlying iterator is unaffected by the transformation.
- Parameters:
iterator
- the iterator to use, not nulltransform
- the transform to use, not null