Top Description Constructors Methods
org.eclipse.xtext.xbase.lib

public Class IteratorExtensions

extends Object
Class Inheritance
Annotations
@GwtCompatible
Imports
java.util.ArrayList, .Comparator, .Iterator, .List, .Map, .NoSuchElementException, .Objects, .Set, org.eclipse.xtext.xbase.lib.Functions.Function1, .Functions.Function2, .Procedures.Procedure1, .Procedures.Procedure2, org.eclipse.xtext.xbase.lib.internal.BooleanFunctionDelegate, .FunctionDelegate, .KeyComparator, com.google.common.annotations.GwtCompatible, .GwtIncompatible, com.google.common.base.Joiner, .Predicates, com.google.common.collect.AbstractIterator, .ImmutableSet, .Iterators, .Lists, .Maps, .Ordering, .Sets

This is an extension library for iterators.
Authors
Sven Efftinge - Initial contribution and API, Sebastian Zarnekow

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static boolean

Returns:

true if this Iterator contains the specified element
contains
(Iterator<?>
the elements to test
iterator
,
Object
element whose presence in this Iterator is to be tested
o
)

Returns true if this Iterator contains the specified element.

public static <T> Iterator<T>

Returns:

an iterator without the first count elements. Never null.
drop
(final Iterator<T>
the iterator. May not be null.
iterator
,
final int
the number of elements that should be dropped.
count
)

Returns a view on this iterator that provides all elements except the first count entries.

public static <T> Iterator<T>

Returns:

the remaining elements after dropping
dropWhile
(final Iterator<? extends T>
the elements from which to drop. May not be null.
iterator
,
final Functions.Function1<? super T, Boolean>
the predicate which decides whether to keep dropping elements. May not be null.
predicate
)

Returns an Iterator containing all elements starting from the first element for which the drop-predicate returned false.

public static boolean

Returns:

true if the two iterators contain equal elements in the same order.
elementsEqual
(Iterator<?>
an iterator. May not be null.
iterator
,
Iterator<?>
an iterator. May not be null.
other
)

Determines whether two iterators contain equal elements in the same order.

public static boolean

Returns:

true if the two iterators contain equal elements in the same order.
elementsEqual
(Iterator<?>
an iterator. May not be null.
iterator
,
Iterable<?>
an iterable. May not be null.
iterable
)

Determines whether two iterators contain equal elements in the same order.

public static <T> boolean

Returns:

true if one or more elements in iterator satisfy the predicate.
exists
(Iterator<T>
the iterator. May not be null.
iterator
,
Functions.Function1<? super T, Boolean>
the predicate. May not be null.
predicate
)

Returns true if one or more elements in iterator satisfy the predicate.

public static <T> Iterator<T>

Returns:

an iterator that contains only the elements that fulfill the predicate. Never null.
filter
(Iterator<T>
the unfiltered iterator. May not be null.
unfiltered
,
Functions.Function1<? super T, Boolean>
the predicate. May not be null.
predicate
)

Returns the elements of unfiltered that satisfy a predicate.

public static <T> Iterator<T>

Returns:

an unmodifiable iterator containing all elements of the original iterator that were of the requested type. Never null.
filter
(Iterator<?>
the unfiltered iterator. May not be null.
unfiltered
,
Class<T>
the type of elements desired
type
)

Returns all instances of class type in unfiltered.

public static <T> Iterator<T>

Returns:

an unmodifiable iterator containing all elements of the original iterator without any null references. Never null.
filterNull
(Iterator<T>
the unfiltered iterator. May not be null.
unfiltered
)

Returns a new iterator filtering any null references.

public static <T> T

Returns:

the first element in the iterator for which the given predicate returns true, returns null if no element matches the predicate or the iterator is empty.
findFirst
(Iterator<T>
the iterator. May not be null.
iterator
,
Functions.Function1<? super T, Boolean>
the predicate. May not be null.
predicate
)

Finds the first element in the given iterator that fulfills the predicate.

public static <T> T

Returns:

the last element in the iterator for which the given predicate returns true, returns null if no element matches the predicate or the iterator is empty.
findLast
(Iterator<T>
the iterator. May not be null.
iterator
,
Functions.Function1<? super T, Boolean>
the predicate. May not be null.
predicate
)

Finds the last element in the given iterator that fulfills the predicate.

public static <T, R> Iterator<R>

Returns:

an iterable that provides the result of the transformation. Never null.
flatMap
(Iterator<T>
the original iterable. May not be null.
original
,
Functions.Function1<? super T, ? extends Iterator<R>>
the transformation. May not be null and must not yield null.
transformation
)

Returns an iterable that performs the given transformation for each element of original when requested.

public static <T> Iterator<T>

Returns:

an iterator that provides the concatenated values of the input elements. Never null.
flatten
(Iterator<? extends Iterator<? extends T>>
the to be flattened iterators. May not be null.
inputs
)

Combines multiple iterators into a single iterator.

public static <T, R> R

Returns:

the last result of the applied combinator function or seed for the empty input.
fold
(Iterator<T>
the to-be-folded iterator. May not be null.
iterator
,
R
the initial value. May be null.
seed
,
Functions.Function2<? super R, ? super T, ? extends R>
the combinator function. May not be null.
function
)

Applies the combinator function to all elements of the iterator in turn and uses seed as the start value.

public static <T> boolean

Returns:

true if every element in iterator satisfies the predicate and also if there is no element.
forall
(Iterator<T>
the iterator. May not be null.
iterator
,
Functions.Function1<? super T, Boolean>
the predicate. May not be null.
predicate
)

Returns true if every element in iterator satisfies the predicate.

public static <T> void
forEach(Iterator<T>
the iterator. May not be null.
iterator
,
Procedures.Procedure1<? super T>
the procedure. May not be null.
procedure
)

Applies procedure for each element of the given iterator.

public static <T> void
forEach(Iterator<T>
the iterator. May not be null.
iterator
,
Procedures.Procedure2<? super T, ? super Integer>
the procedure. May not be null.
procedure
)

Applies procedure for each element of the given iterator.

public static <K, V> Map<K, List<V>>

Returns:

a map mapping the result of evaluating the function keyFunction on each value in the input iterator to that value. As there can be more than one value mapped by a key, the mapping result is is a list of values.
groupBy
(Iterator<? extends V>
the values to use when constructing the Map. May not be null.
values
,
Functions.Function1<? super V, ? extends K>
the function used to produce the key for each value. May not be null.
computeKeys
)

Returns a map for which the Map#values is a collection of lists, where the elements in the list will appear in the order as they appeared in the iterator.

public static <T> T

Returns:

the first element in the iterator or null.
head
(Iterator<T>
the iterator. May not be null.
iterator
)

Returns the first element in the given iterator or null if empty.

public static <A> Iterator<Pair<Integer, A>>

Returns:

the zipped result
indexed
(final Iterator<? extends A>
the elements. May not be null.
iterator
)

Returns an Iterator of Pairs where the nth pair is created by taking the nth element of the source as the value and its 0-based index as the key.

public static boolean

Returns:

true if the iterator contains no elements
isEmpty
(Iterator<?>
the to-be-queried iterator. May not be null.
iterator
)

Determines if the given iterator contains no elements.

public static boolean

Returns:

true if the iterator is null or contains no elements
isNullOrEmpty
(Iterator<?>
the to-be-queried iterator. May be null.
iterator
)

Determines if the given iterator is null or contains no elements.

public static String

Returns:

the string representation of the iterator's elements. Never null.
join
(Iterator<?>
the iterator. May not be null.
iterator
)

Returns the concatenated string representation of the elements in the given iterator.

public static String

Returns:

the string representation of the iterator's elements. Never null.
join
(Iterator<?>
the iterator. May not be null.
iterator
,
CharSequence
the separator. May not be null.
separator
)

Returns the concatenated string representation of the elements in the given iterator.

public static <T> String

Returns:

the string representation of the iterator's elements. Never null.
join
(Iterator<T>
the iterator. May not be null.
iterator
,
CharSequence
the separator. May not be null.
separator
,
Functions.Function1<? super T, ? extends CharSequence>
the function that is used to compute the string representation of a single element. May not be null.
function
)

Returns the concatenated string representation of the elements in the given iterator.

public static <T> String

Returns:

the string representation of the iterator's elements. Never null.
join
(Iterator<T>
the iterator. May not be null.
iterator
,
CharSequence
prepends the resulting string if the iterator contains at least one element. May be null which is equivalent to passing an empty string.
before
,
CharSequence
the separator. May be null which is equivalent to passing an empty string.
separator
,
CharSequence
appended to the resulting string if the iterator contain at least one element. May be null which is equivalent to passing an empty string.
after
,
Functions.Function1<? super T, ? extends CharSequence>
the function that is used to compute the string representation of a single element. May not be null.
function
)

Returns the concatenated string representation of the elements in the given iterator.

public static <T> T

Returns:

the last element in the iterator or null.
last
(Iterator<T>
the iterator. May not be null.
iterator
)
Deprecated Use lastOrNull(Iterator<T>) instead.

Returns the last element in the given iterator or null if empty.

public static <T> T

Returns:

the last element in the iterator or null.
lastOrNull
(Iterator<T>
the iterator. May not be null.
iterator
)

Returns the last element in the given iterator or null if empty.

public static <T, R> Iterator<R>

Returns:

an iterator that provides the result of the transformation. Never null.
map
(Iterator<T>
the original iterator. May not be null.
original
,
Functions.Function1<? super T, ? extends R>
the transformation. May not be null.
transformation
)

Returns an iterator that performs the given transformation for each element of original when requested.

public static <T extends Comparable<? super T>> T

Returns:

the maximum
max
(final Iterator<T>
the mutually comparable elements. May not be null.
iterator
)

Finds the maximum of the elements according to their natural ordering.

public static <T> T

Returns:

the maximum
max
(final Iterator<T>
the elements to find the maximum of. May not be null.
iterator
,
Comparator<? super T>
the comparison function. May not be null.
comparator
)

Finds the maximum element according to comparator.

public static <T, C extends Comparable<? super C>> T

Returns:

the maximum
maxBy
(final Iterator<T>
the elements to find the maximum of. May not be null.
iterator
,
final Functions.Function1<? super T, C>
a function that returns a comparable characteristic to compare the elements by. May not be null.
compareBy
)

Finds the element that yields the maximum value when passed to compareBy If there are several maxima, the first one will be returned.

public static <T extends Comparable<? super T>> T

Returns:

the minimum
min
(final Iterator<T>
the mutually comparable elements. May not be null.
iterator
)

Finds the minimum of the given elements according to their natural ordering.

public static <T> T

Returns:

the minimum
min
(final Iterator<T>
the elements to find the minimum of. May not be null.
iterator
,
Comparator<? super T>
the comparison function. May not be null.
comparator
)

Finds the mininmum element according to comparator.

public static <T, C extends Comparable<? super C>> T

Returns:

the minimum
minBy
(final Iterator<T>
the elements to find the minimum of. May not be null.
iterator
,
final Functions.Function1<? super T, C>
a function that returns a comparable characteristic to compare the elements by. May not be null.
compareBy
)

Finds the element that yields the minimum value when passed to compareBy.

public static <T> Iterator<T>

Returns:

a combined iterator. Never null.
operator_plus
(Iterator<? extends T>
the first iterator. May not be null.
a
,
Iterator<? extends T>
the second iterator. May not be null.
b
)

Concatenates two iterators into a single iterator.

public static <T> T

Returns:

the last result of the applied combinator function or null for the empty input.
reduce
(Iterator<? extends T>
the to-be-reduced iterator. May not be null.
iterator
,
Functions.Function2<? super T, ? super T, ? extends T>
the combinator function. May not be null.
function
)

Applies the combinator function to all elements of the iterator in turn.

public static <T> Iterator<T>

Returns:

an iterator that contains only the elements that do not fulfill the predicate. Never null.
reject
(Iterator<T>
the unfiltered iterator. May not be null.
unfiltered
,
Functions.Function1<? super T, Boolean>
the predicate. May not be null.
predicate
)

Returns the elements of unfiltered that do not satisfy a predicate.

public static int

Returns:

the number of elements in iterator.
size
(Iterator<?>
the iterator. May not be null.
iterator
)

Returns the number of elements in iterator.

public static <T> Iterator<T>

Returns:

an iterator with all elements except the first. Never null.
tail
(final Iterator<T>
the iterator. May not be null.
iterator
)

Returns a view on this iterator that contains all the elements except the first.

public static <T> Iterator<T>

Returns:

an iterator with count elements. Never null.
take
(final Iterator<T>
the iterator. May not be null.
iterator
,
final int
the number of elements that should be returned at most.
count
)

Returns a view on this iterator that provides at most the first count entries.

public static <T> Iterator<T>

Returns:

the taken elements
takeWhile
(final Iterator<? extends T>
the elements from which to take. May not be null.
iterator
,
final Functions.Function1<? super T, Boolean>
the predicate which decides whether to keep taking elements. May not be null.
predicate
)

Returns an Iterator containing all elements starting from the head of the source up to and excluding the first element that violates the predicate.

public static <K, V> Map<K, V>

Returns:

a map mapping each entry in the given iterator to the corresponding result when evaluating the function computeValues.
toInvertedMap
(Iterator<? extends K>
the keys to use when constructing the Map. May not be null.
keys
,
Functions.Function1<? super K, V>
the function used to produce the values for each key. May not be null.
computeValues
)

Returns a map for which the Map#values are computed by the given function, and each key is an element in the given keys.

public static <T> Iterable<T>

Returns:

an Iterable providing the given Iterator. Never null.
toIterable
(final Iterator<T>
the Iterator to wrap in an Iterable. May not be null.
iterator
)

Wraps an Iterator in an Iterable.

public static <T> List<T>

Returns:

a list with the same entries as the given iterator. Never null.
toList
(Iterator<? extends T>
the iterator. May not be null.
iterator
)

Returns a list that contains all the entries of the given iterator in the same order.

public static <K, V> Map<K, V>

Returns:

a map mapping the result of evaluating the function keyFunction on each value in the input iterator to that value
toMap
(Iterator<? extends V>
the values to use when constructing the Map. May not be null.
values
,
Functions.Function1<? super V, K>
the function used to produce the key for each value. May not be null.
computeKeys
)

Returns a map for which the Map#values are the given elements in the given order, and each key is the product of invoking a supplied function computeKeys on its corresponding value.

public static <T, K, V> Map<K, V>

Returns:

a map mapping the result of evaluating the functions keyFunction and computeValues on each value in the input iterator to that value
toMap
(Iterator<? extends T>
the elements to use when constructing the Map. May not be null.
inputs
,
Functions.Function1<? super T, K>
the function used to produce the key for each value. May not be null.
computeKeys
,
Functions.Function1<? super T, V>
the function used to produce the values for each key. May not be null.
computeValues
)

Returns a map for which the Map#values are the product of invoking supplied function computeValues on input iterable elements, and each key is the product of invoking a supplied function computeKeys on same elements.

public static <T> Set<T>

Returns:

a set with the unique entries of the given iterator. Never null.
toSet
(Iterator<? extends T>
the iterator. May not be null.
iterator
)

Returns a set that contains all the unique entries of the given iterator in the order of their appearance.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait