001package org.clafer.ast;
002
003import java.util.Arrays;
004import org.clafer.common.Check;
005
006/**
007 * A constant set.
008 * 
009 * @author jimmy
010 */
011public class AstConstant implements AstSetExpr {
012
013    private final AstClafer type;
014    private final int[] value;
015
016    /**
017     * 
018     * @param type the type
019     * @param value the value, must be sorted
020     */
021    AstConstant(AstClafer type, int... value) {
022        this.type = Check.notNull(type);
023        this.value = Check.notNull(value);
024    }
025
026    public AstClafer getType() {
027        return type;
028    }
029
030    public int[] getValue() {
031        return value;
032    }
033
034    @Override
035    public <A, B> B accept(AstExprVisitor<A, B> visitor, A a) {
036        return visitor.visit(this, a);
037    }
038
039    @Override
040    public String toString() {
041        if (value.length == 1 && type instanceof AstIntClafer) {
042            return Integer.toString(value[0]);
043        }
044        return Arrays.toString(value) + "::" + type;
045    }
046}