Source Code Cross Referenced for SymbolTable.java in  » Science » jcm1-source » edu » hws » jcm » data » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Science » jcm1 source » edu.hws.jcm.data 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*************************************************************************
002:         *                                                                        *
003:         *   1) This source code file, in unmodified form, and compiled classes   *
004:         *      derived from it can be used and distributed without restriction,  *
005:         *      including for commercial use.  (Attribution is not required       *
006:         *      but is appreciated.)                                              *
007:         *                                                                        *
008:         *    2) Modified versions of this file can be made and distributed       *
009:         *       provided:  the modified versions are put into a Java package     *
010:         *       different from the original package, edu.hws;  modified          *
011:         *       versions are distributed under the same terms as the original;   *
012:         *       and the modifications are documented in comments.  (Modification *
013:         *       here does not include simply making subclasses that belong to    *
014:         *       a package other than edu.hws, which can be done without any      *
015:         *       restriction.)                                                    *
016:         *                                                                        *
017:         *   David J. Eck                                                         *
018:         *   Department of Mathematics and Computer Science                       *
019:         *   Hobart and William Smith Colleges                                    *
020:         *   Geneva, New York 14456,   USA                                        *
021:         *   Email: eck@hws.edu          WWW: http://math.hws.edu/eck/            *
022:         *                                                                        *
023:         *************************************************************************/package edu.hws.jcm.data;
024:
025:        import java.util.Hashtable;
026:
027:        /**
028:         * A symbol table contains MathObjects, associating them
029:         * with their names.  To support scoping (for example), a symbol
030:         * table can have a parent symbol table.  If a symbol is not found
031:         * in the table itself, the search procedes to its parent.
032:         * MathObjects in the parent are hidden by MathObjects of
033:         * the same name in a SymbolTable.
034:         *    Note that a NullPointerException error will occur if an
035:         * attempt is made to add a MathObject with a null name to a
036:         * SymbolTable.
037:         *   A MathObject should not be renamed while it is registered
038:         * in a SymbolTable.
039:         *   Note that a Parser has an associated SymbolTable.  I expect
040:         * SymbolTables to be used only through Parsers.
041:         */
042:        public class SymbolTable implements  java.io.Serializable {
043:
044:            private Hashtable symbols; // Objects are stored here and in the parent.
045:            private SymbolTable parent; // Parent symbol table, possibly null.
046:
047:            /**
048:             * Construct a symbol table with null parent.
049:             */
050:            SymbolTable() {
051:                this (null);
052:            }
053:
054:            /**
055:             * Construct a symbol table with specified parent.
056:             */
057:            SymbolTable(SymbolTable parent) {
058:                this .parent = parent;
059:                symbols = new Hashtable();
060:            }
061:
062:            /**
063:             * Returns the parent symbol table of this symbol table.
064:             */
065:            SymbolTable getParent() {
066:                return parent;
067:            }
068:
069:            /**
070:             * Look up the object with the given name, if any.
071:             * If not found, return null.  (If the name is not found
072:             * in the HashTable, symbols, the search is delegated to
073:             * the parent.)  If the name is null, then
074:             * null is returned.
075:             */
076:            synchronized public MathObject get(String name) {
077:                if (name == null)
078:                    return null;
079:                Object sym = symbols.get(name);
080:                if (sym != null)
081:                    return (MathObject) sym;
082:                else if (parent != null)
083:                    return parent.get(name);
084:                else
085:                    return null;
086:            }
087:
088:            /**
089:             * Adds sym to the SymbolTable, associating it with its name.
090:             */
091:            synchronized public void add(MathObject sym) {
092:                if (sym == null)
093:                    throw new NullPointerException(
094:                            "Can't put a null symbol in SymbolTable.");
095:                add(sym.getName(), sym);
096:            }
097:
098:            /**
099:             * Adds the given MathObject, sym, to the symbol table,
100:             * associating it with the given name (which is probably
101:             * the name of the symbol or that name transformed to lower
102:             * case, but it doesn't have to be).
103:             *    If the same name is already in use in the HashTable
104:             * then the new object replaces the current object.
105:             * Note that if the name is defined in the parent
106:             * symbol table, then the old object is hidden, not
107:             * removed from the parent.  If sym is null or if
108:             * sym's name is null, than a NullPointerException is
109:             * thrown.
110:             */
111:            synchronized public void add(String name, MathObject sym) {
112:                if (sym == null)
113:                    throw new NullPointerException(
114:                            "Can't put a null symbol in SymbolTable.");
115:                else if (name == null)
116:                    throw new NullPointerException(
117:                            "Can't put unnamed MathObject in SymbolTable.");
118:                symbols.put(name, sym);
119:            }
120:
121:            /**
122:             * Remove the object with the given name from the symbol table,
123:             * but NOT from the parent symbol table.  No error occurs
124:             * if the name is not in the table or if name is null.
125:             * If an object of the same name occurs in the parent,
126:             * this routine will un-hide it.
127:             */
128:            synchronized public void remove(String name) {
129:                if (name != null)
130:                    symbols.remove(name);
131:            }
132:
133:        } // end class SymbolTable
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.