1 61 62 63 package org.jaxen.function; 64 65 import java.util.List ; 66 67 import org.jaxen.Context; 68 import org.jaxen.Function; 69 import org.jaxen.FunctionCallException; 70 import org.jaxen.Navigator; 71 72 90 public class RoundFunction implements Function 91 { 92 93 96 public RoundFunction() {} 97 98 99 111 public Object call(Context context, 112 List args) throws FunctionCallException 113 { 114 if (args.size() == 1) 115 { 116 return evaluate( args.get(0), 117 context.getNavigator() ); 118 } 119 120 throw new FunctionCallException( "round() requires one argument." ); 121 } 122 123 133 public static Double evaluate(Object obj, 134 Navigator nav) 135 { 136 Double d = NumberFunction.evaluate( obj, 137 nav ); 138 139 if (d.isNaN() || d.isInfinite()) 140 { 141 return d; 142 } 143 144 double value = d.doubleValue(); 145 return new Double ( Math.round( value ) ); 146 } 147 } 148 | Popular Tags |