package aspectjhw.lambda;
import java.util.*;

/** Variable reference terms. */
public class Variable implements Term {
    /** The name of this Variable */
    protected final /*@ non_null @*/ String name;
    
    /** Initialize this Variable to have the given name. */
    //@ requires name != null;
    public Variable(String name) {
        this.name = name;
    }

    // doc comment inherited
    public Term reduce1Step() {
        return this;
    }

    // doc comment inherited
    public Set freeVars() {
        Set s = new HashSet();
        s.add(this.name);
        return s;
    }

    // doc comment inherited
    public Term substituteFor(String var, Term arg) {
        if (name.equals(var)) {
            return arg;
        } else {
            return this;
        }
    }

    // doc comment inherited
    public String toString() { 
        return name; 
    }
    
    // doc comment inherited
    public boolean equals(Object o) {
        return (o instanceof Variable) && name.equals( ((Variable)o).name );
    }
    
    // doc comment inherited
    public int hashCode() { 
        return name.hashCode(); 
    }  
}
