KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lsmp > djep > djep > diffRules > PassThroughDiffRule


1 /* @author rich
2  * Created on 04-Jul-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.diffRules;
9
10 import org.lsmp.djep.djep.DJep;
11 import org.lsmp.djep.djep.DiffRulesI;
12 import org.nfunk.jep.ASTFunNode;
13 import org.nfunk.jep.Node;
14 import org.nfunk.jep.ParseException;
15 import org.nfunk.jep.function.PostfixMathCommandI;
16
17
18 /**
19    * Rules like Sum where diff(sum(a,b,c),x) -> sum(da/dx,db/dx,dc/dx) are instance of this class.
20    **/

21   public class PassThroughDiffRule implements DiffRulesI
22   {
23     private String JavaDoc name;
24     private PostfixMathCommandI pfmc;
25
26     private PassThroughDiffRule() {}
27     public PassThroughDiffRule(DJep djep,String JavaDoc inName)
28     {
29       name = inName;
30       pfmc = djep.getFunctionTable().get(name);
31     }
32     public PassThroughDiffRule(String JavaDoc inName,PostfixMathCommandI inPfmc)
33     {
34         name = inName;
35         pfmc = inPfmc;
36     }
37     public String JavaDoc toString()
38     {
39         if(pfmc==null)
40         {
41             return "" + name +"\t\tPassthrough but no math command!";
42         }
43         switch(pfmc.getNumberOfParameters())
44         {
45         case 0:
46             return name + " \t\tdiff("+name+",x) -> "+name;
47         case 1:
48             return name + " \tdiff("+name+"(a),x) -> "+name+"(da/dx)";
49         case 2:
50             return name + " \tdiff("+name+"(a,b),x) -> "+name+"(da/dx,db/dx)";
51         default:
52             return name + " \tdiff("+name+"(a,b,...),x) -> "+name+"(da/dx,db/dx,...)";
53         }
54     }
55     public String JavaDoc getName() { return name; }
56         
57     public Node differentiate(ASTFunNode node,String JavaDoc var,Node [] children,Node [] dchildren,DJep djep) throws ParseException
58     {
59         return djep.getNodeFactory().buildFunctionNode(node,dchildren);
60     }
61   }
62
Popular Tags