public 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());
param: jPattern Underlying Java API Pattern
Modifier and Type | Method and Description |
---|---|
Pattern<T,F> |
allowCombinations()
Applicable only to
Quantifier.ONE_OR_MORE() and Quantifier.TIMES() patterns,
this option allows more flexibility to the matching events. |
static <T,F extends T> |
apply(Pattern<T,F> jPattern)
Constructs a new Pattern by wrapping a given Java API Pattern
|
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.
|
scala.Option<IterativeCondition<F>> |
getCondition() |
String |
getName() |
scala.Option<Pattern<T,? extends T>> |
getPrevious() |
Quantifier |
getQuantifier() |
scala.Option<Time> |
getWindowTime() |
Pattern<T,T> |
next(String name)
Appends a new pattern to the existing one.
|
void |
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
|
Pattern<T,F> |
optional()
Specifies that this pattern is optional for a final match of the pattern
sequence to happen.
|
Pattern<T,F> |
or(scala.Function1<F,Object> condition)
Adds a condition that has to be satisfied by an event
in order to be considered a match.
|
Pattern<T,F> |
or(scala.Function2<F,Context<F>,Object> condition)
Adds a condition that has to be satisfied by an event
in order to be considered a match.
|
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> clazz)
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(scala.Function1<F,Object> condition)
Adds a condition that has to be satisfied by an event
in order to be considered a match.
|
Pattern<T,F> |
where(scala.Function2<F,Context<F>,Object> condition)
Adds a condition that has to be satisfied by an event
in order to be considered a match.
|
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.
|
Pattern<T,F> |
wrappedPattern() |
public static <T,F extends T> Pattern<T,F> apply(Pattern<T,F> jPattern)
jPattern
- Underlying Java API Pattern.public static <X> Pattern<X,X> begin(String name)
name
- The name of starting pattern of the new pattern sequencepublic String getName()
public scala.Option<Time> getWindowTime()
public Quantifier getQuantifier()
public scala.Option<IterativeCondition<F>> getCondition()
public Pattern<T,F> where(IterativeCondition<F> condition)
AND
. In other case, this is going to be the only
condition.
@param condition The condition as an {@link IterativeCondition}.
@return The pattern with the new condition is set.condition
- (undocumented)public Pattern<T,F> where(scala.Function2<F,Context<F>,Object> condition)
AND
. In other case, this is going to be the only
condition.
@param condition The condition to be set.
@return The pattern with the new condition is set.condition
- (undocumented)public Pattern<T,F> where(scala.Function1<F,Object> condition)
AND
. In other case, this is going to be the only
condition.
@param condition The condition to be set.
@return The pattern with the new condition is set.condition
- (undocumented)public Pattern<T,F> or(IterativeCondition<F> condition)
OR
. In other case, this is going to be the only
condition.
@param condition The condition as an {@link IterativeCondition}.
@return The pattern with the new condition is set.condition
- (undocumented)public Pattern<T,F> or(scala.Function1<F,Object> condition)
OR
. In other case, this is going to be the only
condition.
@param condition The <pre><code>OR</code></pre> condition.
@return The pattern with the new condition is set.condition
- (undocumented)public Pattern<T,F> or(scala.Function2<F,Context<F>,Object> condition)
OR
. In other case, this is going to be the only
condition.
@param condition The <pre><code>OR</code></pre> condition.
@return The pattern with the new condition is set.condition
- (undocumented)public <S extends F> Pattern<T,S> subtype(Class<S> clazz)
clazz
- 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 void 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 <pre><code>A.oneOrMore().followedBy(B)</code></pre> and a sequence of events
<pre><code>A1 A2 B</code></pre> appears, this will generate patterns:
<pre><code>A1 B</code></pre> and <pre><code>A1 A2 B</code></pre>. See also <pre><code>allowCombinations()</code></pre>.
@return The same pattern with a {@link Quantifier.ONE_OR_MORE()} quantifier applied.
@throws 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()
and Quantifier.TIMES()
patterns,
this option allows more flexibility to the matching events.
If
allowCombinations()
is not applied for a
pattern <pre><code>A.oneOrMore().followedBy(B)</code></pre> and a sequence of events
<pre><code>A1 A2 B</code></pre> appears, this will generate patterns:
<pre><code>A1 B</code></pre> and <pre><code>A1 A2 B</code></pre>. If this method is applied, we
will have <pre><code>A1 B</code></pre>, <pre><code>A2 B</code></pre> and <pre><code>A1 A2 B</code></pre>.
@return The same pattern with the updated quantifier.
@throws 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:
Pattern.begin("start").where(_.getName().equals("c"))
.followedBy("middle").where(_.getName().equals("a")).oneOrMore().consecutive()
.followedBy("end1").where(_.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.
Copyright © 2014–2018 The Apache Software Foundation. All rights reserved.