KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > saxon > value > EmptySequence


1 package net.sf.saxon.value;
2 import net.sf.saxon.expr.ExpressionTool;
3 import net.sf.saxon.expr.StaticProperty;
4 import net.sf.saxon.expr.XPathContext;
5 import net.sf.saxon.om.EmptyIterator;
6 import net.sf.saxon.om.NamePool;
7 import net.sf.saxon.om.SequenceIterator;
8 import net.sf.saxon.pattern.NoNodeTest;
9 import net.sf.saxon.type.ItemType;
10
11 import java.io.PrintStream JavaDoc;
12
13 /**
14 * An EmptySequence object represents a sequence containing no members.
15 */

16
17
18 public final class EmptySequence extends Value {
19
20     // This class has a single instance
21
private static EmptySequence THE_INSTANCE = new EmptySequence();
22
23
24     /**
25     * Private constructor: only the predefined instances of this class can be used
26     */

27
28     private EmptySequence() {}
29
30     /**
31     * Get the implicit instance of this class
32     */

33
34     public static EmptySequence getInstance() {
35         return THE_INSTANCE;
36     }
37
38     /**
39      * An implementation of Expression must provide at least one of the methods evaluateItem(), iterate(), or process().
40      * This method indicates which of these methods is prefered.
41      */

42
43     public int getImplementationMethod() {
44         return EVALUATE_METHOD;
45     }
46
47     /**
48     * Return an iteration over the sequence
49     */

50
51     public SequenceIterator iterate(XPathContext context) {
52         return EmptyIterator.getInstance();
53     }
54
55     /**
56     * Determine the item type
57     */

58
59     public ItemType getItemType() {
60         return NoNodeTest.getInstance();
61     }
62
63     /**
64     * Determine the static cardinality
65     */

66
67     public int getCardinality() {
68         return StaticProperty.EMPTY;
69     }
70
71     /**
72     * Get the static properties of this expression (other than its type). The result is
73     * bit-signficant. These properties are used for optimizations. In general, if
74     * property bit is set, it is true, but if it is unset, the value is unknown.
75     */

76
77     public int getSpecialProperties() {
78         return StaticProperty.ORDERED_NODESET |
79                 StaticProperty.SINGLE_DOCUMENT_NODESET |
80                 StaticProperty.CONTEXT_DOCUMENT_NODESET;
81     }
82
83     /**
84      * Get the length of the sequence
85      * @return always 0 for an empty sequence
86      */

87
88     public final int getLength() {
89         return 0;
90     }
91     /**
92     * Is this expression the same as another expression?
93     * @throws ClassCastException if the values are not comparable
94     */

95
96     public boolean equals(Object JavaDoc other) {
97         if (!(other instanceof EmptySequence)) {
98             throw new ClassCastException JavaDoc("Cannot compare " + other.getClass() + " to empty sequence");
99         }
100         return true;
101     }
102
103     public int hashCode() {
104         return 42;
105     }
106
107     /**
108     * Evaluate as a string. Returns the string value of the first value in the sequence
109     * @return "" always
110     */

111
112 // public String getStringValue() throws XPathException {
113
// return "";
114
// }
115

116     /**
117     * Get the effective boolean value - always false
118     */

119
120     public boolean effectiveBooleanValue(XPathContext context) {
121         return false;
122     }
123
124     /**
125     * Diagnostic print of expression structure
126     */

127
128     public void display(int level, NamePool pool, PrintStream JavaDoc out) {
129         out.println(ExpressionTool.indent(level) + "()" );
130     }
131
132 }
133
134 //
135
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
136
// you may not use this file except in compliance with the License. You may obtain a copy of the
137
// License at http://www.mozilla.org/MPL/
138
//
139
// Software distributed under the License is distributed on an "AS IS" basis,
140
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
141
// See the License for the specific language governing rights and limitations under the License.
142
//
143
// The Original Code is: all this file.
144
//
145
// The Initial Developer of the Original Code is Michael H. Kay.
146
//
147
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
148
//
149
// Contributor(s): none.
150
//
151
Popular Tags