KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > icl > saxon > functions > Ceiling


1 package com.icl.saxon.functions;
2 import com.icl.saxon.*;
3 import com.icl.saxon.expr.*;
4
5 import java.util.*;
6 import java.lang.Math JavaDoc;
7 import java.text.*;
8
9
10
11 public class Ceiling extends Function {
12
13
14     /**
15     * Function name (for diagnostics)
16     */

17
18     public String JavaDoc getName() {
19         return "ceiling";
20     };
21
22     /**
23     * Determine the data type of the expression
24     * @return Value.NUMBER
25     */

26
27     public int getDataType() {
28         return Value.NUMBER;
29     }
30
31     /**
32     * Simplify and validate.
33     * This is a pure function so it can be simplified in advance if the arguments are known
34     */

35
36     public Expression simplify() throws XPathException {
37         checkArgumentCount(1, 1);
38         argument[0] = argument[0].simplify();
39         if (argument[0] instanceof Value) {
40             return evaluate(null);
41         }
42         return this;
43     }
44
45     /**
46     * Evaluate the function in a numeric context
47     */

48
49     public double evaluateAsNumber(Context c) throws XPathException {
50         return Math.ceil(argument[0].evaluateAsNumber(c));
51     }
52
53     /**
54     * Evaluate in a general context
55     */

56
57     public Value evaluate(Context c) throws XPathException {
58         return new NumericValue(evaluateAsNumber(c));
59     }
60
61     /**
62     * Determine the dependencies
63     */

64
65     public int getDependencies() {
66         return argument[0].getDependencies();
67     }
68
69     /**
70     * Reduce the dependencies
71     */

72
73     public Expression reduce(int dep, Context c) throws XPathException {
74         Ceiling f = new Ceiling();
75         f.addArgument(argument[0].reduce(dep, c));
76         f.setStaticContext(getStaticContext());
77         return f.simplify();
78     }
79
80 }
81
82
83 //
84
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
85
// you may not use this file except in compliance with the License. You may obtain a copy of the
86
// License at http://www.mozilla.org/MPL/
87
//
88
// Software distributed under the License is distributed on an "AS IS" basis,
89
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
90
// See the License for the specific language governing rights and limitations under the License.
91
//
92
// The Original Code is: all this file.
93
//
94
// The Initial Developer of the Original Code is
95
// Michael Kay of International Computers Limited (mhkay@iclway.co.uk).
96
//
97
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
98
//
99
// Contributor(s): none.
100
//
101
Popular Tags