1 61 62 63 64 package org.jaxen.expr; 65 66 import org.jaxen.Context; 67 import org.jaxen.JaxenException; 68 import org.jaxen.function.NumberFunction; 69 70 class DefaultUnaryExpr extends DefaultExpr implements UnaryExpr 71 { 72 private Expr expr; 73 74 DefaultUnaryExpr(Expr expr) 75 { 76 this.expr = expr; 77 } 78 79 public Expr getExpr() 80 { 81 return this.expr; 82 } 83 84 public String toString() 85 { 86 return "[(DefaultUnaryExpr): " + getExpr() + "]"; 87 } 88 89 public String getText() 90 { 91 return "-(" + getExpr().getText() + ")"; 92 } 93 94 public Expr simplify() 95 { 96 expr = expr.simplify(); 97 98 return this; 99 } 100 101 public Object evaluate(Context context) throws JaxenException 102 { 103 Number number = NumberFunction.evaluate( getExpr().evaluate( context ), 104 context.getNavigator() ); 105 106 return new Double ( number.doubleValue() * -1 ); 107 } 108 public void accept(Visitor visitor) 109 { 110 visitor.visit(this); 111 } 112 } 113 | Popular Tags |