001package org.clafer.ir; 002 003import java.util.Arrays; 004import org.clafer.common.Check; 005import org.clafer.common.Util; 006 007/** 008 * 009 * @author jimmy 010 */ 011public class IrSetUnion extends IrAbstractSet { 012 013 private final IrSetExpr[] operands; 014 private final boolean disjoint; 015 016 IrSetUnion(IrSetExpr[] operands, IrDomain env, IrDomain ker, IrDomain card, boolean disjoint) { 017 super(env, ker, card); 018 this.operands = Check.noNullsNotEmpty(operands); 019 this.disjoint = disjoint; 020 } 021 022 public IrSetExpr[] getOperands() { 023 return operands; 024 } 025 026 public boolean isDisjoint() { 027 return disjoint; 028 } 029 030 @Override 031 public <A, B> B accept(IrSetExprVisitor<A, B> visitor, A a) { 032 return visitor.visit(this, a); 033 } 034 035 @Override 036 public boolean equals(Object obj) { 037 if (obj instanceof IrSetUnion) { 038 IrSetUnion other = (IrSetUnion) obj; 039 return Arrays.equals(operands, other.operands) 040 && disjoint == other.disjoint 041 && super.equals(other); 042 } 043 return false; 044 } 045 046 @Override 047 public int hashCode() { 048 return Arrays.hashCode(operands) ^ (disjoint ? 1231 : 1237); 049 } 050 051 @Override 052 public String toString() { 053 return "(" + Util.intercalate(") ∪ (", operands) + ")" + (disjoint ? " where disjoint" : ""); 054 } 055}