E
- Type of iterated elements from the base CloseableIterator
R
- Type of transformed elements available for retrieval@PublicAPI @Beta public class MemoizingIterator<E,R> extends CloseableAbstractIterator<OrderedElement<E>> implements MemoizedSparseCollection<R>
CloseableIterator
with the availability of retrieval of a transformation of the iterated elements.
Typical application is to remember SMILES structure sources of Molecule
s imported with a MolImporter
.
It is recommended to access the memoized items use only after AbstractIterator.hasNext()
is false
. Otherwise new
structure might be collected upon the next AbstractIterator.hasNext()
or AbstractIterator.next()
invocation.
Please note that this class is marked with @Beta annotation, so it can be subject of incompatible changes or removal in later releases.
Modifier and Type | Method and Description |
---|---|
void |
close() |
protected OrderedElement<E> |
computeNext() |
R |
getMemoized(int i)
Get a non-missing memoiozed.
|
Function<Integer,R> |
getMemoizedFunction()
Function to access captured non-missing memoizeds. |
Optional<R> |
getMemoizedIfPresent(int i)
Get item when present.
|
R |
getMemoizedOrDefault(int i,
R defaultValue)
Get item when present or a default value when missing.
|
Function<Integer,R> |
getMemoizedOrDefaultFunction(R defaultValue)
Function to access present items with a default value for missing items. |
int |
size()
Collected items count.
|
endOfData, hasNext, next, peek
remove
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
transform
forEachRemaining, hasNext, next, remove
protected OrderedElement<E> computeNext()
computeNext
in class AbstractIterator<OrderedElement<E>>
public void close()
close
in interface CloseableIterator<OrderedElement<E>>
close
in interface Closeable
close
in interface AutoCloseable
public int size()
MemoizedSparseCollection
size
in interface MemoizedSparseCollection<R>
public Optional<R> getMemoizedIfPresent(int i)
MemoizedSparseCollection
getMemoizedIfPresent
in interface MemoizedSparseCollection<R>
i
- Index which refers to either a missing or a present elementpublic R getMemoized(int i)
MemoizedSparseCollection
getMemoized
in interface MemoizedSparseCollection<R>
i
- Index of an item which is not missingpublic Function<Integer,R> getMemoizedFunction()
MemoizedSparseCollection
Function
to access captured non-missing memoizeds.getMemoizedFunction
in interface MemoizedSparseCollection<R>
Function
of Integer
to the memoized type T
which delegates to
MemoizedSparseCollection.getMemoized(int)
public R getMemoizedOrDefault(int i, R defaultValue)
MemoizedSparseCollection
getMemoizedOrDefault
in interface MemoizedSparseCollection<R>
i
- Index which refers to either a missing or a present elementdefaultValue
- value for return when missingpublic Function<Integer,R> getMemoizedOrDefaultFunction(R defaultValue)
MemoizedSparseCollection
Function
to access present items with a default value for missing items.getMemoizedOrDefaultFunction
in interface MemoizedSparseCollection<R>
defaultValue
- Value to return for missing items.Function
of Integer
to the memoized type T
which delegates to
MemoizedSparseCollection.getMemoizedOrDefault(int, java.lang.Object)