package de.dhbwstuttgart.strucTypes5.typeVars;

import de.dhbwstuttgart.strucTypes5.constraints.InterfaceForConstraint;

/**
 * Created by sebastian on 30.04.17.
 */
public class TypeVarInterface extends TypeVarAbstract {


    private InterfaceForConstraint interfaceForConstraint;


    public TypeVarInterface(InterfaceForConstraint interfaceForConstraint) {
        this.interfaceForConstraint = interfaceForConstraint;
    }

    public InterfaceForConstraint getInterfaceForConstraint() {
        return interfaceForConstraint;
    }

    public void setInterfaceForConstraint(InterfaceForConstraint interfaceForConstraint) {
        this.interfaceForConstraint = interfaceForConstraint;
    }





    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof TypeVarInterface)) return false;

        TypeVarInterface that = (TypeVarInterface) o;

        return getInterfaceForConstraint() != null ? getInterfaceForConstraint().equals(that.getInterfaceForConstraint()) : that.getInterfaceForConstraint() == null;
    }



    // Equal_for_Unify
    public boolean equalsForUnify(TypeVarAbstract tv) {

        if (tv instanceof  TypeVarInterface) {
            String name = ((TypeVarInterface) tv).getInterfaceForConstraint().getStrucType().toString();
            String name2 = getInterfaceForConstraint().getStrucType().toString();
            if (name.equals(name2)) {
                return true;
            }
            else {
                return false;
            }
        }

        return false;
    }






    @Override
    public String toString() {
        return String.format("TVar_%s" ,   interfaceForConstraint.toString());
    }
}
