KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lsmp > djep > djep > PartialDerivative


1 /* @author rich
2  * Created on 29-Oct-2003
3  *
4  * This code is covered by a Creative Commons
5  * Attribution, Non Commercial, Share Alike license
6  * <a HREF="http://creativecommons.org/licenses/by-nc-sa/1.0">License</a>
7  */

8 package org.lsmp.djep.djep;
9 import org.nfunk.jep.*;
10 import org.lsmp.djep.xjep.*;
11
12 import java.util.Observable JavaDoc;
13 import java.util.Observer JavaDoc;
14 /**
15  * Contains infomation about a PartialDerivative of a variable.
16  * Should
17  * @author Rich Morris
18  * Created on 29-Oct-2003
19  */

20 public class PartialDerivative extends XVariable implements Observer JavaDoc {
21
22     private DVariable root;
23     private String JavaDoc dnames[] = null;
24     private String JavaDoc printString;
25     /**
26      * Protected constructor, should only be constructed
27      * through the findDerivative method in {@link DVariable DVariable}.
28     **/

29     protected PartialDerivative(DVariable var, String JavaDoc derivnames[],Node deriv)
30     {
31         super(var.getName());
32         root = var;
33         dnames = derivnames;
34         setEquation(deriv);
35         printString = DVariable.makeDerivString(root.getName(),derivnames);
36         root.addObserver(this);
37     }
38     
39     public String JavaDoc getName() { return printString; }
40     
41     /**
42      * Every partial derivative has a root variable
43      * for instance the root variable of dy/dx is y.
44      * This method returns than variable.
45      */

46     public DVariable getRoot() { return root; }
47     public String JavaDoc[] getDnames() { return dnames; }
48
49     public String JavaDoc toString()
50     {
51         return printString;
52     }
53     
54     public PartialDerivative findDerivative(String JavaDoc name,DJep jep)
55         throws ParseException
56     {
57         return root.findDerivative(this,name,jep);
58     }
59     
60     
61     /**
62      * When the value of the root object is changed
63      * makes the value of this partial derivative invalid.
64      *
65      * @see java.util.Observer#update(java.util.Observable, java.lang.Object)
66      */

67     public void update(Observable JavaDoc arg0, Object JavaDoc arg1) {
68         if(root.equals(arg0))
69         {
70             setValidValue(false);
71         }
72     }
73
74 }
75
Popular Tags