/** * {@inheritDoc} */ public void accept(final PredicateVisitor predicateVisitor) { predicateVisitor.visit(this); }
/** * Constructor. Creates a new node with the given type. * * @param type type of this logical node. */ public LogicalNode(final Type type) { super(); this.type = type; this.name = type.getName(); }
@Override public String toString() { return "LogicalNode [name=" + name + ", type=" + type + ", children=" + getChildren() + "]"; }
@Override public void visit(final MultiComparisonNode node) { checkNotNull(node, "multi comparison node"); final FilterFieldExpression field = fieldExprFactory.filterBy(node.getComparisonProperty()); final MultiComparisonNode.Type type = node.getComparisonType(); final List<Object> values = node.getComparisonValue(); if (type == MultiComparisonNode.Type.IN) { criteria.add(criteriaFactory.fieldCriteria(field, criteriaFactory.in(values))); } else { throwUnknownType(type); } }
@Override public void visit(final LogicalNode node) { checkNotNull(node, "logical node"); final LogicalNode.Type type = node.getType(); final ParameterPredicateVisitor childVisitor = new ParameterPredicateVisitor(criteriaFactory, fieldExprFactory); node.getChildren().forEach(child -> child.accept(childVisitor)); switch (type) { case AND: criteria.add(criteriaFactory.and(childVisitor.getCriteria())); break; case OR: criteria.add(criteriaFactory.or(childVisitor.getCriteria())); break; case NOT: criteria.add(criteriaFactory.nor(childVisitor.getCriteria())); break; default: throwUnknownType(type); } }
/** * Constructor. Creates a new node with the given type. * * @param type type of this logical node. * @param subNodes the Nodes to add directly as children. */ public LogicalNode(final Type type, final Collection<Node> subNodes) { super(); this.type = type; this.name = type.getName(); getChildren().addAll(subNodes); }
@Override public void visit(final SingleComparisonNode node) { checkNotNull(node, "single comparison node"); final FilterFieldExpression field = fieldExprFactory.filterBy(node.getComparisonProperty()); final SingleComparisonNode.Type type = node.getComparisonType(); final Object value = node.getComparisonValue(); final BiFunction<CriteriaFactory, Object, Predicate> predicateFactory = SINGLE_COMPARISON_NODE_MAPPING.get(type); if (predicateFactory == null) { throwUnknownType(type); } final Predicate predicate = predicateFactory.apply(criteriaFactory, value); criteria.add(criteriaFactory.fieldCriteria(field, predicate)); }
@Override public void visit(final RootNode node) { node.getChildren().forEach(child -> child.accept(this)); }
/** * Add the given value to the list of values. * * @param value the value to add. */ public void addValue(final Object value) { this.getComparisonValue().add(value); }
/** * Constructor. Creates a new node with the given name. * * @param name name of this logical node. */ public LogicalNode(final String name) { super(); this.name = requireNonNull(name); this.type = Type.byName(name); }
@SuppressWarnings("squid:MethodCyclomaticComplexity") @Override public boolean equals(final Object obj) { if (this == obj) { return true; } if (!super.equals(obj)) { return false; } if (getClass() != obj.getClass()) { return false; } final LogicalNode other = (LogicalNode) obj; if (name == null) { if (other.name != null) { return false; } } else if (!name.equals(other.name)) { return false; } if (type != other.type) { return false; } return true; } // CS:ON equals(Object obj)
@Override public void visit(final ExistsNode node) { checkNotNull(node, "exists node"); final ExistsFieldExpression field = fieldExprFactory.existsBy(node.getProperty()); criteria.add(criteriaFactory.existsCriteria(field)); }
/** * {@inheritDoc} */ public void accept(final PredicateVisitor predicateVisitor) { predicateVisitor.visit(this); }
/** * {@inheritDoc} */ public void accept(final PredicateVisitor predicateVisitor) { predicateVisitor.visit(this); }
/** * {@inheritDoc} */ public void accept(final PredicateVisitor predicateVisitor) { predicateVisitor.visit(this); }
@Override public void accept(PredicateVisitor predicateVisitor) { predicateVisitor.visit(this); }
@Override public void accept(final PredicateVisitor predicateVisitor) { predicateVisitor.visit(this); }