|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.omnaest.utils.structure.iterator.IterableUtils
public class IterableUtils
Helper class related to Iterable instances
IteratorUtils| Nested Class Summary | |
|---|---|
static interface |
IterableUtils.IterableReplicator<E>
The IterableUtils.IterableReplicator allows to replicate elements to a given Collection |
| Constructor Summary | |
|---|---|
IterableUtils()
|
|
| Method Summary | ||
|---|---|---|
static
|
adapter(Iterable<? extends FROM> iterable,
ElementConverter<FROM,TO> elementConverter)
Returns a new Iterable instance which uses an Iterator adapter based on the resolved
Iterable.iterator() instance. |
|
static
|
chained(Iterable<E>... iterables)
Returns an Iterable which iterates through the Iterators of each given Iterable every time the own
Iterable.iterator() is called |
|
static
|
circular(Iterable<E> iterable)
Returns a new Iterable instance for the given one which will return a circular Iterator which circulates
endlessly. |
|
static
|
circular(Iterable<E> iterable,
long limit)
Returns a new Iterable instance for the given one which will return a circular Iterator. |
|
static
|
contains(Iterable<E> iterable,
E value)
Returns true if the given Iterable contains the given value. |
|
static
|
convert(Iterable<FROM> iterable,
ElementConverter<FROM,TO> elementConverter)
Converts a given Iterable to a new Iterable type using the given ElementConverter |
|
static
|
countEquals(Iterable<E> iterable,
E element)
Counts all elements within an Iterable which are equal to the given element. |
|
static
|
elementAt(Iterable<E> iterable,
int indexPosition)
Returns the element of the given Iterable at the given index position. |
|
static
|
empty()
Returns an Iterable which returns always a new empty Iterator |
|
static boolean |
equals(Iterable<?> iterable1,
Iterable<?> iterable2)
Returns true if... |
|
static
|
filtered(Iterable<E> iterable,
BitSet filter)
Returns an Iterable where the Iterable.iterator() instance returns only those elements where the respective
bit within the filter BitSet is set to true |
|
static
|
firstElement(Iterable<E> iterable)
Returns the first element of the given Iterable |
|
static int |
hashCode(Iterable<?> iterable)
Generates a Object.hashCode() for a given Iterable and its elements. |
|
static boolean |
isEmpty(Iterable<?> iterable)
isEmpty( null ) = true isEmpty( Arrays.asList()) = true isEmpty( Arrays.asList("") ) = false |
|
static boolean |
isIterableType(Class<?> type)
Returns true if the given type is assignable to the Iterable interface |
|
static
|
lastElement(Iterable<E> iterable)
Returns the last element of the given Iterable |
|
static
|
replicate(Iterable<E> iterable)
Returns a IterableUtils.IterableReplicator |
|
static
|
replicate(Iterator<E> iterator)
Returns a IterableUtils.IterableReplicator |
|
static
|
roundRobin(Iterable<E>... iterables)
Similar to IteratorUtils.roundRobin(Iterator...) |
|
static int |
size(Iterable<?> iterable)
Resolves the size of an Iterable by iterating over it and counting the elements. |
|
static
|
toCountedElementsMap(Iterable<E> iterable)
Returns a Map containing the Set of elements as keys and the count of each element as value. |
|
static
|
valueOf(E... elements)
Returns an Iterable over the given elements |
|
static
|
valueOf(ElementStream<E> elementStream)
Returns an Iterable on an ElementStream |
|
static
|
valueOf(Factory<Iterator<E>> iteratorFactory)
Returns a new Iterable based on a given Factory for Iterators |
|
static
|
valueOf(Iterator<E> iterator)
Returns a new instance of an Iterable which returns the given Iterator instance |
|
static
|
valueOf(Iterator<E> iterator,
boolean replicate)
Returns an Factory of Iterator instances which is based on an internal List buffer which will contain
the elements of the given Iterator. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public IterableUtils()
| Method Detail |
|---|
public static <FROM,TO> Iterable<TO> adapter(Iterable<? extends FROM> iterable,
ElementConverter<FROM,TO> elementConverter)
Iterable instance which uses an Iterator adapter based on the resolved
Iterable.iterator() instance.
iterable - IterableelementConverter - ElementConverter
public static <E> Iterable<E> circular(Iterable<E> iterable)
Iterable instance for the given one which will return a circular Iterator which circulates
endlessly.Iterable has to return new Iterator instances otherwise this will cause
an infinite loop.
iterable -
circular(Iterable)
public static <E> Iterable<E> circular(Iterable<E> iterable,
long limit)
Iterable instance for the given one which will return a circular Iterator. The Iterator
will stop additionally if the given limit of cycles is reached. If no limit should be used set the parameter to -1
iterable - limit -
circular(Iterable)
public static <FROM,TO> Iterable<TO> convert(Iterable<FROM> iterable,
ElementConverter<FROM,TO> elementConverter)
Iterable to a new Iterable type using the given ElementConverter
iterable - elementConverter -
public static <E> int countEquals(Iterable<E> iterable,
E element)
Iterable which are equal to the given element.
iterable - element -
public static <E> E elementAt(Iterable<E> iterable,
int indexPosition)
Iterable at the given index position. Does never throw an Exception instead
returns null if no element could be resolved.
iterable - indexPosition -
public static <E> Iterable<E> empty()
Iterable which returns always a new empty Iterator
IteratorUtils.empty()
public static boolean equals(Iterable<?> iterable1,
Iterable<?> iterable2)
iterable1 - iterable2 -
public static <E> Iterable<E> filtered(Iterable<E> iterable,
BitSet filter)
Iterable where the Iterable.iterator() instance returns only those elements where the respective
bit within the filter BitSet is set to true
iterable - filter -
Iterablepublic static <E> E firstElement(Iterable<E> iterable)
Iterable
iterable -
public static int hashCode(Iterable<?> iterable)
Object.hashCode() for a given Iterable and its elements. The hash code respects the hash codes of
the element instances and their order.
iterable -
public static boolean isEmpty(Iterable<?> iterable)
isEmpty( null ) = true
isEmpty( Arrays.asList()) = true
isEmpty( Arrays.asList("") ) = false
iterable -
public static <E> E lastElement(Iterable<E> iterable)
Iterable
iterable -
public static int size(Iterable<?> iterable)
Iterable by iterating over it and counting the elements.
iterable -
public static <E> Iterable<E> valueOf(ElementStream<E> elementStream)
Iterable on an ElementStream
elementStream -
public static <E> Iterable<E> valueOf(Factory<Iterator<E>> iteratorFactory)
Iterable based on a given Factory for Iterators
iteratorFactory -
public static <E> Iterable<E> valueOf(Iterator<E> iterator)
Iterable which returns the given Iterator instance
iterator - Iterator
valueOf(Iterator, boolean)public static boolean isIterableType(Class<?> type)
Iterable interface
type -
public static <E> Iterable<E> valueOf(E... elements)
Iterable over the given elements
elements -
public static <E> Map<E,Integer> toCountedElementsMap(Iterable<E> iterable)
Map containing the Set of elements as keys and the count of each element as value.
iterable -
Map
public static <E> boolean contains(Iterable<E> iterable,
E value)
Iterable contains the given value. If the given Iterable is null, false is
returned.
iterable - value -
public static <E> IterableUtils.IterableReplicator<E> replicate(Iterable<E> iterable)
IterableUtils.IterableReplicator
iterable - Iterable
IterableUtils.IterableReplicator instance
public static <E> Iterable<E> valueOf(Iterator<E> iterator,
boolean replicate)
Factory of Iterator instances which is based on an internal List buffer which will contain
the elements of the given Iterator. This allows to replicate the content of an Iterator multiple times.
iterator - Iteratorreplicate - if true, the Iterable will return always a new Iterator instance with the same elements based on an
internal immutable List buffer, otherwise only the same given instance without using a buffer.
Factory instance for IteratorsvalueOf(Iterator)public static <E> IterableUtils.IterableReplicator<E> replicate(Iterator<E> iterator)
IterableUtils.IterableReplicator
iterator - Iterator
IterableUtils.IterableReplicator instancepublic static <E> Iterable<E> chained(Iterable<E>... iterables)
Iterable which iterates through the Iterators of each given Iterable every time the own
Iterable.iterator() is called
iterables -
ChainedIterablepublic static <E> Iterable<E> roundRobin(Iterable<E>... iterables)
IteratorUtils.roundRobin(Iterator...)
iterables -
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||