Class Iterables
- java.lang.Object
-
- com.googlecode.concurrenttrees.common.Iterables
-
public class Iterables extends java.lang.Object
Provides methods to convertIterable
s toList
s andSet
s. This class is mostly provided for backwards compatibility in applications which were programmed against concurrent-trees 1.0.0, in which the tree APIs returned lists and sets instead of lazily-evaluated iterables. Note that in applications which would have simply iterated through the lists and sets returned by the old APIs, the new approach of returning lazy iterables is more efficient. Applications can iterate the iterables returned in exactly the same manner, and results will be the same. These methods are provided for convenience in applications which actually relied on List and Set-specific features in the objects which were returned. Most methods in this class are somewhat similar to utilities in Google Guava; but are provided here to avoid a dependency on Guava. Applications could use either these methods or Guava.
-
-
Constructor Summary
Constructors Constructor Description Iterables()
Private constructor, not used.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static int
count(java.lang.Iterable<?> iterable)
Counts the number of elements returned by the givenIterable
.static <T> java.util.List<T>
toList(java.lang.Iterable<T> iterable)
Copies elements from the givenIterable
into a newList
.static <T> java.util.Set<T>
toSet(java.lang.Iterable<T> iterable)
Copies elements from the givenIterable
into a newSet
.static java.lang.String
toString(java.lang.Iterable<?> iterable)
Returns a string representation of elements returned by the givenIterable
.
-
-
-
Method Detail
-
toList
public static <T> java.util.List<T> toList(java.lang.Iterable<T> iterable)
Copies elements from the givenIterable
into a newList
. The iteration order of the list returned, will be the same as that of the iterable. Be aware of the memory implications of copying objects from a lazy iterable into a collection; usually it's better to just work with the iterable directly (i.e. by iterating it).- Type Parameters:
T
- The type of elements returned by the iterable- Parameters:
iterable
- Provides elements to be copied into a new list- Returns:
- A new
List
which contains the elements which were returned by the iterable
-
toSet
public static <T> java.util.Set<T> toSet(java.lang.Iterable<T> iterable)
Copies elements from the givenIterable
into a newSet
. The iteration order of the set returned, will be the same as that of the iterable. Be aware of the memory implications of copying objects from a lazy iterable into a collection; usually it's better to just work with the iterable directly (i.e. by iterating it).- Type Parameters:
T
- The type of elements returned by the iterable- Parameters:
iterable
- Provides elements to be copied into a new set- Returns:
- A new
Set
which contains the elements which were returned by the iterable
-
toString
public static java.lang.String toString(java.lang.Iterable<?> iterable)
Returns a string representation of elements returned by the givenIterable
.- Parameters:
iterable
- Provides elements whosetoString
representations should be included in the string- Returns:
- A string representation of elements returned by the given
Iterable
-
count
public static int count(java.lang.Iterable<?> iterable)
Counts the number of elements returned by the givenIterable
.- Parameters:
iterable
- Provides elements to be counted- Returns:
- The number of elements returned by the iterable
-
-