/** * Adds a condition that has to be satisfied by an event * in order to be considered a match. If another condition has already been * set, the new one is going to be combined with the previous with a * logical {@code 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. */ public Pattern<T, F> where(IterativeCondition<F> condition) { Preconditions.checkNotNull(condition, "The condition cannot be null."); ClosureCleaner.clean(condition, true); if (this.condition == null) { this.condition = condition; } else { this.condition = new RichAndCondition<>(this.condition, condition); } return this; }
/** * This method extends the given condition with stop(until) condition if necessary. * The until condition needs to be applied only if both of the given conditions are not null. * * @param condition the condition to extend * @param untilCondition the until condition to join with the given condition * @param isTakeCondition whether the {@code condition} is for {@code TAKE} edge * @return condition with AND applied or the original condition */ private IterativeCondition<T> extendWithUntilCondition( IterativeCondition<T> condition, IterativeCondition<T> untilCondition, boolean isTakeCondition) { if (untilCondition != null && condition != null) { return new RichAndCondition<>(new RichNotCondition<>(untilCondition), condition); } else if (untilCondition != null && isTakeCondition) { return new RichNotCondition<>(untilCondition); } return condition; }
private void updateWithGreedyCondition( State<T> state, IterativeCondition<T> takeCondition) { for (StateTransition<T> stateTransition : state.getStateTransitions()) { stateTransition.setCondition( new RichAndCondition<>(stateTransition.getCondition(), new RichNotCondition<>(takeCondition))); } } }
/** * Applies a subtype constraint on the current pattern. This means that an event has * to be of the given subtype in order to be matched. * * @param subtypeClass Class of the subtype * @param <S> Type of the subtype * @return The same pattern with the new subtype constraint */ public <S extends F> Pattern<T, S> subtype(final Class<S> subtypeClass) { Preconditions.checkNotNull(subtypeClass, "The class cannot be null."); if (condition == null) { this.condition = new SubtypeCondition<F>(subtypeClass); } else { this.condition = new RichAndCondition<>(condition, new SubtypeCondition<F>(subtypeClass)); } @SuppressWarnings("unchecked") Pattern<T, S> result = (Pattern<T, S>) this; return result; }
singletonState.addProceed( originalStateMap.get(proceedState.getName()), new RichAndCondition<>(proceedCondition, untilCondition)); ? new RichAndCondition<>(proceedCondition, new RichNotCondition<>(untilCondition)) : proceedCondition); } else {
if (untilCondition != null) { State<T> sinkStateCopy = copy(sinkState); loopingState.addProceed(sinkStateCopy, new RichAndCondition<>(proceedCondition, untilCondition)); originalStateMap.put(sinkState.getName(), sinkStateCopy); ? new RichAndCondition<>(proceedCondition, new RichNotCondition<>(untilCondition)) : proceedCondition); updateWithGreedyCondition(sinkState, getTakeCondition(currentPattern));