Java Doc for ExpressionProgram.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 Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   edu.hws.jcm.data.ExpressionProgram

ExpressionProgram
public class ExpressionProgram implements Expression(Code)
An ExprssionProgram represents a mathematical expression such as "3" or "sin(x^2)", stored in the form of a program for a stack machine. The program consists of a sequence of commands that, when executed, will compute the value of the expression.

Each command is encoded as an integer. There are three types of commands that can occur: (1) A negative integer must be one of the 36 constant values PLUS, MINUS,..., CUBERT. These constants represent unary and binary operators and standard functions. (2) An integer in the range 0 <= n < 0x3FFFFFFF encodes an operation of the form "push a constant onto the stack". The constant that is being pushed is encoded as an index in the array "constant", which is a private member of this class that holds all the constants that occur in this ExpressionProgram. (3) An integer >= 0x3FFFFFFF represents an ExpressionCommand object. When 0x3FFFFFFF is subtracted from the integer, the result is an index into the array "command", which is a private member of this class that holds all the ExpressionCommands that occur in this ExpressionProgram.



Field Summary
final public static  intPLUSMINUSTIMESDIVIDEPOWEREQNELTGTLEGEANDORNOTUNARY_MINUSFACTORIALSINCOSTANCOTSECCSCARCSINARCCOSARCTANABSSQRTEXPLNLOG2LOG10TRUNCROUNDFLOORCEILINGCUBERT
     Code for a unary or binary operator or a standard function.
public  StringsourceString
     If this is non-null, it is used as the print string for this expression in the toString() method.

Constructor Summary
public  ExpressionProgram()
     Default constructor creates an initially empty program.

Method Summary
public  voidaddCommand(int code)
     Add a command code to the program, where code is one of the opCode constants that are public final members of this class, from CUBERT to PLUS.
public  voidaddCommandObject(ExpressionCommand com)
     Adds com as the next command in the program.
public  voidaddConstant(double d)
     Add the number d as the next command in the program.
public  voidappendOutputString(int index, StringBuffer buffer)
     Add a string representing part of the expression to the output buffer. You probably are only interested in this if you write a ParserExtension or ExpressionCommand. (The command at position index in the program represents a subexpression.
protected  doubleapplyCommandCode(int code)
     Apply the stack operation represented by code (a number < 0) to the stack.
public  voidcompileDerivative(int index, ExpressionProgram deriv, Variable wrt)
     The command at position index in the program represents a subexpression of the whole expression.
public  voidcopyExpression(int index, ExpressionProgram destination)
     The command at position index in the program represents a subexpression of the whole expression.
public  booleandependsOn(int index, Variable x)
     The command at position index in the program represents a subexpression of the whole expression.
public  booleandependsOn(Variable x)
     Checks whether the expression as a whole has any dependence on the variable x.
public  Expressionderivative(Variable wrt)
     Compute the derivative of this expression with respect to the Variable wrt.
public  intextent(int index)
     The command at position index in the program represents a subexpression of the whole expression.
public synchronized  doublegetVal()
     Run the ExprssionProgram and return the value that it computes.
public synchronized  doublegetValueWithCases(Cases c)
     Run the ExprssionProgram and return the value that it computes. If the Cases object, c, is non-null, then information about "cases" is recorded in c. This information can be used to help detect possible "discontinuities" between two evaluations.
public  StringtoString()
     If a source string has been saved, use it as the print string.
public  voidtrim()
     To save space, cut the arrays that holds the program data down to the actual amount of data that they contain.

Field Detail
PLUSMINUSTIMESDIVIDEPOWEREQNELTGTLEGEANDORNOTUNARY_MINUSFACTORIALSINCOSTANCOTSECCSCARCSINARCCOSARCTANABSSQRTEXPLNLOG2LOG10TRUNCROUNDFLOORCEILINGCUBERT
final public static int PLUSMINUSTIMESDIVIDEPOWEREQNELTGTLEGEANDORNOTUNARY_MINUSFACTORIALSINCOSTANCOTSECCSCARCSINARCCOSARCTANABSSQRTEXPLNLOG2LOG10TRUNCROUNDFLOORCEILINGCUBERT(Code)
Code for a unary or binary operator or a standard function.



sourceString
public String sourceString(Code)
If this is non-null, it is used as the print string for this expression in the toString() method. (When an expression is created by a Parser by parsing a string, the parse stores that string in this variable.)




Constructor Detail
ExpressionProgram
public ExpressionProgram()(Code)
Default constructor creates an initially empty program.




Method Detail
addCommand
public void addCommand(int code)(Code)
Add a command code to the program, where code is one of the opCode constants that are public final members of this class, from CUBERT to PLUS. Each code represents either a binary or unary operator or a standard function that operates on the stack by poping its argument(s) from the stack, perfroming the operation, and pushing the result back onto the stack.



addCommandObject
public void addCommandObject(ExpressionCommand com)(Code)
Adds com as the next command in the program. Among other things, for example, com can be a Variable or Constant. In that case, the meaning of the command is the stack operation "push (value of com)".
Parameters:
  com - added as next command in the program.



addConstant
public void addConstant(double d)(Code)
Add the number d as the next command in the program. The meaning of this command is actually the stack operation "push d".
Parameters:
  d - added as next command in program.



appendOutputString
public void appendOutputString(int index, StringBuffer buffer)(Code)
Add a string representing part of the expression to the output buffer. You probably are only interested in this if you write a ParserExtension or ExpressionCommand. (The command at position index in the program represents a subexpression. It could be a constant or a variable, for example, which is complete subexpression in itself. Or it could be the final operator in a larger subexpression. In that case, the operands, which are located in lower positions in the program, are considered to be part of the expression. This routine appends a print string for the entire subexpression to the buffer. When this is called with index = progCt-1 (the last command in the program), it processes the entire program. Note that the hard part here is deciding when to put in parentheses. This is done based on the precedence of the operators. The result is not always pretty.



applyCommandCode
protected double applyCommandCode(int code)(Code)
Apply the stack operation represented by code (a number < 0) to the stack.



compileDerivative
public void compileDerivative(int index, ExpressionProgram deriv, Variable wrt)(Code)
The command at position index in the program represents a subexpression of the whole expression. This routine adds commands to deriv for computing the derivative of that subexpression with respect to the variable wrt. You probably are not interested in this unless you write a ParserExtension or an ExpressionCommand.



copyExpression
public void copyExpression(int index, ExpressionProgram destination)(Code)
The command at position index in the program represents a subexpression of the whole expression. This routine copies the commands for the entire subexpression to the destination program. You probably are not interested in this unless you write a ParserExtension or an ExpressionCommand.



dependsOn
public boolean dependsOn(int index, Variable x)(Code)
The command at position index in the program represents a subexpression of the whole expression. If that subexpression includes some dependence on the variable x, then true is returned. If the subexpression is constant with respect to the variable x, then false is returned. You probably are not interested in this unless you write a ParserExtension or an ExpressionCommand.



dependsOn
public boolean dependsOn(Variable x)(Code)
Checks whether the expression as a whole has any dependence on the variable x.



derivative
public Expression derivative(Variable wrt)(Code)
Compute the derivative of this expression with respect to the Variable wrt. The value returned is actually an ExpressionProgram.



extent
public int extent(int index)(Code)
The command at position index in the program represents a subexpression of the whole expression. This routine finds and returns the number of commands in the program that are part of that subexpression. That is, the subexpresssion occupies the part of the program between index - extent + 1 and index. You probably are not interested in this unless you write a ParserExtension or an ExpressionCommand.



getVal
public synchronized double getVal()(Code)
Run the ExprssionProgram and return the value that it computes.



getValueWithCases
public synchronized double getValueWithCases(Cases c)(Code)
Run the ExprssionProgram and return the value that it computes. If the Cases object, c, is non-null, then information about "cases" is recorded in c. This information can be used to help detect possible "discontinuities" between two evaluations. See the Cases class for more information.



toString
public String toString()(Code)
If a source string has been saved, use it as the print string. (When a Parser creates an expression by parsing a string, it saves the source string in the ExpressionProgram.) Otherwise, construct the print string based on the commands in the program.



trim
public void trim()(Code)
To save space, cut the arrays that holds the program data down to the actual amount of data that they contain. This should be called after the complete program has been generated.



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.