com.google.inject.internal.util
Class Iterables

java.lang.Object
  extended by com.google.inject.internal.util.Iterables

public final class Iterables
extends Object

This class contains static utility methods that operate on or return objects of type Iterable. Also see the parallel implementations in Iterators.

Author:
Kevin Bourrillion, Scott Bonneau

Method Summary
static
<T> Iterable<T>
concat(Iterable<? extends Iterable<? extends T>> inputs)
          Combines multiple iterables into a single iterable.
static
<T> Iterable<T>
concat(Iterable<? extends T> a, Iterable<? extends T> b)
          Combines two iterables into a single iterable.
static
<T> T
getOnlyElement(Iterable<T> iterable)
          Returns the single element contained in iterable.
static String toString(Iterable<?> iterable)
          Returns a string representation of iterable, with the format [e1, e2, ..., en].
static
<F,T> Iterable<T>
transform(Iterable<F> fromIterable, Function<? super F,? extends T> function)
          Returns an iterable that applies function to each element of fromIterable.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

toString

public static String toString(Iterable<?> iterable)
Returns a string representation of iterable, with the format [e1, e2, ..., en].


getOnlyElement

public static <T> T getOnlyElement(Iterable<T> iterable)
Returns the single element contained in iterable.

Throws:
NoSuchElementException - if the iterable is empty
IllegalArgumentException - if the iterable contains multiple elements

concat

public static <T> Iterable<T> concat(Iterable<? extends T> a,
                                     Iterable<? extends T> b)
Combines two iterables into a single iterable. The returned iterable has an iterator that traverses the elements in a, followed by the elements in b. The source iterators are not polled until necessary.

The returned iterable's iterator supports remove() when the corresponding input iterator supports it.


concat

public static <T> Iterable<T> concat(Iterable<? extends Iterable<? extends T>> inputs)
Combines multiple iterables into a single iterable. The returned iterable has an iterator that traverses the elements of each iterable in inputs. The input iterators are not polled until necessary.

The returned iterable's iterator supports remove() when the corresponding input iterator supports it. The methods of the returned iterable may throw NullPointerException if any of the input iterators are null.


transform

public static <F,T> Iterable<T> transform(Iterable<F> fromIterable,
                                          Function<? super F,? extends T> function)
Returns an iterable that applies function to each element of fromIterable.

The returned iterable's iterator supports remove() if the provided iterator does. After a successful remove() call, fromIterable no longer contains the corresponding element.



Copyright © 2006-2011 Google, Inc.. All Rights Reserved.