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 IrAllDifferent extends IrAbstractBool implements IrBoolExpr { 012 013 private final IrIntExpr[] operands; 014 015 IrAllDifferent(IrIntExpr[] operands, IrBoolDomain domain) { 016 super(domain); 017 this.operands = Check.noNullsNotEmpty(operands); 018 } 019 020 public IrIntExpr[] getOperands() { 021 return operands; 022 } 023 024 @Override 025 public boolean isNegative() { 026 return false; 027 } 028 029 @Override 030 public IrBoolExpr negate() { 031 return new IrNot(this, getDomain().invert()); 032 } 033 034 @Override 035 public <A, B> B accept(IrBoolExprVisitor<A, B> visitor, A a) { 036 return visitor.visit(this, a); 037 } 038 039 @Override 040 public <A, B> B accept(IrIntExprVisitor<A, B> visitor, A a) { 041 return visitor.visit(this, a); 042 } 043 044 @Override 045 public boolean equals(Object obj) { 046 if (obj instanceof IrAllDifferent) { 047 IrAllDifferent other = (IrAllDifferent) obj; 048 return Arrays.equals(operands, other.operands); 049 } 050 return false; 051 } 052 053 @Override 054 public int hashCode() { 055 return Arrays.hashCode(operands); 056 } 057 058 @Override 059 public String toString() { 060 return "allDifferent(" + Util.commaSeparate(operands) + ")"; 061 } 062}