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