Source Code Cross Referenced for Symbol.java in  » Science » jmatlab » org » jmatlab » semantic » 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 » jmatlab » org.jmatlab.semantic 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.jmatlab.semantic;
002:
003:        import java.io.Serializable;
004:        import java.util.List;
005:        import java.util.Vector;
006:
007:        import org.jmatlab.linalg.DefaultComplexImpl;
008:        import org.jmatlab.linalg.DefaultMatrixImpl;
009:        import org.jmatlab.linalg.ICell;
010:        import org.jmatlab.linalg.IComplex;
011:        import org.jmatlab.linalg.IMatrix;
012:        import org.jmatlab.linalg.IStruct;
013:        import org.jmatlab.util.FormatNumber;
014:
015:        /**
016:         * User: Ali
017:         * Date: Jun 18, 2003
018:         * Time: 9:36:03 AM
019:         */
020:        public class Symbol implements  Serializable {
021:            //TODO: make it fail safe by checking type before get
022:            private int type = DataType.INVALID;
023:            private String name;
024:            private Object value;
025:
026:            public Symbol(String name) {
027:                this .name = name;
028:                this .type = DataType.UNDEFINED;
029:            }
030:
031:            public Symbol(Symbol symbol) {
032:                this .name = symbol.getName();
033:                this .type = symbol.getType();
034:                if (type == DataType.MATRIX) {
035:                    this .value = new DefaultMatrixImpl(symbol.getMatrix());
036:                } else {
037:                    this .value = symbol.getValue();
038:                }
039:            }
040:
041:            public Symbol(String name, Symbol symbol) {
042:                this .name = name;
043:                this .type = symbol.getType();
044:                this .value = symbol.getValue();
045:            }
046:
047:            private Object getValue() {
048:                return this .value;
049:            }
050:
051:            public Symbol(String name, Object value) {
052:                this .name = name;
053:                setValue(value);
054:            }
055:
056:            public void setType(int type) {
057:                this .type = type;
058:            }
059:
060:            public void setCorrectType() {
061:                if (value instanceof  Double) {
062:                    this .type = DataType.DOUBLE;
063:                } else if (value instanceof  String) {
064:                    this .type = DataType.STRING;
065:                } else if (value instanceof  IMatrix) {
066:                    this .type = DataType.MATRIX;
067:                } else if (value instanceof  Boolean) {
068:                    this .type = DataType.BOOLEAN;
069:                } else if (value instanceof  IComplex) {
070:                    this .type = DataType.COMPLEX;
071:                } else if (value instanceof  IStruct) {
072:                    this .type = DataType.STRUCT;
073:                } else if (value instanceof  ICell) {
074:                    this .type = DataType.CELL;
075:                } else if (value instanceof  Vector) {
076:                    this .type = DataType.VECTOR;
077:                } else if (value instanceof  List) {
078:                    this .type = DataType.LIST;
079:                }
080:            }
081:
082:            public void setValue(Object value) {
083:                this .value = value;
084:                setCorrectType();
085:            }
086:
087:            public List getList() {
088:                if (type == DataType.LIST) {
089:                    return (List) value;
090:                } else {
091:                    return null;
092:                }
093:            }
094:
095:            public Boolean getBoolean() {
096:                if (type == DataType.BOOLEAN) {
097:                    return (Boolean) value;
098:                } else {
099:                    return null;
100:                }
101:            }
102:
103:            public IMatrix getMatrix() {
104:                if (type == DataType.MATRIX) {
105:                    return (IMatrix) value;
106:                } else {
107:                    return null;
108:                }
109:            }
110:
111:            public IStruct getStruct() {
112:                if (type == DataType.STRUCT) {
113:                    return (IStruct) value;
114:                } else {
115:                    return null;
116:                }
117:            }
118:
119:            public ICell getCell() {
120:                if (type == DataType.CELL) {
121:                    return (ICell) value;
122:                } else {
123:                    return null;
124:                }
125:            }
126:
127:            public IComplex getComplex() {
128:                if (type == DataType.DOUBLE) {
129:                    IComplex c = new DefaultComplexImpl(((Double) value)
130:                            .doubleValue(), 0);
131:                    return c;
132:                }
133:                if (type == DataType.COMPLEX) {
134:                    return (IComplex) value;
135:                } else {
136:                    return null;
137:                }
138:            }
139:
140:            public Double getDouble() {
141:                if (type == DataType.DOUBLE) {
142:                    return (Double) value;
143:                } else {
144:                    return null;
145:                }
146:            }
147:
148:            public int getType() {
149:                return type;
150:            }
151:
152:            public String getString() {
153:                if (type == DataType.STRING) {
154:                    return (String) value;
155:                } else {
156:                    return null;
157:                }
158:            }
159:
160:            public String getName() {
161:                return name;
162:            }
163:
164:            public void setName(String name) {
165:                this .name = name;
166:            }
167:
168:            public String toString() {
169:                String output = null;
170:                if (type == DataType.MATRIX) {
171:                    output = getMatrix().toString();
172:                } else if (type == DataType.COMPLEX) {
173:                    output = getComplex().toString();
174:                } else if (type == DataType.DOUBLE) {
175:                    double d = getDouble().doubleValue();
176:                    if (Double.isInfinite(d)) {
177:                        output = "Inf";
178:                    } else if (Double.isInfinite(-d)) {
179:                        output = "-Inf";
180:                    } else if (Double.isNaN(d)) {
181:                        output = "NaN";
182:                    } else {
183:                        output = FormatNumber.format(d);
184:                    }
185:                } else if (type == DataType.BOOLEAN) {
186:                    output = "" + getBoolean().booleanValue();
187:                } else if (type == DataType.STRING) {
188:                    output = getString();
189:                } else if (type == DataType.STRUCT) {
190:                    output = getStruct().toString();
191:                } else if (type == DataType.CELL) {
192:                    output = getCell().toString();
193:                } else {
194:                    throw new SemanticException("Unknow datatype to print.");
195:                }
196:                return output;
197:            }
198:
199:            public static void main(String[] args) {
200:                Symbol s = new Symbol("x", new Double(1.0));
201:                Symbol s1 = new Symbol("y", s);
202:            }
203:
204:            public Vector getVector() {
205:                if (type == DataType.VECTOR) {
206:                    return (Vector) value;
207:                } else {
208:                    return null;
209:                }
210:            }
211:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.