001: package net.sf.saxon.value;
002:
003: import net.sf.saxon.expr.ExpressionTool;
004: import net.sf.saxon.expr.StaticProperty;
005: import net.sf.saxon.expr.XPathContext;
006: import net.sf.saxon.om.EmptyIterator;
007: import net.sf.saxon.om.NamePool;
008: import net.sf.saxon.om.SequenceIterator;
009: import net.sf.saxon.pattern.NoNodeTest;
010: import net.sf.saxon.type.ItemType;
011: import net.sf.saxon.type.TypeHierarchy;
012:
013: import java.io.PrintStream;
014:
015: /**
016: * An EmptySequence object represents a sequence containing no members.
017: */
018:
019: public final class EmptySequence extends Value {
020:
021: // This class has a single instance
022: private static EmptySequence THE_INSTANCE = new EmptySequence();
023:
024: /**
025: * Private constructor: only the predefined instances of this class can be used
026: */
027:
028: private EmptySequence() {
029: }
030:
031: /**
032: * Get the implicit instance of this class
033: */
034:
035: public static EmptySequence getInstance() {
036: return THE_INSTANCE;
037: }
038:
039: /**
040: * An implementation of Expression must provide at least one of the methods evaluateItem(), iterate(), or process().
041: * This method indicates which of these methods is prefered.
042: */
043:
044: public int getImplementationMethod() {
045: return EVALUATE_METHOD;
046: }
047:
048: /**
049: * Return an iteration over the sequence
050: */
051:
052: public SequenceIterator iterate(XPathContext context) {
053: return EmptyIterator.getInstance();
054: }
055:
056: /**
057: * Determine the item type
058: * @param th
059: */
060:
061: public ItemType getItemType(TypeHierarchy th) {
062: return NoNodeTest.getInstance();
063: }
064:
065: /**
066: * Determine the static cardinality
067: */
068:
069: public int getCardinality() {
070: return StaticProperty.EMPTY;
071: }
072:
073: /**
074: * Get the static properties of this expression (other than its type). The result is
075: * bit-signficant. These properties are used for optimizations. In general, if
076: * property bit is set, it is true, but if it is unset, the value is unknown.
077: */
078:
079: public int getSpecialProperties() {
080: return StaticProperty.ORDERED_NODESET
081: | StaticProperty.SINGLE_DOCUMENT_NODESET
082: | StaticProperty.CONTEXT_DOCUMENT_NODESET;
083: }
084:
085: /**
086: * Get the length of the sequence
087: * @return always 0 for an empty sequence
088: */
089:
090: public final int getLength() {
091: return 0;
092: }
093:
094: /**
095: * Is this expression the same as another expression?
096: * @throws ClassCastException if the values are not comparable
097: */
098:
099: public boolean equals(Object other) {
100: if (!(other instanceof EmptySequence)) {
101: throw new ClassCastException("Cannot compare "
102: + other.getClass() + " to empty sequence");
103: }
104: return true;
105: }
106:
107: public int hashCode() {
108: return 42;
109: }
110:
111: /**
112: * Evaluate as a string. Returns the string value of the first value in the sequence
113: * @return "" always
114: */
115:
116: // public String getStringValue() throws XPathException {
117: // return "";
118: // }
119: /**
120: * Get the effective boolean value - always false
121: */
122:
123: public boolean effectiveBooleanValue(XPathContext context) {
124: return false;
125: }
126:
127: /**
128: * Diagnostic print of expression structure
129: */
130:
131: public void display(int level, NamePool pool, PrintStream out) {
132: out.println(ExpressionTool.indent(level) + "()");
133: }
134:
135: }
136:
137: //
138: // The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
139: // you may not use this file except in compliance with the License. You may obtain a copy of the
140: // License at http://www.mozilla.org/MPL/
141: //
142: // Software distributed under the License is distributed on an "AS IS" basis,
143: // WITHOUT WARRANTY OF ANY KIND, either express or implied.
144: // See the License for the specific language governing rights and limitations under the License.
145: //
146: // The Original Code is: all this file.
147: //
148: // The Initial Developer of the Original Code is Michael H. Kay.
149: //
150: // Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
151: //
152: // Contributor(s): none.
153: //
|