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) |
protected |
Pattern(String name,
Pattern<T,? extends T> previous,
Quantifier.ConsumingStrategy consumingStrategy) |
Modifier and Type | Method and Description |
---|---|
Pattern<T,F> |
allowCombinations()
Applicable only to
Quantifier.ONE_OR_MORE(ConsumingStrategy) and
Quantifier.TIMES(ConsumingStrategy) patterns, this option allows more flexibility to the matching events. |
static <X> Pattern<X,X> |
begin(String name)
Starts a new pattern sequence.
|
Pattern<T,F> |
consecutive()
Works in conjunction with
oneOrMore() or times(int) . |
Pattern<T,T> |
followedBy(String name)
Appends a new pattern to the existing one.
|
Pattern<T,T> |
followedByAny(String name)
Appends a new pattern to the existing one.
|
IterativeCondition<F> |
getCondition() |
String |
getName() |
Pattern<T,? extends T> |
getPrevious() |
Quantifier |
getQuantifier() |
int |
getTimes() |
Time |
getWindowTime() |
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> |
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)
public int getTimes()
public String getName()
public Time getWindowTime()
public Quantifier getQuantifier()
public IterativeCondition<F> getCondition()
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 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> 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.ONE_OR_MORE(ConsumingStrategy)
quantifier applied.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> allowCombinations()
Quantifier.ONE_OR_MORE(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 () {
Copyright © 2014–2018 The Apache Software Foundation. All rights reserved.