Class IteratorInstance<N,R>
java.lang.Object
com.vladsch.flexmark.tree.iteration.IteratorInstance<N,R>
- All Implemented Interfaces:
ValueIteration<R>, VoidIteration
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final org.slf4j.Loggerprivate static final org.slf4j.Loggerprivate booleanprivate @Nullable MutableDataSetprivate final @NotNull Objectprivate booleanprivate booleanprivate IteratorInstance.Iteration<N> private final @NotNull IterationConditions<N> private Nprivate intprivate @Nullable Stack<IteratorInstance.Iteration<N>> private @NotNull Objectprivate intprivate intFields inherited from interface VoidIteration
NULL -
Constructor Summary
ConstructorsConstructorDescriptionIteratorInstance(@NotNull IterationConditions<N> iterationConditions, @NotNull Predicate<? super N> filterPredicate, @NotNull Predicate<? super N> recursionPredicate, N element) IteratorInstance(@NotNull IterationConditions<N> iterationConditions, @NotNull Predicate<? super N> filterPredicate, @NotNull Predicate<? super N> recursionPredicate, N element, @NotNull Object defaultValue) -
Method Summary
Modifier and TypeMethodDescriptionvoiddoBreak(int recursionLevel) Break out of given recursion levelvoidComplete current iteration, ie.voiddoContinue(int recursionLevel) Continue with the next iteration of the given recursion levelvoiddoReturn()Break out of all recursion levels and return current result value for the loop if value loopprivate voiddropRecursions(int iteration, boolean inclusive) intgetData()Per loop instance data instance can be used to store context informationbooleanbooleanintgetMatch()intintintvoidifIncomplete(@NotNull Runnable runnable) Run the passed code only if the current iteration is not completebooleanbooleanbooleanbooleanvoiditerate(@NotNull ValueIterationConsumer<? super N, R> consumer) voiditerate(@NotNull VoidIterationConsumer<? super N> consumer) private voidRecurse()Unconditionally recurse into current elementvoidSet result value and terminate all recursionsvoidSet the result which will be returned by the loop if terminated withoutValueIteration.Return(Object)call.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface VoidIteration
doBreak, doContinue
-
Field Details
-
LOG_INFO
private static final org.slf4j.Logger LOG_INFO -
LOG_TRACE
private static final org.slf4j.Logger LOG_TRACE -
myIteration
-
myRecursions
-
myIterationConditions
-
myRecursionPredicate
-
myFilterPredicate
-
myTotalLoopCount
private int myTotalLoopCount -
myTotalAcceptCount
private int myTotalAcceptCount -
myMatch
-
myDataSet
-
myDefaultValue
-
myResult
-
myBreak
private boolean myBreak -
myHadRecurse
private boolean myHadRecurse -
myIsDefaultResult
private boolean myIsDefaultResult -
myMaxRecursions
private int myMaxRecursions
-
-
Constructor Details
-
IteratorInstance
-
IteratorInstance
-
-
Method Details
-
iterate
-
iterate
-
getHaveNext
public boolean getHaveNext()- Specified by:
getHaveNextin 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:
getHaveAcceptableNextin interfaceVoidIteration- Returns:
- true if have next element and it passes element filters.
NOTE:
ValueIterationConsumerAdapternot 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
Description copied from interface:ValueIterationSet the result which will be returned by the loop if terminated withoutValueIteration.Return(Object)call.- Specified by:
setResultin interfaceValueIteration<N>- Parameters:
value- value to return from the loop
-
getResult
- Specified by:
getResultin interfaceValueIteration<N>- Returns:
- current result value
-
Return
Description copied from interface:ValueIterationSet result value and terminate all recursions- Specified by:
Returnin interfaceValueIteration<N>- Parameters:
value- value to return for the result of the loop
-
Recurse
private void Recurse()Unconditionally recurse into current element -
doReturn
public void doReturn()Description copied from interface:VoidIterationBreak out of all recursion levels and return current result value for the loop if value loop- Specified by:
doReturnin interfaceVoidIteration
-
dropRecursions
private void dropRecursions(int iteration, boolean inclusive) -
doContinue
public void doContinue(int recursionLevel) Description copied from interface:VoidIterationContinue with the next iteration of the given recursion level- Specified by:
doContinuein interfaceVoidIteration- Parameters:
recursionLevel- 0 current, <0 previous recursion levels, gt;0 actual recursion level
-
doBreak
public void doBreak(int recursionLevel) Description copied from interface:VoidIterationBreak out of given recursion level- Specified by:
doBreakin interfaceVoidIteration- Parameters:
recursionLevel- 0 current, lt;0 previous recursion levels, gt;0 actual recursion level
-
getData
Description copied from interface:VoidIterationPer loop instance data instance can be used to store context informationExists between
VoidIterationConsumer.beforeStart(VoidIteration)andValueIterationConsumer.afterEnd(ValueIteration)for consumer andlifetime of
IteratorInstancefor caller ofTreeIterator.iterate(N, R, ValueIterationConsumer)- Specified by:
getDatain interfaceVoidIteration- Returns:
- per loop instance mutable data holder
-
getMatch
-
isComplete
public boolean isComplete()- Specified by:
isCompletein interfaceVoidIteration- Returns:
- true if current iteration is complete ie. had ( Break(), Continue(), Return(), Complete())
-
isIncomplete
public boolean isIncomplete()- Specified by:
isIncompletein interfaceVoidIteration- Returns:
- true if current iteration is not complete, ie. need to continue processing
-
ifIncomplete
Description copied from interface:VoidIterationRun the passed code only if the current iteration is not complete- Specified by:
ifIncompletein interfaceVoidIteration- Parameters:
runnable- to run
-
doComplete
public void doComplete()Description copied from interface:VoidIterationComplete 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:
doCompletein interfaceVoidIteration
-
isTerminated
public boolean isTerminated()- Specified by:
isTerminatedin interfaceVoidIteration- Returns:
- true if looping terminated by
VoidIteration.doReturn(), orVoidIteration.doBreak()of the last recursion level.
-
getLoopCount
public int getLoopCount()- Specified by:
getLoopCountin interfaceVoidIteration- Returns:
- times through the loop of the current recursion level, includes skipped elements due to filtering
-
getAcceptCount
public int getAcceptCount()- Specified by:
getAcceptCountin interfaceVoidIteration- Returns:
- total times consumer was invoked, ie. valid elements
-
getTotalLoopCount
public int getTotalLoopCount()- Specified by:
getTotalLoopCountin interfaceVoidIteration- Returns:
- current loop count across all recursions
-
getTotalAcceptCount
public int getTotalAcceptCount()- Specified by:
getTotalAcceptCountin interfaceVoidIteration- Returns:
- accept count across all recursions
-
getRecursionLevel
public int getRecursionLevel()- Specified by:
getRecursionLevelin 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:
isDefaultResultin 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
- Specified by:
getDefaultValuein interfaceValueIteration<N>- Returns:
- defaultValue passed to loop instance
-