Package com.chemaxon.calculations.io
Class MemoizingIterator<E,R>
- java.lang.Object
-
- com.google.common.collect.UnmodifiableIterator<T>
-
- com.google.common.collect.AbstractIterator<T>
-
- com.chemaxon.calculations.io.CloseableAbstractIterator<OrderedElement<E>>
-
- com.chemaxon.calculations.io.MemoizingIterator<E,R>
-
- Type Parameters:
E
- Type of iterated elements from the baseCloseableIterator
R
- Type of transformed elements available for retrieval
- All Implemented Interfaces:
CloseableIterator<OrderedElement<E>>
,MemoizedSparseCollection<R>
,Closeable
,AutoCloseable
,Iterator<OrderedElement<E>>
- Direct Known Subclasses:
SmilesMemoizingMoleculeIterator
@PublicAPI @Beta public class MemoizingIterator<E,R> extends com.chemaxon.calculations.io.CloseableAbstractIterator<OrderedElement<E>> implements MemoizedSparseCollection<R>
Decorate aCloseableIterator
with the availability of retrieval of a transformation of the iterated elements. Typical application is to remember SMILES structure sources ofMolecule
s imported with aMolImporter
.It is recommended to access the memoized items use only after
AbstractIterator.hasNext()
isfalse
. Otherwise new structure might be collected upon the nextAbstractIterator.hasNext()
orAbstractIterator.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.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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.-
Methods inherited from class com.google.common.collect.AbstractIterator
endOfData, hasNext, next, peek
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.chemaxon.calculations.io.CloseableIterator
forward, limit, limit, transform, transformIterator, transformMultipleElements
-
Methods inherited from interface java.util.Iterator
forEachRemaining, hasNext, next, remove
-
-
-
-
Method Detail
-
computeNext
protected OrderedElement<E> computeNext()
- Specified by:
computeNext
in classcom.google.common.collect.AbstractIterator<OrderedElement<E>>
-
close
public void close()
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in interfaceCloseableIterator<E>
-
size
public int size()
Description copied from interface:MemoizedSparseCollection
Collected items count. Including missing items.- Specified by:
size
in interfaceMemoizedSparseCollection<E>
- Returns:
- collected items count
-
getMemoizedIfPresent
public Optional<R> getMemoizedIfPresent(int i)
Description copied from interface:MemoizedSparseCollection
Get item when present.- Specified by:
getMemoizedIfPresent
in interfaceMemoizedSparseCollection<E>
- Parameters:
i
- Index which refers to either a missing or a present element- Returns:
- Collected remembered element
-
getMemoized
public R getMemoized(int i)
Description copied from interface:MemoizedSparseCollection
Get a non-missing memoiozed.- Specified by:
getMemoized
in interfaceMemoizedSparseCollection<E>
- Parameters:
i
- Index of an item which is not missing- Returns:
- Collected remembered item
-
getMemoizedFunction
public Function<Integer,R> getMemoizedFunction()
Description copied from interface:MemoizedSparseCollection
Function
to access captured non-missing memoizeds.- Specified by:
getMemoizedFunction
in interfaceMemoizedSparseCollection<E>
- Returns:
- A
Function
ofInteger
to the memoized typeT
which delegates toMemoizedSparseCollection.getMemoized(int)
-
getMemoizedOrDefault
public R getMemoizedOrDefault(int i, R defaultValue)
Description copied from interface:MemoizedSparseCollection
Get item when present or a default value when missing.- Specified by:
getMemoizedOrDefault
in interfaceMemoizedSparseCollection<E>
- Parameters:
i
- Index which refers to either a missing or a present elementdefaultValue
- value for return when missing- Returns:
- Collected remembered element or default when missing
-
getMemoizedOrDefaultFunction
public Function<Integer,R> getMemoizedOrDefaultFunction(R defaultValue)
Description copied from interface:MemoizedSparseCollection
Function
to access present items with a default value for missing items.- Specified by:
getMemoizedOrDefaultFunction
in interfaceMemoizedSparseCollection<E>
- Parameters:
defaultValue
- Value to return for missing items.- Returns:
- A
Function
ofInteger
to the memoized typeT
which delegates toMemoizedSparseCollection.getMemoizedOrDefault(int, java.lang.Object)
-
-