Class CloseableUncertainIterator<T>
java.lang.Object
com.github.basking2.sdsai.itrex.iterators.splitjoin.CloseableUncertainIterator<T>
- All Implemented Interfaces:
UncertainIterator<T>
,AutoCloseable
public class CloseableUncertainIterator<T>
extends Object
implements UncertainIterator<T>, AutoCloseable
An uncertain iterator that may be closed, signalling it will receive or generate no more elements.
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.github.basking2.sdsai.itrex.iterators.splitjoin.UncertainIterator
UncertainIterator.HAS_NEXT
-
Constructor Summary
ConstructorDescriptionCallsCloseableUncertainIterator(Queue)
with aConcurrentLinkedQueue
instance.CloseableUncertainIterator
(Queue<T> queue) Construct this using the given queue for data. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
hasNext()
Return TRUE if elements are ready, FALSE if they are not or MAYBE if we do not know.next()
Get the next value or throwNoSuchElementException
.boolean
This callsQueue.offer(Object)
on the backing queue and returns the result.
-
Constructor Details
-
CloseableUncertainIterator
Construct this using the given queue for data. When the queue has datahasNext()
will reeturnUncertainIterator.HAS_NEXT.TRUE
. When the queue is emptyhasNext()
will returnUncertainIterator.HAS_NEXT.MAYBE
. When the queue is empty and this object has beenclose()
ed, thenUncertainIterator.HAS_NEXT.FALSE
is returned.- Parameters:
queue
- The queue to read elements from.
-
CloseableUncertainIterator
public CloseableUncertainIterator()CallsCloseableUncertainIterator(Queue)
with aConcurrentLinkedQueue
instance.
-
-
Method Details
-
next
Description copied from interface:UncertainIterator
Get the next value or throwNoSuchElementException
.- Specified by:
next
in interfaceUncertainIterator<T>
- Returns:
- The next element.
-
hasNext
Description copied from interface:UncertainIterator
Return TRUE if elements are ready, FALSE if they are not or MAYBE if we do not know. If no other sources of data are available and the state of the computation system cannot be changed, then MAYBE should be considered FALSE.- Specified by:
hasNext
in interfaceUncertainIterator<T>
- Returns:
- TRUE if elements are ready, FALSE if they are not or MAYBE if we do not know.
-
close
- Specified by:
close
in interfaceAutoCloseable
- Throws:
Exception
-
offer
This callsQueue.offer(Object)
on the backing queue and returns the result. If the user would like to use custom enqueuing semantics they should provide their own thread-safe queue to the constructor.- Parameters:
t
- The element to enqueue.- Returns:
- True on success, false otherwise.
-