KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lsmp > djep > xjep > XSymbolTable


1 /*****************************************************************************
2
3 JEP - Java Math Expression Parser 2.3.0
4       October 3 2004
5       (c) Copyright 2004, Nathan Funk and Richard Morris
6       See LICENSE.txt for license information.
7
8 *****************************************************************************/

9 package org.lsmp.djep.xjep;
10 import java.util.*;
11 import org.nfunk.jep.*;
12
13 /**
14  * An extension of the symbol table with a few new features.
15  *
16  * @author Rich Morris
17  * Created on 18-Mar-2004
18  */

19 public class XSymbolTable extends SymbolTable
20 {
21     /**
22      * Create a new XSymbolTable with the given variable factory.
23      */

24     public XSymbolTable(VariableFactory varFac)
25     {
26         super(varFac);
27     }
28     
29     /** Creates a new SymbolTable with the same variable factory as this. */
30     public SymbolTable newInstance()
31     {
32         return new XSymbolTable(vf);
33     }
34
35     /** Prints the contents of the symbol table displaying its equations and value. */
36     public void print(PrintVisitor pv)
37     {
38         for(Enumeration e = this.elements(); e.hasMoreElements(); )
39         {
40             XVariable var = (XVariable) e.nextElement();
41             pv.append(var.toString(pv)+"\n");
42             // TODO watchout for posible conflict with overriding pv's string buffer
43
}
44     }
45     
46     /** Copy the values of all constants into this from the supplied symbol table. */
47     public void copyConstants(SymbolTable symTab)
48     {
49         for(Enumeration e = symTab.elements(); e.hasMoreElements(); )
50         {
51             Variable var = (Variable) e.nextElement();
52             if(var.isConstant())
53                 this.addConstant(var.getName(),var.getValue());
54         }
55     }
56 }
57
Popular Tags