Class IteratorInstance<N,R>
- All Implemented Interfaces:
ValueIteration<R>
,VoidIteration
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final org.slf4j.Logger
private static final org.slf4j.Logger
private boolean
private @Nullable MutableDataSet
private final @NotNull Object
private boolean
private boolean
private IteratorInstance.Iteration<N>
private final @NotNull IterationConditions<N>
private N
private int
private @Nullable Stack<IteratorInstance.Iteration<N>>
private @NotNull Object
private int
private int
Fields inherited from interface com.vladsch.flexmark.tree.iteration.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 TypeMethodDescriptionvoid
doBreak
(int recursionLevel) Break out of given recursion levelvoid
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 loopprivate void
dropRecursions
(int iteration, boolean inclusive) int
getData()
Per loop instance data instance can be used to store context informationboolean
boolean
int
getMatch()
int
int
int
void
ifIncomplete
(@NotNull Runnable runnable) Run the passed code only if the current iteration is not completeboolean
boolean
boolean
boolean
void
iterate
(@NotNull ValueIterationConsumer<? super N, R> consumer) void
iterate
(@NotNull VoidIterationConsumer<? super N> consumer) private void
Recurse()
Unconditionally recurse into current elementvoid
Set result value and terminate all recursionsvoid
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
-
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:
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
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
- Specified by:
getResult
in interfaceValueIteration<N>
- Returns:
- current result value
-
Return
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
-
Recurse
private void Recurse()Unconditionally recurse into current element -
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
-
dropRecursions
private void dropRecursions(int iteration, boolean inclusive) -
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
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
-
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
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
- Specified by:
getDefaultValue
in interfaceValueIteration<N>
- Returns:
- defaultValue passed to loop instance
-