Class Pattern<T,F extends T>
- Type Parameters:
T- Base type of the elements appearing in the patternF- Subtype of T to which the current pattern operator is constrained
- Direct Known Subclasses:
GroupPattern
A pattern definition is used by NFACompiler to
create a NFA.
Pattern<T, F> pattern = Pattern.<T>begin("start")
.next("middle").subtype(F.class)
.followedBy("end").where(new MyCondition());
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedPattern(String name, Pattern<T, ? extends T> previous, Quantifier.ConsumingStrategy consumingStrategy, AfterMatchSkipStrategy afterMatchSkipStrategy) -
Method Summary
Modifier and TypeMethodDescriptionApplicable only toQuantifier.looping(ConsumingStrategy)andQuantifier.times(ConsumingStrategy)patterns, this option allows more flexibility to the matching events.static <X> Pattern<X,X> Starts a new pattern sequence.static <X> Pattern<X,X> begin(String name, AfterMatchSkipStrategy afterMatchSkipStrategy) Starts a new pattern sequence.static <T,F extends T>
GroupPattern<T,F> Starts a new pattern sequence.static <T,F extends T>
GroupPattern<T,F> begin(Pattern<T, F> group, AfterMatchSkipStrategy afterMatchSkipStrategy) Starts a new pattern sequence.Works in conjunction withoneOrMore()ortimes(int).followedBy(String name) Appends a new pattern to the existing one.followedBy(Pattern<T, F> group) Appends a new group pattern to the existing one.followedByAny(String name) Appends a new pattern to the existing one.followedByAny(Pattern<T, F> group) Appends a new group pattern to the existing one.getName()getTimes()getWindowSize(WithinType withinType) greedy()Specifies that this pattern is greedy.Appends a new pattern to the existing one.Appends a new group pattern to the existing one.notFollowedBy(String name) Appends a new pattern to the existing one.Appends a new pattern to the existing one.Specifies that this pattern can occurone or moretimes.Specifies that this pattern can occurone or moretimes and time interval corresponds to the maximum time gap between previous and current event for each times.optional()Specifies that this pattern is optional for a final match of the pattern sequence to happen.or(IterativeCondition<F> condition) Adds a condition that has to be satisfied by an event in order to be considered a match.Applies a subtype constraint on the current pattern.times(int times) Specifies exact number of times that this pattern should be matched.times(int from, int to) Specifies that the pattern can occur between from and to times.Specifies that the pattern can occur between from and to times with time interval corresponds to the maximum time gap between previous and current event for each times.Specifies exact number of times that this pattern should be matched and time interval corresponds to the maximum time gap between previous and current event for each times.timesOrMore(int times) Specifies that this pattern can occur the specified times at least.timesOrMore(int times, Duration windowTime) Specifies that this pattern can occur the specified times at least with interval corresponds to the maximum time gap between previous and current event for each times.toString()until(IterativeCondition<F> untilCondition) Applies a stop condition for a looping state.where(IterativeCondition<F> condition) Adds a condition that has to be satisfied by an event in order to be considered a match.Defines the maximum time interval in which a matching pattern has to be completed in order to be considered valid.within(Duration windowTime, WithinType withinType) Defines the maximum time interval in which a matching pattern has to be completed in order to be considered valid.
-
Constructor Details
-
Pattern
protected Pattern(String name, Pattern<T, ? extends T> previous, Quantifier.ConsumingStrategy consumingStrategy, AfterMatchSkipStrategy afterMatchSkipStrategy)
-
-
Method Details
-
getPrevious
-
getTimes
-
getName
-
getWindowSize
-
getWindowSize
-
getQuantifier
-
getCondition
-
getUntilCondition
-
begin
Starts a new pattern sequence. The provided name is the one of the initial pattern of the new sequence. Furthermore, the base type of the event sequence is set.- Type Parameters:
X- Base type of the event pattern- Parameters:
name- The name of starting pattern of the new pattern sequence- Returns:
- The first pattern of a pattern sequence
-
begin
Starts a new pattern sequence. The provided name is the one of the initial pattern of the new sequence. Furthermore, the base type of the event sequence is set.- Type Parameters:
X- Base type of the event pattern- Parameters:
name- The name of starting pattern of the new pattern sequenceafterMatchSkipStrategy- theAfterMatchSkipStrategy.SkipStrategyto use after each match.- Returns:
- The first pattern of a pattern sequence
-
where
Adds a condition that has to be satisfied by an event in order to be considered a match. If another condition has already been set, the new one is going to be combined with the previous with a logicalAND. In other case, this is going to be the only condition.- Parameters:
condition- The condition as anIterativeCondition.- Returns:
- The pattern with the new condition is set.
-
or
Adds a condition that has to be satisfied by an event in order to be considered a match. If another condition has already been set, the new one is going to be combined with the previous with a logicalOR. In other case, this is going to be the only condition.- Parameters:
condition- The condition as anIterativeCondition.- Returns:
- The pattern with the new condition is set.
-
subtype
Applies a subtype constraint on the current pattern. This means that an event has to be of the given subtype in order to be matched.- Type Parameters:
S- Type of the subtype- Parameters:
subtypeClass- Class of the subtype- Returns:
- The same pattern with the new subtype constraint
-
until
Applies a stop condition for a looping state. It allows cleaning the underlying state.- Parameters:
untilCondition- a condition an event has to satisfy to stop collecting events into looping state- Returns:
- The same pattern with applied untilCondition
-
within
Defines the maximum time interval in which a matching pattern has to be completed in order to be considered valid. This interval corresponds to the maximum time gap between first and the last event.- Parameters:
windowTime- Time of the matching window- Returns:
- The same pattern operator with the new window length
-
within
Defines the maximum time interval in which a matching pattern has to be completed in order to be considered valid. This interval corresponds to the maximum time gap between events.- Parameters:
withinType- Type of the within interval between eventswindowTime- Time of the matching window- Returns:
- The same pattern operator with the new window length
-
next
Appends a new pattern to the existing one. The new pattern enforces strict temporal contiguity. This means that the whole pattern sequence matches only if an event which matches this pattern directly follows the preceding matching event. Thus, there cannot be any events in between two matching events.- Parameters:
name- Name of the new pattern- Returns:
- A new pattern which is appended to this one
-
notNext
Appends a new pattern to the existing one. The new pattern enforces that there is no event matching this pattern right after the preceding matched event.- Parameters:
name- Name of the new pattern- Returns:
- A new pattern which is appended to this one
-
followedBy
Appends a new pattern to the existing one. The new pattern enforces non-strict temporal contiguity. This means that a matching event of this pattern and the preceding matching event might be interleaved with other events which are ignored.- Parameters:
name- Name of the new pattern- Returns:
- A new pattern which is appended to this one
-
notFollowedBy
Appends a new pattern to the existing one. The new pattern enforces that there is no event matching this pattern between the preceding pattern and succeeding this one.NOTE: There has to be other pattern after this one.
- Parameters:
name- Name of the new pattern- Returns:
- A new pattern which is appended to this one
-
followedByAny
Appends a new pattern to the existing one. The new pattern enforces non-strict temporal contiguity. This means that a matching event of this pattern and the preceding matching event might be interleaved with other events which are ignored.- Parameters:
name- Name of the new pattern- Returns:
- A new pattern which is appended to this one
-
optional
Specifies that this pattern is optional for a final match of the pattern sequence to happen.- Returns:
- The same pattern as optional.
- Throws:
MalformedPatternException- if the quantifier is not applicable to this pattern.
-
oneOrMore
Specifies that this pattern can occurone or moretimes. This means at least one and at most infinite number of events can be matched to this pattern.If this quantifier is enabled for a pattern
A.oneOrMore().followedBy(B)and a sequence of eventsA1 A2 Bappears, this will generate patterns:A1 BandA1 A2 B. See alsoallowCombinations().- Returns:
- The same pattern with a
Quantifier.looping(ConsumingStrategy)quantifier applied. - Throws:
MalformedPatternException- if the quantifier is not applicable to this pattern.
-
oneOrMore
Specifies that this pattern can occurone or moretimes and time interval corresponds to the maximum time gap between previous and current event for each times. This means at least one and at most infinite number of events can be matched to this pattern.If this quantifier is enabled for a pattern
A.oneOrMore().followedBy(B)and a sequence of eventsA1 A2 Bappears, this will generate patterns:A1 BandA1 A2 B. See alsoallowCombinations().- Parameters:
windowTime- time of the matching window between times- Returns:
- The same pattern with a
Quantifier.looping(ConsumingStrategy)quantifier applied. - Throws:
MalformedPatternException- if the quantifier is not applicable to this pattern.
-
greedy
Specifies that this pattern is greedy. This means as many events as possible will be matched to this pattern.- Returns:
- The same pattern with
Quantifier.greedy()set to true. - Throws:
MalformedPatternException- if the quantifier is not applicable to this pattern.
-
times
Specifies exact number of times that this pattern should be matched.- Parameters:
times- number of times matching event must appear- Returns:
- The same pattern with number of times applied
- Throws:
MalformedPatternException- if the quantifier is not applicable to this pattern.
-
times
Specifies exact number of times that this pattern should be matched and time interval corresponds to the maximum time gap between previous and current event for each times.- Parameters:
times- number of times matching event must appearwindowTime- time of the matching window between times- Returns:
- The same pattern with number of times applied
- Throws:
MalformedPatternException- if the quantifier is not applicable to this pattern.
-
times
Specifies that the pattern can occur between from and to times.- Parameters:
from- number of times matching event must appear at leastto- number of times matching event must appear at most- Returns:
- The same pattern with the number of times range applied
- Throws:
MalformedPatternException- if the quantifier is not applicable to this pattern.
-
times
Specifies that the pattern can occur between from and to times with time interval corresponds to the maximum time gap between previous and current event for each times.- Parameters:
from- number of times matching event must appear at leastto- number of times matching event must appear at mostwindowTime- time of the matching window between times- Returns:
- The same pattern with the number of times range applied
- Throws:
MalformedPatternException- if the quantifier is not applicable to this pattern.
-
timesOrMore
Specifies that this pattern can occur the specified times at least. This means at least the specified times and at most infinite number of events can be matched to this pattern.- Returns:
- The same pattern with a
Quantifier.looping(ConsumingStrategy)quantifier applied. - Throws:
MalformedPatternException- if the quantifier is not applicable to this pattern.
-
timesOrMore
Specifies that this pattern can occur the specified times at least with interval corresponds to the maximum time gap between previous and current event for each times. This means at least the specified times and at most infinite number of events can be matched to this pattern.- Parameters:
times- number of times at least matching event must appearwindowTime- time of the matching window between times- Returns:
- The same pattern with a
Quantifier.looping(ConsumingStrategy)quantifier applied. - Throws:
MalformedPatternException- if the quantifier is not applicable to this pattern.
-
allowCombinations
Applicable only toQuantifier.looping(ConsumingStrategy)andQuantifier.times(ConsumingStrategy)patterns, this option allows more flexibility to the matching events.If
allowCombinations()is not applied for a patternA.oneOrMore().followedBy(B)and a sequence of eventsA1 A2 Bappears, this will generate patterns:A1 BandA1 A2 B. If this method is applied, we will haveA1 B,A2 BandA1 A2 B.- Returns:
- The same pattern with the updated quantifier. *
- Throws:
MalformedPatternException- if the quantifier is not applicable to this pattern.
-
consecutive
Works in conjunction withoneOrMore()ortimes(int). Specifies that any not matching element breaks the loop.E.g. a pattern like:
Pattern.<Event>begin("start").where(new SimpleCondition<Event>() { @Override public boolean filter(Event value) throws Exception { return value.getName().equals("c"); } }) .followedBy("middle").where(new SimpleCondition<Event>() { @Override public boolean filter(Event value) throws Exception { return value.getName().equals("a"); } }).oneOrMore().consecutive() .followedBy("end1").where(new SimpleCondition<Event>() { @Override public boolean filter(Event value) throws Exception { return value.getName().equals("b"); } });for a sequence: C D A1 A2 A3 D A4 B
will generate matches: {C A1 B}, {C A1 A2 B}, {C A1 A2 A3 B}
By default a relaxed continuity is applied.
- Returns:
- pattern with continuity changed to strict
-
begin
public static <T,F extends T> GroupPattern<T,F> begin(Pattern<T, F> group, AfterMatchSkipStrategy afterMatchSkipStrategy) Starts a new pattern sequence. The provided pattern is the initial pattern of the new sequence.- Parameters:
group- the pattern to begin withafterMatchSkipStrategy- theAfterMatchSkipStrategy.SkipStrategyto use after each match.- Returns:
- The first pattern of a pattern sequence
-
begin
Starts a new pattern sequence. The provided pattern is the initial pattern of the new sequence.- Parameters:
group- the pattern to begin with- Returns:
- the first pattern of a pattern sequence
-
followedBy
Appends a new group pattern to the existing one. The new pattern enforces non-strict temporal contiguity. This means that a matching event of this pattern and the preceding matching event might be interleaved with other events which are ignored.- Parameters:
group- the pattern to append- Returns:
- A new pattern which is appended to this one
-
followedByAny
Appends a new group pattern to the existing one. The new pattern enforces non-strict temporal contiguity. This means that a matching event of this pattern and the preceding matching event might be interleaved with other events which are ignored.- Parameters:
group- the pattern to append- Returns:
- A new pattern which is appended to this one
-
next
Appends a new group pattern to the existing one. The new pattern enforces strict temporal contiguity. This means that the whole pattern sequence matches only if an event which matches this pattern directly follows the preceding matching event. Thus, there cannot be any events in between two matching events.- Parameters:
group- the pattern to append- Returns:
- A new pattern which is appended to this one
-
getAfterMatchSkipStrategy
- Returns:
- the pattern's
AfterMatchSkipStrategy.SkipStrategyafter match.
-
toString
-