org.apache.flink.cep.pattern.Quantifier.Times Java Examples

The following examples show how to use org.apache.flink.cep.pattern.Quantifier.Times. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Pattern.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #2
Source File: Pattern.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #3
Source File: Pattern.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #4
Source File: Pattern.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
public Times getTimes() {
	return times;
}
 
Example #5
Source File: NFACompiler.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a "complex" state consisting of given number of states with
 * same {@link IterativeCondition}.
 *
 * @param sinkState the state that the created state should point to
 * @param proceedState state that the state being converted should proceed to
 * @param times     number of times the state should be copied
 * @return the first state of the "complex" state, next state should point to it
 */
@SuppressWarnings("unchecked")
private State<T> createTimesState(final State<T> sinkState, final State<T> proceedState, Times times) {
	State<T> lastSink = sinkState;
	setCurrentGroupPatternFirstOfLoop(false);
	final IterativeCondition<T> untilCondition = (IterativeCondition<T>) currentPattern.getUntilCondition();
	final IterativeCondition<T> innerIgnoreCondition = extendWithUntilCondition(
		getInnerIgnoreCondition(currentPattern),
		untilCondition,
		false);
	final IterativeCondition<T> takeCondition = extendWithUntilCondition(
		getTakeCondition(currentPattern),
		untilCondition,
		true);

	if (currentPattern.getQuantifier().hasProperty(Quantifier.QuantifierProperty.GREEDY) &&
		times.getFrom() != times.getTo()) {
		if (untilCondition != null) {
			State<T> sinkStateCopy = copy(sinkState);
			originalStateMap.put(sinkState.getName(), sinkStateCopy);
		}
		updateWithGreedyCondition(sinkState, takeCondition);
	}

	for (int i = times.getFrom(); i < times.getTo(); i++) {
		lastSink = createSingletonState(lastSink, proceedState, takeCondition, innerIgnoreCondition, true);
		addStopStateToLooping(lastSink);
	}
	for (int i = 0; i < times.getFrom() - 1; i++) {
		lastSink = createSingletonState(lastSink, null, takeCondition, innerIgnoreCondition, false);
		addStopStateToLooping(lastSink);
	}
	// we created the intermediate states in the loop, now we create the start of the loop.
	setCurrentGroupPatternFirstOfLoop(true);
	return createSingletonState(
		lastSink,
		proceedState,
		takeCondition,
		getIgnoreCondition(currentPattern),
		currentPattern.getQuantifier().hasProperty(Quantifier.QuantifierProperty.OPTIONAL));
}
 
Example #6
Source File: Pattern.java    From flink with Apache License 2.0 4 votes vote down vote up
public Times getTimes() {
	return times;
}
 
Example #7
Source File: NFACompiler.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a "complex" state consisting of given number of states with
 * same {@link IterativeCondition}.
 *
 * @param sinkState the state that the created state should point to
 * @param proceedState state that the state being converted should proceed to
 * @param times     number of times the state should be copied
 * @return the first state of the "complex" state, next state should point to it
 */
@SuppressWarnings("unchecked")
private State<T> createTimesState(final State<T> sinkState, final State<T> proceedState, Times times) {
	State<T> lastSink = sinkState;
	setCurrentGroupPatternFirstOfLoop(false);
	final IterativeCondition<T> untilCondition = (IterativeCondition<T>) currentPattern.getUntilCondition();
	final IterativeCondition<T> innerIgnoreCondition = extendWithUntilCondition(
		getInnerIgnoreCondition(currentPattern),
		untilCondition,
		false);
	final IterativeCondition<T> takeCondition = extendWithUntilCondition(
		getTakeCondition(currentPattern),
		untilCondition,
		true);

	if (currentPattern.getQuantifier().hasProperty(Quantifier.QuantifierProperty.GREEDY) &&
		times.getFrom() != times.getTo()) {
		if (untilCondition != null) {
			State<T> sinkStateCopy = copy(sinkState);
			originalStateMap.put(sinkState.getName(), sinkStateCopy);
		}
		updateWithGreedyCondition(sinkState, takeCondition);
	}

	for (int i = times.getFrom(); i < times.getTo(); i++) {
		lastSink = createSingletonState(lastSink, proceedState, takeCondition, innerIgnoreCondition, true);
		addStopStateToLooping(lastSink);
	}
	for (int i = 0; i < times.getFrom() - 1; i++) {
		lastSink = createSingletonState(lastSink, null, takeCondition, innerIgnoreCondition, false);
		addStopStateToLooping(lastSink);
	}
	// we created the intermediate states in the loop, now we create the start of the loop.
	setCurrentGroupPatternFirstOfLoop(true);
	return createSingletonState(
		lastSink,
		proceedState,
		takeCondition,
		getIgnoreCondition(currentPattern),
		currentPattern.getQuantifier().hasProperty(Quantifier.QuantifierProperty.OPTIONAL));
}
 
Example #8
Source File: Pattern.java    From flink with Apache License 2.0 4 votes vote down vote up
public Times getTimes() {
	return times;
}
 
Example #9
Source File: NFACompiler.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a "complex" state consisting of given number of states with
 * same {@link IterativeCondition}.
 *
 * @param sinkState the state that the created state should point to
 * @param proceedState state that the state being converted should proceed to
 * @param times     number of times the state should be copied
 * @return the first state of the "complex" state, next state should point to it
 */
@SuppressWarnings("unchecked")
private State<T> createTimesState(final State<T> sinkState, final State<T> proceedState, Times times) {
	State<T> lastSink = sinkState;
	setCurrentGroupPatternFirstOfLoop(false);
	final IterativeCondition<T> untilCondition = (IterativeCondition<T>) currentPattern.getUntilCondition();
	final IterativeCondition<T> innerIgnoreCondition = extendWithUntilCondition(
		getInnerIgnoreCondition(currentPattern),
		untilCondition,
		false);
	final IterativeCondition<T> takeCondition = extendWithUntilCondition(
		getTakeCondition(currentPattern),
		untilCondition,
		true);

	if (currentPattern.getQuantifier().hasProperty(Quantifier.QuantifierProperty.GREEDY) &&
		times.getFrom() != times.getTo()) {
		if (untilCondition != null) {
			State<T> sinkStateCopy = copy(sinkState);
			originalStateMap.put(sinkState.getName(), sinkStateCopy);
		}
		updateWithGreedyCondition(sinkState, takeCondition);
	}

	for (int i = times.getFrom(); i < times.getTo(); i++) {
		lastSink = createSingletonState(lastSink, proceedState, takeCondition, innerIgnoreCondition, true);
		addStopStateToLooping(lastSink);
	}
	for (int i = 0; i < times.getFrom() - 1; i++) {
		lastSink = createSingletonState(lastSink, null, takeCondition, innerIgnoreCondition, false);
		addStopStateToLooping(lastSink);
	}
	// we created the intermediate states in the loop, now we create the start of the loop.
	setCurrentGroupPatternFirstOfLoop(true);
	return createSingletonState(
		lastSink,
		proceedState,
		takeCondition,
		getIgnoreCondition(currentPattern),
		currentPattern.getQuantifier().hasProperty(Quantifier.QuantifierProperty.OPTIONAL));
}
 
Example #10
Source File: Pattern.java    From Flink-CEPplus with Apache License 2.0 3 votes vote down vote up
/**
 * 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;
}
 
Example #11
Source File: Pattern.java    From Flink-CEPplus with Apache License 2.0 3 votes vote down vote up
/**
 * 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;
}
 
Example #12
Source File: Pattern.java    From flink with Apache License 2.0 3 votes vote down vote up
/**
 * 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;
}
 
Example #13
Source File: Pattern.java    From flink with Apache License 2.0 3 votes vote down vote up
/**
 * 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;
}
 
Example #14
Source File: Pattern.java    From flink with Apache License 2.0 3 votes vote down vote up
/**
 * 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;
}
 
Example #15
Source File: Pattern.java    From flink with Apache License 2.0 3 votes vote down vote up
/**
 * 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;
}