/** * Convert this object to a string. * * @return A string representation of this object. */ public String toString() { StringBuffer buffer = new StringBuffer("(" + getName()); Iterator<ConstraintExpression> i = getElements().iterator(); while (i.hasNext()) { buffer.append(i.next().toString()); if (i.hasNext()) buffer.append(" "); } buffer.append(")"); return buffer.toString(); }
public static List<ConstraintExpression> replaceOperationArgs(Map<Variable,ValueElement> bindings, ConstraintOperation constraint) throws QueryException { List<ConstraintExpression> newArgs = new ArrayList<ConstraintExpression>(); for (ConstraintExpression expr: constraint.getElements()) { newArgs.add(bindVariables(bindings, expr)); } return newArgs; } }
public List<Tuples> resolveConstraintOperation(ModelExpression modelExpr, ConstraintOperation constraintOper) throws QueryException { LinkedList<Tuples> result = new LinkedList<Tuples>(); for (ConstraintExpression constraintExpr: constraintOper.getElements()) { result.add(ConstraintOperations.resolveConstraintExpression(this, modelExpr, constraintExpr)); } return result; }
/** * Get all constraints which are variables. For back-compatibility, this * method currently ignores the fourth element of the triple. * * @return A set containing all variable constraints. */ public Set<Variable> getVariables() { // Check to see if there variables have been retrieved. if (variables == null) { Set<Variable> v = new HashSet<Variable>(); for (ConstraintExpression expr: getElements()) v.addAll(expr.getVariables()); variables = Collections.unmodifiableSet(v); } return variables; }
/** * Construct a constraint operation. Subclasses are compelled to use this * constructor, guaranteeing that the operands are always non-<code>null</code> * . * * @param lhs a non-<code>null</code> model expression * @param rhs another non-<code>null</code> model expression */ protected ConstraintOperation(ConstraintExpression lhs, ConstraintExpression rhs) { // Validate "lhs" parameter if (lhs == null) throw new IllegalArgumentException("Null \"lhs\" parameter"); // Validate "rhs" parameter if (rhs == null) throw new IllegalArgumentException("Null \"rhs\" parameter"); // Initialize fields elements = new ArrayList<ConstraintExpression>(2); // Add the LHS if (lhs.getClass().equals(getClass())) { elements.addAll(((ConstraintOperation)lhs).getElements()); } else { elements.add(lhs); } // Add the RHS if (rhs.getClass().equals(getClass())) { elements.addAll( ( (ConstraintOperation) rhs).getElements()); } else { elements.add(rhs); } }