T
- Base type of the elements appearing in the patternF
- Subtype of T to which the current pattern operator is constrainedpublic class Pattern<T,F extends T> extends Object
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());
Modifier | Constructor and Description |
---|---|
protected |
Pattern(String name,
Pattern<T,? extends T> previous,
Quantifier.ConsumingStrategy consumingStrategy,
AfterMatchSkipStrategy afterMatchSkipStrategy) |
Modifier and Type | Method and Description |
---|---|
Pattern<T,F> |
allowCombinations()
Applicable only to
Quantifier.looping(ConsumingStrategy) and Quantifier.times(ConsumingStrategy) patterns, this option allows more flexibility to the
matching events. |
static <T,F extends T> |
begin(Pattern<T,F> group)
Starts a new pattern sequence.
|
static <T,F extends T> |
begin(Pattern<T,F> group,
AfterMatchSkipStrategy afterMatchSkipStrategy)
Starts a new pattern sequence.
|
static <X> Pattern<X,X> |
begin(String name)
Starts a new pattern sequence.
|
static <X> Pattern<X,X> |
begin(String name,
AfterMatchSkipStrategy afterMatchSkipStrategy)
Starts a new pattern sequence.
|
Pattern<T,F> |
consecutive()
Works in conjunction with
oneOrMore() or times(int) . |
GroupPattern<T,F> |
followedBy(Pattern<T,F> group)
Appends a new group pattern to the existing one.
|
Pattern<T,T> |
followedBy(String name)
Appends a new pattern to the existing one.
|
GroupPattern<T,F> |
followedByAny(Pattern<T,F> group)
Appends a new group pattern to the existing one.
|
Pattern<T,T> |
followedByAny(String name)
Appends a new pattern to the existing one.
|
AfterMatchSkipStrategy |
getAfterMatchSkipStrategy() |
IterativeCondition<F> |
getCondition() |
String |
getName() |
Pattern<T,? extends T> |
getPrevious() |
Quantifier |
getQuantifier() |
Quantifier.Times |
getTimes() |
IterativeCondition<F> |
getUntilCondition() |
Time |
getWindowTime() |
Pattern<T,F> |
greedy()
Specifies that this pattern is greedy.
|
GroupPattern<T,F> |
next(Pattern<T,F> group)
Appends a new group pattern to the existing one.
|
Pattern<T,T> |
next(String name)
Appends a new pattern to the existing one.
|
Pattern<T,T> |
notFollowedBy(String name)
Appends a new pattern to the existing one.
|
Pattern<T,T> |
notNext(String name)
Appends a new pattern to the existing one.
|
Pattern<T,F> |
oneOrMore()
Specifies that this pattern can occur
one or more times. |
Pattern<T,F> |
optional()
Specifies that this pattern is optional for a final match of the pattern sequence to happen.
|
Pattern<T,F> |
or(IterativeCondition<F> condition)
Adds a condition that has to be satisfied by an event in order to be considered a match.
|
<S extends F> |
subtype(Class<S> subtypeClass)
Applies a subtype constraint on the current pattern.
|
Pattern<T,F> |
times(int times)
Specifies exact number of times that this pattern should be matched.
|
Pattern<T,F> |
times(int from,
int to)
Specifies that the pattern can occur between from and to times.
|
Pattern<T,F> |
timesOrMore(int times)
Specifies that this pattern can occur the specified times at least.
|
String |
toString() |
Pattern<T,F> |
until(IterativeCondition<F> untilCondition)
Applies a stop condition for a looping state.
|
Pattern<T,F> |
where(IterativeCondition<F> condition)
Adds a condition that has to be satisfied by an event in order to be considered a match.
|
Pattern<T,F> |
within(Time windowTime)
Defines the maximum time interval in which a matching pattern has to be completed in order to
be considered valid.
|
protected Pattern(String name, Pattern<T,? extends T> previous, Quantifier.ConsumingStrategy consumingStrategy, AfterMatchSkipStrategy afterMatchSkipStrategy)
public Quantifier.Times getTimes()
public String getName()
public Time getWindowTime()
public Quantifier getQuantifier()
public IterativeCondition<F> getCondition()
public IterativeCondition<F> getUntilCondition()
public static <X> Pattern<X,X> begin(String name)
X
- Base type of the event patternname
- The name of starting pattern of the new pattern sequencepublic static <X> Pattern<X,X> begin(String name, AfterMatchSkipStrategy afterMatchSkipStrategy)
X
- Base type of the event patternname
- The name of starting pattern of the new pattern sequenceafterMatchSkipStrategy
- the AfterMatchSkipStrategy.SkipStrategy
to use after
each match.public Pattern<T,F> where(IterativeCondition<F> condition)
AND
. In other case, this is going to be the only condition.condition
- The condition as an IterativeCondition
.public Pattern<T,F> or(IterativeCondition<F> condition)
OR
. In other case, this is going to be the only condition.condition
- The condition as an IterativeCondition
.public <S extends F> Pattern<T,S> subtype(Class<S> subtypeClass)
S
- Type of the subtypesubtypeClass
- Class of the subtypepublic Pattern<T,F> until(IterativeCondition<F> untilCondition)
untilCondition
- a condition an event has to satisfy to stop collecting events into
looping statepublic Pattern<T,F> within(Time windowTime)
windowTime
- Time of the matching windowpublic Pattern<T,T> next(String name)
name
- Name of the new patternpublic Pattern<T,T> notNext(String name)
name
- Name of the new patternpublic Pattern<T,T> followedBy(String name)
name
- Name of the new patternpublic Pattern<T,T> notFollowedBy(String name)
NOTE: There has to be other pattern after this one.
name
- Name of the new patternpublic Pattern<T,T> followedByAny(String name)
name
- Name of the new patternpublic Pattern<T,F> optional()
MalformedPatternException
- if the quantifier is not applicable to this pattern.public Pattern<T,F> oneOrMore()
one or more
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 events A1 A2 B
appears, this will generate patterns: A1 B
and
A1 A2 B
. See also allowCombinations()
.
Quantifier.looping(ConsumingStrategy)
quantifier
applied.MalformedPatternException
- if the quantifier is not applicable to this pattern.public Pattern<T,F> greedy()
Quantifier.greedy()
set to true.MalformedPatternException
- if the quantifier is not applicable to this pattern.public Pattern<T,F> times(int times)
times
- number of times matching event must appearMalformedPatternException
- if the quantifier is not applicable to this pattern.public Pattern<T,F> times(int from, int to)
from
- number of times matching event must appear at leastto
- number of times matching event must appear at mostMalformedPatternException
- if the quantifier is not applicable to this pattern.public Pattern<T,F> timesOrMore(int times)
Quantifier.looping(ConsumingStrategy)
quantifier
applied.MalformedPatternException
- if the quantifier is not applicable to this pattern.public Pattern<T,F> allowCombinations()
Quantifier.looping(ConsumingStrategy)
and Quantifier.times(ConsumingStrategy)
patterns, this option allows more flexibility to the
matching events.
If allowCombinations()
is not applied for a pattern A.oneOrMore().followedBy(B)
and a sequence of events A1 A2 B
appears, this will
generate patterns: A1 B
and A1 A2 B
. If this method is applied, we will have
A1 B
, A2 B
and A1 A2 B
.
MalformedPatternException
- if the quantifier is not applicable to this pattern.public Pattern<T,F> consecutive()
oneOrMore()
or times(int)
.
Specifies that any not matching element breaks the loop.
E.g. a pattern like:
{@code Pattern.begin("start").where(new SimpleCondition () {
public static <T,F extends T> GroupPattern<T,F> begin(Pattern<T,F> group, AfterMatchSkipStrategy afterMatchSkipStrategy)
group
- the pattern to begin withafterMatchSkipStrategy
- the AfterMatchSkipStrategy.SkipStrategy
to use after
each match.public static <T,F extends T> GroupPattern<T,F> begin(Pattern<T,F> group)
group
- the pattern to begin withpublic GroupPattern<T,F> followedBy(Pattern<T,F> group)
group
- the pattern to appendpublic GroupPattern<T,F> followedByAny(Pattern<T,F> group)
group
- the pattern to appendpublic GroupPattern<T,F> next(Pattern<T,F> group)
group
- the pattern to appendpublic AfterMatchSkipStrategy getAfterMatchSkipStrategy()
AfterMatchSkipStrategy.SkipStrategy
after match.Copyright © 2014–2022 The Apache Software Foundation. All rights reserved.