static List<HasContainer> splitAndP(final List<HasContainer> hasContainers, final Iterable<HasContainer> has) { has.forEach(hasContainer -> { if (hasContainer.getPredicate() instanceof AndP) { for (final P<?> predicate : ((AndP<?>) hasContainer.getPredicate()).getPredicates()) { hasContainers.add(new HasContainer(hasContainer.getKey(), predicate)); } } else hasContainers.add(hasContainer); }); return hasContainers; }
switch (predicate) { case "and": return new AndP((List<P>) value); case "or": return new OrP((List<P>) value);
public AndP(final List<P<V>> predicates) { super(predicates); for (final P<V> p : predicates) { this.and(p); } this.biPredicate = new AndBiPredicate(this); }
@Override public P<V> and(final Predicate<? super V> predicate) { if (!(predicate instanceof P)) throw new IllegalArgumentException("Only P predicates can be and'd together"); else if (predicate instanceof AndP) this.predicates.addAll(((AndP) predicate).getPredicates()); else this.predicates.add((P<V>) predicate); return this; }
@Override public P<V> and(final Predicate<? super V> predicate) { if (!(predicate instanceof P)) throw new IllegalArgumentException("Only P predicates can be and'd together"); return new AndP<>(Arrays.asList(this, (P<V>) predicate)); }
public AndP(final List<P<V>> predicates) { super(predicates); for (final P<V> p : predicates) { this.and(p); } this.biPredicate = new AndBiPredicate(this); }
@Override public void addHasContainer(final HasContainer hasContainer) { if (hasContainer.getPredicate() instanceof AndP) { for (final P<?> predicate : ((AndP<?>) hasContainer.getPredicate()).getPredicates()) { this.addHasContainer(new HasContainer(hasContainer.getKey(), predicate)); } } else this.hasContainers.add(hasContainer); }
@Override public P<V> and(final Predicate<? super V> predicate) { if (!(predicate instanceof P)) throw new IllegalArgumentException("Only P predicates can be and'd together"); return new AndP<>(Arrays.asList(this, (P<V>) predicate)); }
@Override public void addHasContainer(final HasContainer hasContainer) { if (hasContainer.getPredicate() instanceof AndP) { for (final P<?> predicate : ((AndP<?>) hasContainer.getPredicate()).getPredicates()) { this.addHasContainer(new HasContainer(hasContainer.getKey(), predicate)); } } else this.hasContainers.add(hasContainer); }
@Override public P<V> negate() { super.negate(); return new AndP<>(this.predicates); }
public static Condition convAnd(HugeGraph graph, HugeType type, HasContainer has) { P<?> p = has.getPredicate(); assert p instanceof AndP; @SuppressWarnings("unchecked") List<P<Object>> predicates = ((AndP<Object>) p).getPredicates(); if (predicates.size() < 2) { throw newUnsupportedPredicate(p); } Condition cond = null; for (P<Object> predicate : predicates) { HasContainer newHas = new HasContainer(has.getKey(), predicate); Condition newCond = convHas2Condition(newHas, type, graph); if (cond == null) { cond = newCond; } else { cond = Condition.and(newCond, cond); } } return cond; }
/** * Determines if a value is within (inclusive) of the range of the two specified values. * * @since 3.0.0-incubating */ public static <V> P<V> between(final V first, final V second) { return new AndP<V>(Arrays.asList(new P(Compare.gte, first), new P(Compare.lt, second))); }
@Override public P<V> and(final Predicate<? super V> predicate) { if (!(predicate instanceof P)) throw new IllegalArgumentException("Only P predicates can be and'd together"); else if (predicate instanceof AndP) this.predicates.addAll(((AndP) predicate).getPredicates()); else this.predicates.add((P<V>) predicate); return this; }
/** * Determines if a value is within (exclusive) the range of the two specified values. * * @since 3.0.0-incubating */ public static <V> P<V> inside(final V first, final V second) { return new AndP<V>(Arrays.asList(new P(Compare.gt, first), new P(Compare.lt, second))); }
private List<HasContainer> optimizeBetween(ReplacedStep<?, ?> replacedStep, List<HasContainer> hasContainers) { List<HasContainer> result = new ArrayList<>(); for (HasContainer hasContainer : hasContainers) { if (hasContainerKeyNotIdOrLabel(hasContainer) && hasContainer.getPredicate() instanceof AndP) { AndP<?> andP = (AndP) hasContainer.getPredicate(); List<? extends P<?>> predicates = andP.getPredicates(); if (predicates.size() == 2) { if (predicates.get(0).getBiPredicate() == Compare.gte && predicates.get(1).getBiPredicate() == Compare.lt) { replacedStep.addHasContainer(hasContainer); result.add(hasContainer); } } } } return result; }
return predicate.equals("and") ? new AndP((List<P>) value) : new OrP((List<P>) value); else if (value instanceof Collection) { if (predicate.equals("between"))
private List<HasContainer> optimizeInside(ReplacedStep<?, ?> replacedStep, List<HasContainer> hasContainers) { List<HasContainer> result = new ArrayList<>(); for (HasContainer hasContainer : hasContainers) { if (hasContainerKeyNotIdOrLabel(hasContainer) && hasContainer.getPredicate() instanceof AndP) { AndP<?> andP = (AndP) hasContainer.getPredicate(); List<? extends P<?>> predicates = andP.getPredicates(); if (predicates.size() == 2) { if (predicates.get(0).getBiPredicate() == Compare.gt && predicates.get(1).getBiPredicate() == Compare.lt) { replacedStep.addHasContainer(hasContainer); result.add(hasContainer); } } } } return result; }
return predicate.equals("and") ? new AndP((List<P>) value) : new OrP((List<P>) value); else if (value instanceof Collection) { if (predicate.equals("between"))
private List<HasContainer> optimizeInside(ReplacedStep<?, ?> replacedStep, List<HasContainer> hasContainers) { List<HasContainer> result = new ArrayList<>(); for (HasContainer hasContainer : hasContainers) { if (hasContainerKeyNotIdOrLabel(hasContainer) && hasContainer.getPredicate() instanceof AndP) { AndP<?> andP = (AndP) hasContainer.getPredicate(); List<? extends P<?>> predicates = andP.getPredicates(); if (predicates.size() == 2) { if (predicates.get(0).getBiPredicate() == Compare.gt && predicates.get(1).getBiPredicate() == Compare.lt) { replacedStep.addHasContainer(hasContainer); result.add(hasContainer); } } } } return result; }
return predicate.equals(GraphSONTokens.AND) ? new AndP((List<P>) value) : new OrP((List<P>) value); } else if (predicate.equals(GraphSONTokens.NOT) && value instanceof P) { return P.not((P<?>) value);