private void checkIfNoNotPattern() { if (quantifier.getConsumingStrategy() == ConsumingStrategy.NOT_FOLLOW || quantifier.getConsumingStrategy() == ConsumingStrategy.NOT_NEXT) { throw new MalformedPatternException("Option not applicable to NOT pattern"); } }
/** * 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. * * @return The same pattern with a {@link Quantifier#looping(ConsumingStrategy)} quantifier applied. * @throws MalformedPatternException if the quantifier is not applicable to this pattern. */ public Pattern<T, F> timesOrMore(int times) { checkIfNoNotPattern(); checkIfQuantifierApplied(); this.quantifier = Quantifier.looping(quantifier.getConsumingStrategy()); this.times = Times.of(times); return this; }
private void addStopStateToLooping(final State<T> loopingState) { if (followingPattern != null && followingPattern.getQuantifier().getConsumingStrategy() == Quantifier.ConsumingStrategy.NOT_FOLLOW) { final IterativeCondition<T> notCondition = getTakeCondition(followingPattern); final State<T> stopState = createStopState(notCondition, followingPattern.getName()); loopingState.addProceed(stopState, notCondition); } }
/** * Specifies that this pattern can occur {@code one or more} times. * This means at least one and at most infinite number of events can * be matched to this pattern. * * <p>If this quantifier is enabled for a * pattern {@code A.oneOrMore().followedBy(B)} and a sequence of events * {@code A1 A2 B} appears, this will generate patterns: * {@code A1 B} and {@code A1 A2 B}. See also {@link #allowCombinations()}. * * @return The same pattern with a {@link Quantifier#looping(ConsumingStrategy)} quantifier applied. * @throws MalformedPatternException if the quantifier is not applicable to this pattern. */ public Pattern<T, F> oneOrMore() { checkIfNoNotPattern(); checkIfQuantifierApplied(); this.quantifier = Quantifier.looping(quantifier.getConsumingStrategy()); this.times = Times.of(1); return this; }
/** * Specifies exact number of times that this pattern should be matched. * * @param times number of times matching event must appear * @return The same pattern with number of times applied * * @throws MalformedPatternException if the quantifier is not applicable to this pattern. */ public Pattern<T, F> times(int times) { checkIfNoNotPattern(); checkIfQuantifierApplied(); Preconditions.checkArgument(times > 0, "You should give a positive number greater than 0."); this.quantifier = Quantifier.times(quantifier.getConsumingStrategy()); this.times = Times.of(times); return this; }
/** * Retrieves list of conditions resulting in Stop state and names of the corresponding NOT patterns. * * <p>A current not condition can be produced in two cases: * <ol> * <li>the previous pattern is a {@link Quantifier.ConsumingStrategy#NOT_FOLLOW}</li> * <li>exists a backward path of {@link Quantifier.QuantifierProperty#OPTIONAL} patterns to * {@link Quantifier.ConsumingStrategy#NOT_FOLLOW}</li> * </ol> * * <p><b>WARNING:</b> for more info on the second case see: {@link NFAFactoryCompiler#copyWithoutTransitiveNots(State)} * * @return list of not conditions with corresponding names */ private List<Tuple2<IterativeCondition<T>, String>> getCurrentNotCondition() { List<Tuple2<IterativeCondition<T>, String>> notConditions = new ArrayList<>(); Pattern<T, ? extends T> previousPattern = currentPattern; while (previousPattern.getPrevious() != null && ( previousPattern.getPrevious().getQuantifier().hasProperty(Quantifier.QuantifierProperty.OPTIONAL) || previousPattern.getPrevious().getQuantifier().getConsumingStrategy() == Quantifier.ConsumingStrategy.NOT_FOLLOW)) { previousPattern = previousPattern.getPrevious(); if (previousPattern.getQuantifier().getConsumingStrategy() == Quantifier.ConsumingStrategy.NOT_FOLLOW) { final IterativeCondition<T> notCondition = getTakeCondition(previousPattern); notConditions.add(Tuple2.of(notCondition, previousPattern.getName())); } } return notConditions; }
/** * Specifies that the pattern can occur between from and to times. * * @param from number of times matching event must appear at least * @param to number of times matching event must appear at most * @return The same pattern with the number of times range applied * * @throws MalformedPatternException if the quantifier is not applicable to this pattern. */ public Pattern<T, F> times(int from, int to) { checkIfNoNotPattern(); checkIfQuantifierApplied(); this.quantifier = Quantifier.times(quantifier.getConsumingStrategy()); if (from == 0) { this.quantifier.optional(); from = 1; } this.times = Times.of(from, to); return this; }
/** * Compiles the given pattern into a {@link NFAFactory}. The NFA factory can be used to create * multiple NFAs. */ void compileFactory() { if (currentPattern.getQuantifier().getConsumingStrategy() == Quantifier.ConsumingStrategy.NOT_FOLLOW) { throw new MalformedPatternException("NotFollowedBy is not supported as a last part of a Pattern!"); } checkPatternNameUniqueness(); checkPatternSkipStrategy(); // we're traversing the pattern from the end to the beginning --> the first state is the final state State<T> sinkState = createEndingState(); // add all the normal states sinkState = createMiddleStates(sinkState); // add the beginning state createStartState(sinkState); }
Quantifier.ConsumingStrategy consumingStrategy = pattern.getQuantifier().getConsumingStrategy(); if (headOfGroup(pattern)) { consumingStrategy = currentGroupPattern.getQuantifier().getConsumingStrategy(); } else { consumingStrategy = currentGroupPattern.getQuantifier().getInnerConsumingStrategy();
while (currentPattern.getPrevious() != null) { if (currentPattern.getQuantifier().getConsumingStrategy() == Quantifier.ConsumingStrategy.NOT_FOLLOW) { } else if (currentPattern.getQuantifier().getConsumingStrategy() == Quantifier.ConsumingStrategy.NOT_NEXT) { final State<T> notNext = createState(currentPattern.getName(), State.StateType.Normal); final IterativeCondition<T> notCondition = getTakeCondition(currentPattern);
@Test public void testNonStrictContiguity() { Pattern<Object, ?> pattern = Pattern.begin("start").followedBy("next").followedBy("end"); Pattern<Object, ?> previous; Pattern<Object, ?> previous2; assertNotNull(previous = pattern.getPrevious()); assertNotNull(previous2 = previous.getPrevious()); assertNull(previous2.getPrevious()); assertEquals(ConsumingStrategy.SKIP_TILL_NEXT, pattern.getQuantifier().getConsumingStrategy()); assertEquals(ConsumingStrategy.SKIP_TILL_NEXT, previous.getQuantifier().getConsumingStrategy()); assertEquals(pattern.getName(), "end"); assertEquals(previous.getName(), "next"); assertEquals(previous2.getName(), "start"); }
@Test public void testPatternWithSubtypingAndFilter() { Pattern<Event, Event> pattern = Pattern.<Event>begin("start").next("subevent").subtype(SubEvent.class).where(new SimpleCondition<SubEvent>() { private static final long serialVersionUID = -4118591291880230304L; @Override public boolean filter(SubEvent value) throws Exception { return false; } }).followedBy("end"); Pattern<Event, ?> previous; Pattern<Event, ?> previous2; assertNotNull(previous = pattern.getPrevious()); assertNotNull(previous2 = previous.getPrevious()); assertNull(previous2.getPrevious()); assertEquals(ConsumingStrategy.SKIP_TILL_NEXT, pattern.getQuantifier().getConsumingStrategy()); assertNotNull(previous.getCondition()); assertEquals(pattern.getName(), "end"); assertEquals(previous.getName(), "subevent"); assertEquals(previous2.getName(), "start"); }
assertNull(previous2.getPrevious()); assertEquals(ConsumingStrategy.SKIP_TILL_NEXT, pattern.getQuantifier().getConsumingStrategy()); assertFalse(previous.getCondition() instanceof RichOrCondition); assertTrue(previous2.getCondition() instanceof RichOrCondition);
private void checkIfNoNotPattern() { if (quantifier.getConsumingStrategy() == ConsumingStrategy.NOT_FOLLOW || quantifier.getConsumingStrategy() == ConsumingStrategy.NOT_NEXT) { throw new MalformedPatternException("Option not applicable to NOT pattern"); } }
private void checkIfNoNotPattern() { if (quantifier.getConsumingStrategy() == ConsumingStrategy.NOT_FOLLOW || quantifier.getConsumingStrategy() == ConsumingStrategy.NOT_NEXT) { throw new MalformedPatternException("Option not applicable to NOT pattern"); } }
private void checkIfNoNotPattern() { if (quantifier.getConsumingStrategy() == ConsumingStrategy.NOT_FOLLOW || quantifier.getConsumingStrategy() == ConsumingStrategy.NOT_NEXT) { throw new MalformedPatternException("Option not applicable to NOT pattern"); } }
private void addStopStateToLooping(final State<T> loopingState) { if (followingPattern != null && followingPattern.getQuantifier().getConsumingStrategy() == Quantifier.ConsumingStrategy.NOT_FOLLOW) { final IterativeCondition<T> notCondition = getTakeCondition(followingPattern); final State<T> stopState = createStopState(notCondition, followingPattern.getName()); loopingState.addProceed(stopState, notCondition); } }
private void addStopStateToLooping(final State<T> loopingState) { if (followingPattern != null && followingPattern.getQuantifier().getConsumingStrategy() == Quantifier.ConsumingStrategy.NOT_FOLLOW) { final IterativeCondition<T> notCondition = (IterativeCondition<T>) followingPattern.getCondition(); final State<T> stopState = createStopState(notCondition, followingPattern.getName()); loopingState.addProceed(stopState, notCondition); } }
private void addStopStateToLooping(final State<T> loopingState) { if (followingPattern != null && followingPattern.getQuantifier().getConsumingStrategy() == Quantifier.ConsumingStrategy.NOT_FOLLOW) { final IterativeCondition<T> notCondition = getTakeCondition(followingPattern); final State<T> stopState = createStopState(notCondition, followingPattern.getName()); loopingState.addProceed(stopState, notCondition); } }
/** * Specifies exact number of times that this pattern should be matched. * * @param times number of times matching event must appear * @return The same pattern with number of times applied * * @throws MalformedPatternException if the quantifier is not applicable to this pattern. */ public Pattern<T, F> times(int times) { checkIfNoNotPattern(); checkIfQuantifierApplied(); Preconditions.checkArgument(times > 0, "You should give a positive number greater than 0."); this.quantifier = Quantifier.times(quantifier.getConsumingStrategy()); this.times = Times.of(times); return this; }