1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49 package org.jaxen.function;
50
51 import java.util.List;
52
53 import org.jaxen.Context;
54 import org.jaxen.Function;
55 import org.jaxen.FunctionCallException;
56 import org.jaxen.Navigator;
57
58 /***
59 * <p><b>4.4</b> <code><i>number</i> ceiling(<i>number</i>)</code>
60 * <blockquote src="http://www.w3.org/TR/xpath">
61 * <p>
62 *
63 * <p><q>The ceiling function returns the smallest
64 * (closest to negative infinity) number that is not less
65 * than the argument and that is an integer....If the argument
66 * is NaN, then NaN is returned. If the argument is positive infinity,
67 * then positive infinity is returned. If the argument is negative infinity,
68 * then negative infinity is returned. If the argument is positive zero,
69 * then positive zero is returned.
70 * If the argument is negative zero, then negative zero is returned.
71 * If the argument is less than zero, but greater than -1,
72 * then negative zero is returned.</q>
73 * </p>
74 *
75 * @author bob mcwhirter (bob @ werken.com)
76 *
77 * @see <a href="http://www.w3.org/TR/xpath#function-ceiling">Section 4.4 of the XPath Specification</a>
78 * @see <a href="http://www.w3.org/1999/11/REC-xpath-19991116-errata/">XPath Specification Errata</a>
79 *
80 */
81 public class CeilingFunction implements Function
82 {
83
84 /***
85 * Create a new <code>CeilingFunction</code> object.
86 */
87 public CeilingFunction() {}
88
89 /*** Returns the smallest integer greater than or equal to a number.
90 *
91 * @param context the context at the point in the
92 * expression when the function is called
93 * @param args a list with exactly one item which will be converted to a
94 * <code>Double</code> as if by the XPath <code>number()</code> function
95 *
96 * @return a <code>Double</code> containing the smallest integer greater than or equal
97 * <code>args.get(0)</code>
98 *
99 * @throws FunctionCallException if <code>args</code> has more or less than one item
100 */
101 public Object call(Context context,
102 List args) throws FunctionCallException
103 {
104 if (args.size() == 1)
105 {
106 return evaluate( args.get(0),
107 context.getNavigator() );
108 }
109
110 throw new FunctionCallException("ceiling() requires one argument.");
111 }
112
113 /*** Returns the smallest integer greater than or equal to the argument.
114 * If necessary, the argument is first converted to a <code>Double</code>
115 * as if by the XPath <code>number()</code> function.
116 *
117 * @param obj the object whose ceiling is returned
118 * @param nav ignored
119 *
120 * @return a <code>Double</code> containing the smallest integer
121 * greater than or equal to <code>obj</code>
122 */
123 public static Double evaluate(Object obj,
124 Navigator nav)
125 {
126 Double value = NumberFunction.evaluate( obj,
127 nav );
128
129 return new Double( Math.ceil( value.doubleValue() ) );
130 }
131 }