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 IrJoinFunction extends IrAbstractSet { 012 013 private final IrSetExpr take; 014 private final IrIntExpr[] refs; 015 private final Integer globalCardinality; 016 017 IrJoinFunction(IrSetExpr take, IrIntExpr[] refs, IrDomain env, IrDomain ker, IrDomain card, Integer globalCardinality) { 018 super(env, ker, card); 019 this.take = Check.notNull(take); 020 this.refs = Check.noNullsNotEmpty(refs); 021 this.globalCardinality = globalCardinality; 022 } 023 024 public IrSetExpr getTake() { 025 return take; 026 } 027 028 public IrIntExpr[] getRefs() { 029 return refs; 030 } 031 032 public boolean hasGlobalCardinality() { 033 return globalCardinality != null; 034 } 035 036 public Integer getGlobalCardinality() { 037 return globalCardinality; 038 } 039 040 @Override 041 public <A, B> B accept(IrSetExprVisitor<A, B> visitor, A a) { 042 return visitor.visit(this, a); 043 } 044 045 @Override 046 public boolean equals(Object obj) { 047 if (obj instanceof IrJoinFunction) { 048 IrJoinFunction other = (IrJoinFunction) obj; 049 return take.equals(other.take) && Arrays.equals(refs, other.refs) && Util.equals(globalCardinality, other.globalCardinality) && super.equals(other); 050 } 051 return false; 052 } 053 054 @Override 055 public int hashCode() { 056 return take.hashCode() ^ Arrays.hashCode(refs) ^ Util.hashCode(globalCardinality); 057 } 058 059 @Override 060 public String toString() { 061 return take + " . " + Arrays.toString(refs) 062 + (hasGlobalCardinality() ? " with global cardinality " + getGlobalCardinality() : ""); 063 } 064}