KickJava   Java API By Example, From Geeks To Geeks.

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


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

14
15     public String JavaDoc getName() {
16         return "last";
17     };
18
19     /**
20     * Determine the data type of the expression
21     * @return Value.NUMBER
22     */

23
24     public int getDataType() {
25         return Value.NUMBER;
26     }
27
28     /**
29     * Simplify and validate.
30     */

31
32     public Expression simplify() throws XPathException {
33         checkArgumentCount(0, 0);
34         return this;
35     }
36
37     /**
38     * Evaluate the function in a numeric context
39     */

40
41     public double evaluateAsNumber(Context c) throws XPathException {
42         return (double)c.getLast();
43     }
44
45     /**
46     * Evaluate in a general context
47     */

48
49     public Value evaluate(Context c) throws XPathException {
50         return new NumericValue(evaluateAsNumber(c));
51     }
52
53     /**
54     * Determine the dependencies
55     */

56
57     public int getDependencies() {
58         return Context.LAST;
59     }
60
61     /**
62     * Reduce the dependencies
63     */

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