Class IterativeCondition<T>
- All Implemented Interfaces:
Serializable,org.apache.flink.api.common.functions.Function
- Direct Known Subclasses:
RichIterativeCondition,SimpleCondition
NFA.
A condition can be a simple filter or a more complex condition that iterates over the
previously accepted elements in the pattern and decides to accept a new element or not based on
some statistic over these elements. In the former case, the condition should extend the SimpleCondition class. In the later, the condition should extend this class, which gives you
also access to the previously accepted elements through a IterativeCondition.Context.
An iterative condition that accepts an element if i) its name is middle, and ii) the sum of
the prices of all accepted elements is less than 5 would look like:
private class MyCondition extends IterativeCondition<Event> {
@Override
public boolean filter(Event value, Context<Event> ctx) throws Exception {
if (!value.getName().equals("middle")) {
return false;
}
double sum = 0.0;
for (Event e: ctx.getEventsForPattern("middle")) {
sum += e.getPrice();
}
sum += value.getPrice();
return Double.compare(sum, 5.0) <= 0;
}
}
ATTENTION: The call to getEventsForPattern(...) has to find the elements that belong to the pattern among the elements
stored by the NFA. The cost of this operation can vary, so when implementing your condition, try
to minimize the times the method is called.- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceThe context used when evaluating thecondition. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract booleanfilter(T value, IterativeCondition.Context<T> ctx) The filter function that evaluates the predicate.
-
Constructor Details
-
IterativeCondition
public IterativeCondition()
-
-
Method Details
-
filter
The filter function that evaluates the predicate.IMPORTANT: The system assumes that the function does not modify the elements on which the predicate is applied. Violating this assumption can lead to incorrect results.
- Parameters:
value- The value to be tested.ctx- TheIterativeCondition.Contextused for the evaluation of the function and provides access to the already accepted events in the pattern (seeIterativeCondition.Context.getEventsForPattern(String)).- Returns:
truefor values that should be retained,falsefor values to be filtered out.- Throws:
Exception- This method may throw exceptions. Throwing an exception will cause the operation to fail and may trigger recovery.
-