Some common iterators for Java
Overview
This is a collection of companion Iterators
for some commonly useful Iterable
implementations for the following use cases:
This library is an extensions of the corresponding library for Java, that contains Iterators
for Android specific data structures.
This library is hosted in the Maven Central Repository. You can use it with the following coordinates:
compile 'net.markenwerk:android-commons-iterators:3.1.0'
Consult the usage description and Javadoc for further information.
Usage
Iterating over sparse arrays
This library provides the following Iterators
that take existing sparse arrays and yield all elements of the given array wrapped in an Entry
:
LongSparseArrayIterator
SparseArrayIterator
SparseBooleanArrayIterator
SparseIntegerArrayIterator
SparseLongArrayIterator
SparseArray<Foo> sparseArray = ...
// yields every foo from sparseArray
Iterator<Entry<Integer, Foo>> arraytIterator = new SparseArrayIterator<>(sparseArray);
Iterating over other objects
This library provides the generic PairIterator
that takes and existing Pair
and yields both contained values.
Pair<Foo, Foo> pair = ...
// yields both foos from pair
Iterator<Foo> pairIterator = new PairIterator<>(pair);