KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jmock > examples > calculator > SimpleEnvironment


1 /* Copyright (c) 2000-2004 jMock.org
2  */

3 package org.jmock.examples.calculator;
4
5 import java.util.HashMap JavaDoc;
6
7
8 public class SimpleEnvironment implements Environment
9 {
10     public HashMap JavaDoc variables = new HashMap JavaDoc();
11
12
13     public Expression getVariable( String JavaDoc name ) throws CalculatorException {
14         if (variables.containsKey(name)) {
15             return (Expression)variables.get(name);
16         }
17         throw new CalculatorException("variable \"" + name + "\" not defined");
18     }
19
20     public void setVariable( String JavaDoc name, Expression expression ) {
21         variables.put(name, expression);
22     }
23 }
24
Popular Tags