KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > JSci > maths > symbolic > Constant


1 package JSci.maths.symbolic;
2  
3 import java.util.*;
4 import JSci.maths.*;
5 import JSci.maths.groups.*;
6 import JSci.maths.fields.*;
7
8 /** This class wraps any constant value. Probably it will become
9  * obsolete! */

10 public class Constant extends Expression {
11     private final Member value;
12
13     /** A constant Expression
14      * @param x the constant value
15      */

16     public Constant(Member x) {
17     value=x;
18     }
19
20     public String JavaDoc toString() {
21     return value.toString();
22     }
23
24     public Expression differentiate(Variable x) {
25     return new Constant(((AbelianGroup)getSet()).zero());
26     }
27
28     public Expression evaluate() {
29     return this;
30     }
31
32     protected int getPriority() {
33     String JavaDoc sv=value.toString();
34         if (
35             sv.indexOf("+")!=-1 ||
36             sv.indexOf("-")!=-1
37             ) return 0;
38         if (sv.indexOf("*")!=-1) return 10;
39         if (sv.indexOf("^")!=-1) return 15;
40         return 20;
41     }
42
43     public Object JavaDoc getSet() {
44     return value.getSet();
45     }
46
47     public Member getValue() { return value; }
48
49     public boolean equals(Object JavaDoc o) {
50     Object JavaDoc op;
51     if (o instanceof Constant) op=((Constant)o).getValue();
52     else op=o;
53     return (value.equals(op));
54     }
55
56 }
57
58
59
60
61
Popular Tags