package de.dhbwstuttgart.strucTypes5.constraints;

import de.dhbwstuttgart.strucTypes5.typeVars.TypeVar;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract;

/**
 * Created by sebastian on 01.05.17.
 */
public class ConstraintShouldEqual extends ConstraintAbstract{

    private TypeVarAbstract t1;
    private TypeVarAbstract t2;

    public ConstraintShouldEqual(TypeVarAbstract t1, TypeVarAbstract t2) {
        this.t1 = t1;
        this.t2 = t2;
    }


    @Override
    public boolean replaceTypeVarAbstract(TypeVarAbstract alt, TypeVarAbstract neu) {
        if (t1.equals(alt)) {
            t1 = ConstraintAbstract.helpChange(alt,neu,t1);
        }
        if (t2.equals(alt)) {
            t2 = ConstraintAbstract.helpChange(alt,neu,t2);
        }
        ConstraintAbstract.helpChange2(alt,neu,t1);
        ConstraintAbstract.helpChange2(alt,neu,t2);
        return  true;
    }

    public TypeVarAbstract getT1() {
        return t1;
    }

    public void setT1(TypeVarAbstract t1) {
        this.t1 = t1;
    }

    public TypeVarAbstract getT2() {
        return t2;
    }

    public void setT2(TypeVarAbstract t2) {
        this.t2 = t2;
    }

    @Override
    public String toString() {
        return String.format("ConstraintShouldEqual( %s =* %s )" , t1, t2);
    }
}

