package org.clafer.ir;

import java.util.Arrays;
import org.clafer.common.Check;
import org.clafer.domain.BoolDomain;

/**
 *
 * @author jimmy
 */
public class IrSortSets extends IrAbstractBool {

    private final IrSetExpr[] sets;
    private final IrIntExpr[] bounds;

    public IrSortSets(IrSetExpr[] sets, IrIntExpr[] bounds, BoolDomain domain) {
        super(domain);
        if (sets.length != bounds.length) {
            throw new IllegalArgumentException();
        }
        this.sets = Check.noNullsNotEmpty(sets);
        this.bounds = Check.noNullsNotEmpty(bounds);
    }

    public IrSetExpr[] getSets() {
        return sets;
    }

    public IrIntExpr[] getBounds() {
        return bounds;
    }

    @Override
    public IrBoolExpr negate() {
        return new IrNot(this, getDomain().invert());
    }

    @Override
    public boolean isNegative() {
        return false;
    }

    @Override
    public <A, B> B accept(IrBoolExprVisitor<A, B> visitor, A a) {
        return visitor.visit(this, a);
    }

    @Override
    public <A, B> B accept(IrIntExprVisitor<A, B> visitor, A a) {
        return visitor.visit(this, a);
    }

    @Override
    public boolean equals(Object obj) {
        if (obj instanceof IrSortSets) {
            IrSortSets other = (IrSortSets) obj;
            return Arrays.equals(sets, other.sets) && Arrays.equals(bounds, other.bounds);
        }
        return false;
    }

    @Override
    public int hashCode() {
        return Arrays.deepHashCode(sets) ^ Arrays.deepHashCode(bounds);
    }
}

@@ -1543,11 +1543,158 @@
 );%0A    %7D
+%0A%0A    @Override%0A    public String toString() %7B%0A        return %22SortSet %22 + Arrays.toString(sets) + %22 with bounds %22 + Arrays.toString(bounds);%0A    %7D
 %0A%7D%0A

Implement toString method for IR sort sets.