package org.clafer.ir;

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

/**
 *
 * @author jimmy
 */
public class IrStringVar extends IrAbstractString implements IrVar {

    private final String name;
    private final IrIntVar[] chars;
    private final IrIntVar length;

    protected IrStringVar(String name, IrIntVar[] chars, IrIntVar length) {
        super(getCharDomains(Check.noNulls(chars)), Check.notNull(length).getDomain());
        this.name = Check.notNull(name);
        this.chars = chars;
        this.length = length;
    }

    private static Domain[] getCharDomains(IrIntExpr[] chars) {
        Domain[] charDomains = new Domain[chars.length];
        for (int i = 0; i < charDomains.length; i++) {
            charDomains[i] = chars[i].getDomain();
        }
        return charDomains;
    }

    @Override
    public String getName() {
        return name;
    }

    public IrIntVar[] getCharVars() {
        return chars;
    }

    public IrIntVar getLengthVar() {
        return length;
    }

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

    @Override
    public boolean equals(Object obj) {
        return this == obj;
    }

    @Override
    public int hashCode() {
        return name.hashCode();
    }

    @Override
    public String toString() {
        return Arrays.toString(chars) + "[length=" + length + "]";
    }
}

@@ -1252,26 +1252,270 @@
     
-return this == obj
+if (this == obj) %7B%0A            return true;%0A        %7D%0A        if (obj instanceof IrStringVar) %7B%0A            IrStringVar other = (IrStringVar) obj;%0A            return length.equals(other.length) && Arrays.equals(chars, other.chars);%0A        %7D%0A        return false
 ;%0A  
@@ -1576,20 +1576,47 @@
  return 
-name
+Arrays.hashCode(chars) %5E length
 .hashCod

Use the fields to compute equals and hashCode of IR string variables.