Groovy JDK

java.util
Class Iterator

Method Summary
boolean asBoolean()
Coerce an iterator instance to a boolean value.
Number count(Object value)
Counts the number of occurrences of the given value from the items within this Iterator.
Object inject(Object value, Closure closure)
Iterates through the given iterator, passing in the initial value to the closure along with the current iterated item then passing into the next iteration the value of the previous closure.
Iterator iterator()
An identity function for iterators, supporting 'duck-typing' when trying to get an iterator for each object within a collection, some of which may already be iterators.
String join(String separator)
Concatenates the toString() representation of each item from the iterator, with the given String as a separator between each item.
T max()
Adds max() method to Iterator objects.
T max(Closure closure)
Selects the maximum value found from the Iterator using the closure to determine the correct ordering.
T max(Comparator comparator)
Selects the maximum value found from the Iterator using the given comparator.
T min()
Adds min() method to Iterator objects.
T min(Comparator comparator)
Selects the minimum value found from the Iterator using the given comparator.
T min(Closure closure)
Selects the minimum value found from the Iterator using the closure to determine the correct ordering.
Iterator reverse()
Reverses the iterator.
int size()
Provide the standard Groovy size() method for Iterator.
Iterator sort()
Sorts the given iterator items into a sorted iterator.
Iterator sort(Comparator comparator)
Sorts the given iterator items into a sorted iterator using the comparator.
Iterator sort(Closure closure)
Sorts the given iterator items into a sorted iterator using the Closure to determine the correct ordering.
Object sum()
Sums the items from an Iterator.
Object sum(Object initialValue)
Sums the items from an Iterator.
List toList()
Convert an iterator to a List.
Iterator unique()
Returns an iterator equivalent to this iterator all duplicated items removed by using the default comparator.
Iterator unique(Closure closure)
Returns an iterator equivalent to this iterator but with all duplicated items removed by using a Closure to determine duplicate (equal) items.
Iterator unique(Comparator comparator)
Returns an iterator equivalent to this iterator with all duplicated items removed by using the supplied comparator.
 
Method Detail

asBoolean

public boolean asBoolean()
 
Coerce an iterator instance to a boolean value. An iterator is coerced to false if there are no more elements to iterate over, and to true otherwise.
Returns:
the boolean value
Since:
1.7.0

count

public Number count(Object value)
 
Counts the number of occurrences of the given value from the items within this Iterator. Comparison is done using Groovy's == operator (using compareTo(value) == 0 or equals(value) ). The iterator will become exhausted of elements after determining the count value.
Parameters:
value - the value being searched for.
Returns:
the number of occurrences
Since:
1.5.0

inject

public Object inject(Object value, Closure closure)
 
Iterates through the given iterator, passing in the initial value to the closure along with the current iterated item then passing into the next iteration the value of the previous closure.
Parameters:
value - a value.
closure - a closure.
Returns:
the last value of the last iteration
Since:
1.5.0

iterator

public Iterator iterator()
 
An identity function for iterators, supporting 'duck-typing' when trying to get an iterator for each object within a collection, some of which may already be iterators.
Returns:
itself
Since:
1.5.0

join

public String join(String separator)
 
Concatenates the toString() representation of each item from the iterator, with the given String as a separator between each item. The iterator will become exhausted of elements after determining the resulting conjoined value.
Parameters:
separator - a String separator.
Returns:
the joined String
Since:
1.5.5

max

public T max()
 
Adds max() method to Iterator objects. The iterator will become exhausted of elements after determining the maximum value.
Returns:
the maximum value
Since:
1.5.5
See:
GroovyCollections#max.

max

public T max(Closure closure)
 
Selects the maximum value found from the Iterator using the closure to determine the correct ordering. The iterator will become exhausted of elements after this operation.

If the closure has two parameters it is used like a traditional Comparator. I.e. it should compare its two parameters for order, returning a negative integer, zero, or a positive integer when the first parameter is less than, equal to, or greater than the second respectively. Otherwise, the Closure is assumed to take a single parameter and return a Comparable (typically an Integer) which is then used for further comparison.
Parameters:
closure - a Closure used to determine the correct ordering.
Returns:
the maximum value
Since:
1.5.5
See:
#max.

max

public T max(Comparator comparator)
 
Selects the maximum value found from the Iterator using the given comparator.
Parameters:
comparator - a Comparator.
Returns:
the maximum value
Since:
1.5.5

min

public T min()
 
Adds min() method to Iterator objects. The iterator will become exhausted of elements after determining the minimum value.
Returns:
the minimum value
Since:
1.5.5
See:
#min.

min

public T min(Comparator comparator)
 
Selects the minimum value found from the Iterator using the given comparator.
Parameters:
comparator - a Comparator.
Returns:
the minimum value
Since:
1.5.5
See:
#min.

min

public T min(Closure closure)
 
Selects the minimum value found from the Iterator using the closure to determine the correct ordering. The iterator will become exhausted of elements after this operation.

If the closure has two parameters it is used like a traditional Comparator. I.e. it should compare its two parameters for order, returning a negative integer, zero, or a positive integer when the first parameter is less than, equal to, or greater than the second respectively. Otherwise, the Closure is assumed to take a single parameter and return a Comparable (typically an Integer) which is then used for further comparison.
Parameters:
closure - a Closure used to determine the correct ordering.
Returns:
the minimum value
Since:
1.5.5
See:
#min.

reverse

public Iterator reverse()
 
Reverses the iterator. The original iterator will become exhausted of elements after determining the reversed values. A new iterator for iterating through the reversed values is returned.
Returns:
a reversed Iterator
Since:
1.5.5

size

public int size()
 
Provide the standard Groovy size() method for Iterator. The iterator will become exhausted of elements after determining the size value.
Returns:
the length of the Iterator
Since:
1.5.5

sort

public Iterator sort()
 
Sorts the given iterator items into a sorted iterator. The items are assumed to be comparable. The original iterator will become exhausted of elements after completing this method call. A new iterator is produced that traverses the items in sorted order.
Returns:
the sorted items as an Iterator
Since:
1.5.5

sort

public Iterator sort(Comparator comparator)
 
Sorts the given iterator items into a sorted iterator using the comparator.
Parameters:
comparator - a Comparator used for comparing items.
Returns:
the sorted items as an Iterator
Since:
1.5.5

sort

public Iterator sort(Closure closure)
 
Sorts the given iterator items into a sorted iterator using the Closure to determine the correct ordering. The original iterator will be fully processed after the method call.

If the closure has two parameters it is used like a traditional Comparator. I.e. it should compare its two parameters for order, returning a negative integer, zero, or a positive integer when the first parameter is less than, equal to, or greater than the second respectively. Otherwise, the Closure is assumed to take a single parameter and return a Comparable (typically an Integer) which is then used for further comparison.
Parameters:
closure - a Closure used to determine the correct ordering.
Returns:
the sorted items as an Iterator
Since:
1.5.5

sum

public Object sum()
 
Sums the items from an Iterator. This is equivalent to invoking the "plus" method on all items from the Iterator. The iterator will become exhausted of elements after determining the sum value.
Returns:
The sum of all of the items
Since:
1.5.5

sum

public Object sum(Object initialValue)
 
Sums the items from an Iterator. This is equivalent to invoking the "plus" method on all items from the Iterator.
Parameters:
initialValue - the items in the collection will be summed to this initial value.
Returns:
The sum of all of the items
Since:
1.5.5

toList

public List toList()
 
Convert an iterator to a List. The iterator will become exhausted of elements after making this conversion.
Returns:
a List
Since:
1.5.0

unique

public Iterator unique()
 
Returns an iterator equivalent to this iterator all duplicated items removed by using the default comparator. The original iterator will become exhausted of elements after determining the unique values. A new iterator for the unique values will be returned.
Returns:
the modified Iterator
Since:
1.5.5

unique

public Iterator unique(Closure closure)
 
Returns an iterator equivalent to this iterator but with all duplicated items removed by using a Closure to determine duplicate (equal) items. The original iterator will be fully processed after the call.

If the closure takes a single parameter, the argument passed will be each element, and the closure should return a value used for comparison (either using {@link Comparable#compareTo(Object)} or {@link Object#equals(Object)}). If the closure takes two parameters, two items from the Iterator will be passed as arguments, and the closure should return an int value (with 0 indicating the items are not unique).
Parameters:
closure - a Closure used to determine unique items.
Returns:
the modified Iterator
Since:
1.5.5

unique

public Iterator unique(Comparator comparator)
 
Returns an iterator equivalent to this iterator with all duplicated items removed by using the supplied comparator.
Parameters:
comparator - a Comparator.
Returns:
the modified Iterator
Since:
1.5.5

Groovy JDK