package calc;

import java.util.HashMap;

/** Map from formula names to formulas
 * @author Gary T. Leavens
 */
public class FormulaMap {
	private static HashMap map = new HashMap();
	
    /**
     * Add the association of the name to the formula, 
     * replacing the old value if any.
     * @param name the formula's name
     * @param formula the formula
     */
    //@ requires name != null && formula != null;
	public static void put(String name, FormulaType formula) {
		map.put(name, formula);
	}

    /**
     * Retrieve the formula associated with the given name.
     * @param name the formula's name
     */
    //@ requires name != null;
    //@ ensures \result != null;
	public static FormulaType get(String name) {
		Object o = map.get(name);
		if (o == null) {
			throw new IllegalArgumentException(
				"Unknown formula name: " + name);
		} else {
			return (FormulaType) o;
		}
	}
	
    /**
     * Is the given name a defined name for a formula?
     */
	public static boolean isDefinedAt(String name) {
		return map.containsKey(name);
	}

}
