Class Iterables
java.lang.Object
com.googlecode.concurrenttrees.common.Iterables
Provides methods to convert
Iterable
s to List
s and Set
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 Details
-
Iterables
Iterables()Private constructor, not used.
-
-
Method Details
-
toList
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
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
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
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
-