/** * Gather the component operands of a union or intersect expression * @param operator union or intersect * @param set the set into which the components are to be gathered. If the operator * is union, this follows the tree gathering all operands of union expressions. Ditto, * mutatis mutandis, for intersect expressions. */ public void gatherComponents(int operator, Set set) { if (operand0 instanceof VennExpression && ((VennExpression)operand0).operator == operator) { ((VennExpression)operand0).gatherComponents(operator, set); } else { set.add(operand0); } if (operand1 instanceof VennExpression && ((VennExpression)operand1).operator == operator) { ((VennExpression)operand1).gatherComponents(operator, set); } else { set.add(operand1); } }
/** * Is this expression the same as another expression? */ public boolean equals(Object other) { // NOTE: it's possible that the method in the superclass is already adequate for this if (other instanceof VennExpression) { VennExpression b = (VennExpression)other; if (operator != b.operator) { return false; } if (operand0.equals(b.operand0) && operand1.equals(b.operand1)) { return true; } if (operator == Token.UNION || operator == Token.INTERSECT) { // These are commutative and associative, so for example (A|B)|C equals B|(A|C) Set s0 = new HashSet(10); gatherComponents(operator, s0); Set s1 = new HashSet(10); ((VennExpression)other).gatherComponents(operator, s1); return s0.equals(s1); } } return false; }
/** * Is this expression the same as another expression? */ public boolean equals(Object other) { // NOTE: it's possible that the method in the superclass is already adequate for this if (other instanceof VennExpression) { VennExpression b = (VennExpression) other; if (operator != b.operator) { return false; } if (getLhsExpression().isEqual(b.getLhsExpression()) && getRhsExpression().isEqual(b.getRhsExpression())) { return true; } if (operator == Token.UNION || operator == Token.INTERSECT) { // These are commutative and associative, so for example (A|B)|C equals B|(A|C) Set<Expression> s0 = new HashSet<>(10); gatherComponents(operator, s0); Set<Expression> s1 = new HashSet<>(10); ((VennExpression) other).gatherComponents(operator, s1); return s0.equals(s1); } } return false; }
/** * Is this expression the same as another expression? */ public boolean equals(Object other) { // NOTE: it's possible that the method in the superclass is already adequate for this if (other instanceof VennExpression) { VennExpression b = (VennExpression) other; if (operator != b.operator) { return false; } if (getLhsExpression().isEqual(b.getLhsExpression()) && getRhsExpression().isEqual(b.getRhsExpression())) { return true; } if (operator == Token.UNION || operator == Token.INTERSECT) { // These are commutative and associative, so for example (A|B)|C equals B|(A|C) Set<Expression> s0 = new HashSet<>(10); gatherComponents(operator, s0); Set<Expression> s1 = new HashSet<>(10); ((VennExpression) other).gatherComponents(operator, s1); return s0.equals(s1); } } return false; }
/** * Gather the component operands of a union or intersect expression * * @param operator union or intersect * @param set the set into which the components are to be gathered. If the operator * is union, this follows the tree gathering all operands of union expressions. Ditto, * mutatis mutandis, for intersect expressions. */ public void gatherComponents(int operator, Set<Expression> set) { if (getLhsExpression() instanceof VennExpression && ((VennExpression) getLhsExpression()).operator == operator) { ((VennExpression) getLhsExpression()).gatherComponents(operator, set); } else { set.add(getLhsExpression()); } if (getRhsExpression() instanceof VennExpression && ((VennExpression) getRhsExpression()).operator == operator) { ((VennExpression) getRhsExpression()).gatherComponents(operator, set); } else { set.add(getRhsExpression()); } }
/** * Gather the component operands of a union or intersect expression * * @param operator union or intersect * @param set the set into which the components are to be gathered. If the operator * is union, this follows the tree gathering all operands of union expressions. Ditto, * mutatis mutandis, for intersect expressions. */ public void gatherComponents(int operator, Set<Expression> set) { if (getLhsExpression() instanceof VennExpression && ((VennExpression) getLhsExpression()).operator == operator) { ((VennExpression) getLhsExpression()).gatherComponents(operator, set); } else { set.add(getLhsExpression()); } if (getRhsExpression() instanceof VennExpression && ((VennExpression) getRhsExpression()).operator == operator) { ((VennExpression) getRhsExpression()).gatherComponents(operator, set); } else { set.add(getRhsExpression()); } }