Class IteratorInstance<N,R>
- java.lang.Object
-
- com.vladsch.flexmark.tree.iteration.IteratorInstance<N,R>
-
- All Implemented Interfaces:
ValueIteration<R>
,VoidIteration
public final class IteratorInstance<N,R> extends java.lang.Object implements ValueIteration<R>
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
IteratorInstance.Iteration<V>
-
Field Summary
-
Fields inherited from interface com.vladsch.flexmark.tree.iteration.VoidIteration
NULL
-
-
Constructor Summary
Constructors Constructor Description IteratorInstance(IterationConditions<N> iterationConditions, java.util.function.Predicate<? super N> filterPredicate, java.util.function.Predicate<? super N> recursionPredicate, N element)
IteratorInstance(IterationConditions<N> iterationConditions, java.util.function.Predicate<? super N> filterPredicate, java.util.function.Predicate<? super N> recursionPredicate, N element, java.lang.Object defaultValue)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
doBreak(int recursionLevel)
Break out of given recursion levelvoid
doComplete()
Complete current iteration, ie.void
doContinue(int recursionLevel)
Continue with the next iteration of the given recursion levelvoid
doReturn()
Break out of all recursion levels and return current result value for the loop if value loopint
getAcceptCount()
MutableDataHolder
getData()
Per loop instance data instance can be used to store context informationR
getDefaultValue()
boolean
getHaveAcceptableNext()
boolean
getHaveNext()
int
getLoopCount()
N
getMatch()
int
getRecursionLevel()
R
getResult()
int
getTotalAcceptCount()
int
getTotalLoopCount()
void
ifIncomplete(java.lang.Runnable runnable)
Run the passed code only if the current iteration is not completeboolean
isComplete()
boolean
isDefaultResult()
boolean
isIncomplete()
boolean
isTerminated()
void
iterate(ValueIterationConsumer<? super N,R> consumer)
void
iterate(VoidIterationConsumer<? super N> consumer)
void
Return(java.lang.Object value)
Set result value and terminate all recursionsvoid
setResult(java.lang.Object value)
Set the result which will be returned by the loop if terminated withoutValueIteration.Return(Object)
call.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.vladsch.flexmark.tree.iteration.VoidIteration
doBreak, doContinue
-
-
-
-
Constructor Detail
-
IteratorInstance
public IteratorInstance(@NotNull IterationConditions<N> iterationConditions, @NotNull java.util.function.Predicate<? super N> filterPredicate, @NotNull java.util.function.Predicate<? super N> recursionPredicate, @NotNull N element)
-
IteratorInstance
public IteratorInstance(@NotNull IterationConditions<N> iterationConditions, @NotNull java.util.function.Predicate<? super N> filterPredicate, @NotNull java.util.function.Predicate<? super N> recursionPredicate, @NotNull N element, @NotNull java.lang.Object defaultValue)
-
-
Method Detail
-
iterate
public void iterate(@NotNull VoidIterationConsumer<? super N> consumer)
-
iterate
public void iterate(@NotNull ValueIterationConsumer<? super N,R> consumer)
-
getHaveNext
public boolean getHaveNext()
- Specified by:
getHaveNext
in interfaceVoidIteration
- Returns:
- true if have next element, does not mean it matches filters, just raw next from loop iterator, fast check
-
getHaveAcceptableNext
public boolean getHaveAcceptableNext()
- Specified by:
getHaveAcceptableNext
in interfaceVoidIteration
- Returns:
- true if have next element and it passes element filters.
NOTE:
ValueIterationConsumerAdapter
not invoked. It is part of the consumer.accept() call hierarchy and can have code side-effects. Only predicate filters are tested. This does not mean the final consumer will see this value.
-
setResult
public void setResult(@NotNull java.lang.Object value)
Description copied from interface:ValueIteration
Set the result which will be returned by the loop if terminated withoutValueIteration.Return(Object)
call.- Specified by:
setResult
in interfaceValueIteration<N>
- Parameters:
value
- value to return from the loop
-
getResult
@NotNull public R getResult()
- Specified by:
getResult
in interfaceValueIteration<N>
- Returns:
- current result value
-
Return
public void Return(@NotNull java.lang.Object value)
Description copied from interface:ValueIteration
Set result value and terminate all recursions- Specified by:
Return
in interfaceValueIteration<N>
- Parameters:
value
- value to return for the result of the loop
-
doReturn
public void doReturn()
Description copied from interface:VoidIteration
Break out of all recursion levels and return current result value for the loop if value loop- Specified by:
doReturn
in interfaceVoidIteration
-
doContinue
public void doContinue(int recursionLevel)
Description copied from interface:VoidIteration
Continue with the next iteration of the given recursion level- Specified by:
doContinue
in interfaceVoidIteration
- Parameters:
recursionLevel
- 0 current, <0 previous recursion levels, gt;0 actual recursion level
-
doBreak
public void doBreak(int recursionLevel)
Description copied from interface:VoidIteration
Break out of given recursion level- Specified by:
doBreak
in interfaceVoidIteration
- Parameters:
recursionLevel
- 0 current, lt;0 previous recursion levels, gt;0 actual recursion level
-
getData
public MutableDataHolder getData()
Description copied from interface:VoidIteration
Per loop instance data instance can be used to store context informationExists between
VoidIterationConsumer.beforeStart(VoidIteration)
andValueIterationConsumer.afterEnd(ValueIteration)
for consumer andlifetime of
IteratorInstance
for caller ofTreeIterator.iterate(N, R, com.vladsch.flexmark.tree.iteration.ValueIterationConsumer<? super N, R>)
- Specified by:
getData
in interfaceVoidIteration
- Returns:
- per loop instance mutable data holder
-
getMatch
@Nullable public N getMatch()
-
isComplete
public boolean isComplete()
- Specified by:
isComplete
in interfaceVoidIteration
- Returns:
- true if current iteration is complete ie. had ( Break(), Continue(), Return(), Complete())
-
isIncomplete
public boolean isIncomplete()
- Specified by:
isIncomplete
in interfaceVoidIteration
- Returns:
- true if current iteration is not complete, ie. need to continue processing
-
ifIncomplete
public void ifIncomplete(@NotNull java.lang.Runnable runnable)
Description copied from interface:VoidIteration
Run the passed code only if the current iteration is not complete- Specified by:
ifIncomplete
in interfaceVoidIteration
- Parameters:
runnable
- to run
-
doComplete
public void doComplete()
Description copied from interface:VoidIteration
Complete current iteration, ie. isComplete() will report true and isIncomplete() falsePurely a convenience feature to use without needing to track if break or continue have been executed
- Specified by:
doComplete
in interfaceVoidIteration
-
isTerminated
public boolean isTerminated()
- Specified by:
isTerminated
in interfaceVoidIteration
- Returns:
- true if looping terminated by
VoidIteration.doReturn()
, orVoidIteration.doBreak()
of the last recursion level.
-
getLoopCount
public int getLoopCount()
- Specified by:
getLoopCount
in interfaceVoidIteration
- Returns:
- times through the loop of the current recursion level, includes skipped elements due to filtering
-
getAcceptCount
public int getAcceptCount()
- Specified by:
getAcceptCount
in interfaceVoidIteration
- Returns:
- total times consumer was invoked, ie. valid elements
-
getTotalLoopCount
public int getTotalLoopCount()
- Specified by:
getTotalLoopCount
in interfaceVoidIteration
- Returns:
- current loop count across all recursions
-
getTotalAcceptCount
public int getTotalAcceptCount()
- Specified by:
getTotalAcceptCount
in interfaceVoidIteration
- Returns:
- accept count across all recursions
-
getRecursionLevel
public int getRecursionLevel()
- Specified by:
getRecursionLevel
in interfaceVoidIteration
- Returns:
- count of recursion level, can use in Break(recursionLevel) or Continue(recursionLevel) to break/continue a particular recursion
-
isDefaultResult
public boolean isDefaultResult()
- Specified by:
isDefaultResult
in interfaceValueIteration<N>
- Returns:
- true if the current loop result value was never set (ie. only set at loop instantiation with
defaultValue)
NOTE: does not test current value with equality to default value, set by
ValueIteration.setResult(Object)
orValueIteration.Return(Object)
-
getDefaultValue
@NotNull public R getDefaultValue()
- Specified by:
getDefaultValue
in interfaceValueIteration<N>
- Returns:
- defaultValue passed to loop instance
-
-