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 10 public class Constant extends Expression { 11 private final Member value; 12 13 16 public Constant(Member x) { 17 value=x; 18 } 19 20 public String 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 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 getSet() { 44 return value.getSet(); 45 } 46 47 public Member getValue() { return value; } 48 49 public boolean equals(Object o) { 50 Object 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 |