Github user dawidwys commented on a diff in the pull request:
https://github.com/apache/flink/pull/3621#discussion_r108649205
--- Diff:
flink-libraries/flink-cep/src/main/java/org/apache/flink/cep/pattern/Pattern.java
---
@@ -267,6 +267,76 @@ public int getTimes() {
}
/**
+ * Works in conjunction with {@link Pattern#zeroOrMore()}, {@link
Pattern#oneOrMore()} or {@link Pattern#times(int)}.
+ * Specifies that any not matching element breaks the loop.
+ *
+ * <p>E.g. a pattern like:
+ * <pre>{@code
+ * Pattern.<Event>begin("start").where(new FilterFunction<Event>() {
+ * @Override
+ * public boolean filter(Event value) throws Exception {
+ * return value.getName().equals("c");
+ * }
+ * })
+ * .followedBy("middle").where(new FilterFunction<Event>() {
+ * @Override
+ * public boolean filter(Event value) throws Exception {
+ * return value.getName().equals("a");
+ * }
+ * })
+ * }<b>.oneOrMore(true).consecutive()</b>{@code
+ * .followedBy("end1").where(new FilterFunction<Event>() {
+ * @Override
+ * public boolean filter(Event value) throws Exception {
+ * return value.getName().equals("b");
+ * }
+ * });
+ * }</pre>
+ *
+ * <p>for a sequence: C D A1 A2 A3 D A4 B
+ *
+ * <p>will generate matches: {C A1 B}, {C A1 A2 B}, {C A1 A2 A3 B}
+ *
+ * <p><b>NOTICE:</b> This operator can be applied only when either
zeroOrMore,
+ * oneOrMore or times was previously applied!
+ *
+ * <p>By default a relaxed continuity is applied.
+ *
+ * @return pattern with continuity changed to strict
+ */
+ public Pattern<T, F> consecutive() {
+ switch (this.quantifier) {
+
+ case ZERO_OR_MORE_EAGER:
+ this.quantifier =
Quantifier.ZERO_OR_MORE_EAGER_STRICT;
+ break;
+ case ZERO_OR_MORE_COMBINATIONS:
+ this.quantifier =
Quantifier.ZERO_OR_MORE_COMBINATIONS_STRICT;
+ break;
+ case ONE_OR_MORE_EAGER:
+ this.quantifier =
Quantifier.ONE_OR_MORE_EAGER_STRICT;
+ break;
+ case ONE_OR_MORE_COMBINATIONS:
+ this.quantifier =
Quantifier.ONE_OR_MORE_COMBINATIONS_STRICT;
+ break;
+ case TIMES:
+ this.quantifier = Quantifier.TIMES_STRICT;
+ break;
+ case ZERO_OR_MORE_COMBINATIONS_STRICT:
+ case ONE_OR_MORE_EAGER_STRICT:
+ case ONE_OR_MORE_COMBINATIONS_STRICT:
+ case ZERO_OR_MORE_EAGER_STRICT:
+ case TIMES_STRICT:
+ throw new MalformedPatternException("Strict
continuity already applied!");
--- End diff --
Ok after your second comment I changed just the message of the exception
As a side note I was considering changing the quantifier field to
EnumSet<QuantifierProperty> but then we would not have a clearly defined valid
combinations of properties (we would have to maintain it at the API level).
This method though would be as simple as .add(QuantifierProperty.STRICT)
@kl0u What do you think?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---