1 16 package org.apache.commons.jxpath.ri.compiler; 17 18 import org.apache.commons.jxpath.ri.EvalContext; 19 20 26 public class Constant extends Expression { 27 28 private Object value; 29 30 public Constant(Number number) { 31 this.value = number; 32 } 33 34 public Constant(String string) { 35 this.value = string; 36 } 37 38 public Object compute(EvalContext context) { 39 return value; 40 } 41 42 45 public Object computeValue(EvalContext context) { 46 return value; 47 } 48 49 52 public boolean isContextDependent() { 53 return false; 54 } 55 56 59 public boolean computeContextDependent() { 60 return false; 61 } 62 63 public String toString() { 64 if (value instanceof Number ) { 65 double doubleValue = ((Number ) value).doubleValue(); 66 long longValue = ((Number ) value).longValue(); 67 if (doubleValue == longValue) { 68 return String.valueOf(longValue); 69 } 70 else { 71 return String.valueOf(doubleValue); 72 } 73 } 74 else { 75 return "'" + value + "'"; 76 } 77 } 78 } | Popular Tags |