/** * Creates a hash code, based on the child expressions and the current operation type. * * @return The hash code for this object. */ public int hashCode() { Set<ModelExpression> myExpressions = new HashSet<ModelExpression>(); flattenExpression(myExpressions, getClass()); return (getClass().hashCode() * 7) + myExpressions.hashCode(); }
public Tuples resolve(QueryEvaluationContext context, ModelExpression modelExpr, Constraint constraint) throws Exception { Tuples lhs = ConstraintOperations. resolveModelExpression(context, ((ModelOperation)modelExpr).getLHS(), constraint); Tuples rhs = ConstraintOperations. resolveModelExpression(context, ((ModelOperation)modelExpr).getRHS(), constraint); try { return TuplesOperations.append(lhs, rhs); } finally { lhs.close(); rhs.close(); } } }),
public Tuples resolve(QueryEvaluationContext context, ModelExpression modelExpr, Constraint constraint) throws Exception { Tuples lhs = ConstraintOperations. resolveModelExpression(context, ((ModelOperation)modelExpr).getLHS(), constraint); Tuples rhs = ConstraintOperations. resolveModelExpression(context, ((ModelOperation)modelExpr).getRHS(), constraint); try { return TuplesOperations.join(lhs, rhs); } finally { lhs.close(); rhs.close(); } } }),
/** * Traverse down the binary tree of the current object, and merge any nodes * of the current type into a flattened set. * * @param expressions The set to be built up containing all nodes being * operated on in the same way. * @param type The class representing the operation type. */ private void flattenExpression(Set<ModelExpression> expressions, Class<?> type) { if (lhs.getClass().equals(type)) { ((ModelOperation)lhs).flattenExpression(expressions, type); } else { expressions.add(lhs); } if (rhs.getClass().equals(type)) { ((ModelOperation)rhs).flattenExpression(expressions, type); } else { expressions.add(rhs); } }
/** * Transform to an equivalent WHERE clause expression. * * @param m The object to compare against. * @return <code>true</code> if the objects are the same type, * and applied to the same operands */ public boolean equals(Object m) { if (!(m instanceof ModelOperation)) return false; if ((m == null) || !m.getClass().equals(getClass())) return false; if (m == this) return true; Class<?> type = m.getClass(); Set<ModelExpression> otherExpressions = new HashSet<ModelExpression>(); ((ModelOperation)m).flattenExpression(otherExpressions, type); Set<ModelExpression> myExpressions = new HashSet<ModelExpression>(); flattenExpression(myExpressions, type); return myExpressions.equals(otherExpressions); }