001package org.clafer.ir; 002 003import org.clafer.common.Check; 004 005/** 006 * 007 * @author jimmy 008 */ 009public class IrMask extends IrAbstractSet { 010 011 private final IrSetExpr set; 012 private final int from; 013 private final int to; 014 015 IrMask(IrSetExpr set, int from, int to, IrDomain env, IrDomain ker, IrDomain card) { 016 super(env, ker, card); 017 018 if (from > to) { 019 throw new IllegalArgumentException(); 020 } 021 022 this.set = Check.notNull(set); 023 this.from = from; 024 this.to = to; 025 } 026 027 public IrSetExpr getSet() { 028 return set; 029 } 030 031 public int getFrom() { 032 return from; 033 } 034 035 public int getTo() { 036 return to; 037 } 038 039 @Override 040 public <A, B> B accept(IrSetExprVisitor<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 IrMask) { 047 IrMask other = (IrMask) obj; 048 return set.equals(other.set) & from == other.from && to == other.to && super.equals(other); 049 } 050 return false; 051 } 052 053 @Override 054 public int hashCode() { 055 return set.hashCode() ^ from ^ to; 056 } 057 058 @Override 059 public String toString() { 060 return set + " mask [" + from + ", " + to + "]"; 061 } 062}