public <S> S capture(Capture<S> capture) { return captures().get(capture); }
@SuppressWarnings("unchecked cast") public <T> T get(Capture<T> capture) { if (this.equals(NIL)) { throw new NoSuchElementException("Requested value for unknown Capture. Was it registered in the Pattern?"); } else if (this.capture.equals(capture)) { return (T) value; } else { return tail.get(capture); } }
@Override public <C> Stream<Match> accept(Object object, Captures captures, C context) { Captures newCaptures = captures.addAll(Captures.ofNullable(capture, (T) object)); return Stream.of(Match.of(newCaptures)); }
@Override public int hashCode() { int result = value != null ? value.hashCode() : 0; result = 31 * result + captures.hashCode(); return result; }
public final <C> Stream<Match> match(Object object, C context) { return match(object, Captures.empty(), context); }
@Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } Present<?> present = (Present<?>) o; if (value != null ? !value.equals(present.value) : present.value != null) { return false; } return captures.equals(present.captures); }
@SuppressWarnings("unchecked cast") public <T> T get(Capture<T> capture) { if (this.equals(NIL)) { throw new NoSuchElementException("Requested value for unknown Capture. Was it registered in the Pattern?"); } else if (this.capture.equals(capture)) { return (T) value; } else { return tail.get(capture); } }
@Override public <T> Match<T> matchCapture(CapturePattern<T> capturePattern, Object object, Captures captures) { return Match.of((T) object, captures.addAll(Captures.ofNullable(capturePattern.capture(), (T) object))); }
@Override public int hashCode() { int result = capture != null ? capture.hashCode() : 0; result = 31 * result + (value != null ? value.hashCode() : 0); result = 31 * result + (tail != null ? tail.hashCode() : 0); return result; } }
public final Stream<Match> match(Object object) { return match(object, Captures.empty(), null); }
@Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } Captures captures = (Captures) o; if (capture != null ? !capture.equals(captures.capture) : captures.capture != null) { return false; } if (value != null ? !value.equals(captures.value) : captures.value != null) { return false; } return tail != null ? tail.equals(captures.tail) : captures.tail == null; }
public <T> T capture(Capture<T> capture) { return captures().get(capture); }
@Override public int hashCode() { int result = capture != null ? capture.hashCode() : 0; result = 31 * result + (value != null ? value.hashCode() : 0); result = 31 * result + (tail != null ? tail.hashCode() : 0); return result; } }
<T> Match<T> match(Pattern<T> pattern, Object object, Captures captures);
@Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } Captures captures = (Captures) o; if (capture != null ? !capture.equals(captures.capture) : captures.capture != null) { return false; } if (value != null ? !value.equals(captures.value) : captures.value != null) { return false; } return tail != null ? tail.equals(captures.tail) : captures.tail == null; }
@Override public Result apply(ExchangeNode exchange, Captures captures, Context context) { AggregationNode aggregation = captures.get(AGGREGATION); GroupIdNode groupId = captures.get(GROUP_ID); return transform(aggregation, groupId, context) .map(newAggregation -> { PlanNode newExchange = exchange.replaceChildren(ImmutableList.of(newAggregation)); return Result.ofPlanNode(newExchange); }) .orElseGet(Result::empty); } }