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() |
Optional<Duration> |
getWindowSize() |
Optional<Duration> |
getWindowSize(WithinType withinType) |
Time |
getWindowTime()
Deprecated.
Use
getWindowSize() |
Time |
getWindowTime(WithinType withinType)
Deprecated.
|
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> |
oneOrMore(Duration windowTime)
Specifies that this pattern can occur
one or more times and time interval corresponds
to the maximum time gap between previous and current event for each times. |
Pattern<T,F> |
oneOrMore(Time windowTime)
Deprecated.
|
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 times,
Duration windowTime)
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.
|
Pattern<T,F> |
times(int from,
int to)
Specifies that the pattern can occur between from and to times.
|
Pattern<T,F> |
times(int from,
int to,
Duration windowTime)
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.
|
Pattern<T,F> |
times(int from,
int to,
Time windowTime)
Deprecated.
|
Pattern<T,F> |
times(int times,
Time windowTime)
Deprecated.
Using
times(int, Duration) |
Pattern<T,F> |
timesOrMore(int times)
Specifies that this pattern can occur the specified times at least.
|
Pattern<T,F> |
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.
|
Pattern<T,F> |
timesOrMore(int times,
Time windowTime)
Deprecated.
|
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(Duration windowTime)
Defines the maximum time interval in which a matching pattern has to be completed in order to
be considered valid.
|
Pattern<T,F> |
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.
|
Pattern<T,F> |
within(Time windowTime)
Deprecated.
Use
within(Duration) . |
Pattern<T,F> |
within(Time windowTime,
WithinType withinType)
Deprecated.
|
protected Pattern(String name, Pattern<T,? extends T> previous, Quantifier.ConsumingStrategy consumingStrategy, AfterMatchSkipStrategy afterMatchSkipStrategy)
public Quantifier.Times getTimes()
public String getName()
@Deprecated @Nullable public Time getWindowTime()
getWindowSize()
@Deprecated @Nullable public Time getWindowTime(WithinType withinType)
getWindowSize(WithinType)
.public Optional<Duration> getWindowSize(WithinType withinType)
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 state@Deprecated public Pattern<T,F> within(@Nullable Time windowTime)
within(Duration)
.windowTime
- Time of the matching windowpublic Pattern<T,F> within(@Nullable Duration windowTime)
windowTime
- Time of the matching window@Deprecated public Pattern<T,F> within(@Nullable Time windowTime, WithinType withinType)
within(Duration, WithinType)
.withinType
- Type of the within interval between eventswindowTime
- Time of the matching windowpublic Pattern<T,F> within(@Nullable Duration windowTime, WithinType withinType)
withinType
- Type of the within interval between eventswindowTime
- 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.@Deprecated public Pattern<T,F> oneOrMore(@Nullable Time windowTime)
oneOrMore(Duration)
one or more
times 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 events A1 A2 B
appears, this will generate patterns: A1 B
and
A1 A2 B
. See also allowCombinations()
.
windowTime
- time of the matching window between timesQuantifier.looping(ConsumingStrategy)
quantifier
applied.MalformedPatternException
- if the quantifier is not applicable to this pattern.public Pattern<T,F> oneOrMore(@Nullable Duration windowTime)
one or more
times 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 events A1 A2 B
appears, this will generate patterns: A1 B
and
A1 A2 B
. See also allowCombinations()
.
windowTime
- time of the matching window between timesQuantifier.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.@Deprecated public Pattern<T,F> times(int times, @Nullable Time windowTime)
times(int, Duration)
times
- number of times matching event must appearwindowTime
- time of the matching window between timesMalformedPatternException
- if the quantifier is not applicable to this pattern.public Pattern<T,F> times(int times, @Nullable Duration windowTime)
times
- number of times matching event must appearwindowTime
- time of the matching window between timesMalformedPatternException
- 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.@Deprecated public Pattern<T,F> times(int from, int to, @Nullable Time windowTime)
times(int, int, Duration)
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 timesMalformedPatternException
- if the quantifier is not applicable to this pattern.public Pattern<T,F> times(int from, int to, @Nullable Duration windowTime)
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 timesMalformedPatternException
- 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.@Deprecated public Pattern<T,F> timesOrMore(int times, @Nullable Time windowTime)
timesOrMore(int, Duration)
times
- number of times at least matching event must appearwindowTime
- time of the matching window between timesQuantifier.looping(ConsumingStrategy)
quantifier
applied.MalformedPatternException
- if the quantifier is not applicable to this pattern.public Pattern<T,F> timesOrMore(int times, @Nullable Duration windowTime)
times
- number of times at least matching event must appearwindowTime
- time of the matching window between timesQuantifier.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–2024 The Apache Software Foundation. All rights reserved.