package de.dhbwstuttgart.strucTypes5.constraints;

import de.dhbwstuttgart.strucTypes5.algo.Type;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by sebastian on 21.04.17.
 */
public class InterfaceForConstraint {

    private TypeVarAbstract strucType;
    private List<TypeVarAbstract> generics;


    public InterfaceForConstraint(TypeVarAbstract strucType, List<TypeVarAbstract> generics) {
        this.strucType = strucType;
        this.generics = generics;
    }


    public boolean replaceTypeVarAbstract(TypeVarAbstract alt, TypeVarAbstract neu) {

       List<TypeVarAbstract> genericsneu = new ArrayList<>();

        for (TypeVarAbstract tv : generics) {
            if (tv.equals(alt)) {
                genericsneu.add(neu);
            }
            else {
                genericsneu.add(tv);
            }
        }

        generics = genericsneu;
        return  true;
    }



    public TypeVarAbstract getStrucType() {
        return strucType;
    }

    public void setStrucType(TypeVarAbstract strucType) {
        this.strucType = strucType;
    }

    public List<TypeVarAbstract> getGenerics() {
        return generics;
    }

    public void setGenerics(List<TypeVarAbstract> generics) {
        this.generics = generics;
    }

    @Override
    public String toString() {
        return String.format("sT %s <%s> " , strucType , generics);
    }
}
