Package net.sf.saxon.om
Class ZeroOrOne<T extends Item<?>>
java.lang.Object
net.sf.saxon.om.ZeroOrOne<T>
- All Implemented Interfaces:
Iterable<T>,GroundedValue<T>,Sequence<T>
- Direct Known Subclasses:
One
A value that is a sequence containing zero or one items.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanGet the effective boolean valueempty()Return the instance of ZeroOrOne that represents the empty sequenceintGet the length of the sequenceConvert the value to a string, using the serialization rules.Get the string value of this sequence.head()Get the first item in the sequence.itemAt(int n) Get the n'th item in the sequence (starting from 0).iterate()Return an enumeration of this nodeset value.reduce()Reduce the sequence to its simplest form.subsequence(int start, int length) Get a subsequence of the valuetoString()Returns a string representation of the object (used only for diagnostics).Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface net.sf.saxon.om.GroundedValue
asIterable, iterator, materialize, toShortStringMethods inherited from interface java.lang.Iterable
forEach, spliteratorMethods inherited from interface net.sf.saxon.om.Sequence
makeRepeatable
-
Constructor Details
-
ZeroOrOne
Create a sequence containing zero or one items- Parameters:
item- The item to be contained in the sequence, or null if the sequence is to be empty
-
-
Method Details
-
empty
Return the instance of ZeroOrOne that represents the empty sequence- Returns:
- a representation of the empty sequence that satisfies the type ZeroOrOne
-
getStringValueCS
Get the string value of this sequence. The string value of an item is the result of applying the string() function. The string value of an empty sequence is the zero-length string.- Specified by:
getStringValueCSin interfaceGroundedValue<T extends Item<?>>- Returns:
- the string value of the sequence.
-
getStringValue
Convert the value to a string, using the serialization rules. For atomic values this is the same as a cast; for sequence values it gives a space-separated list. For QNames and NOTATIONS, or lists containing them, it fails.- Specified by:
getStringValuein interfaceGroundedValue<T extends Item<?>>- Returns:
- the string value of the sequence.
-
head
Get the first item in the sequence. -
getLength
public int getLength()Get the length of the sequence- Specified by:
getLengthin interfaceGroundedValue<T extends Item<?>>- Returns:
- the number of items in the sequence. Note that for a single item, including a map or array, the result is always 1 (one).
-
itemAt
Get the n'th item in the sequence (starting from 0). This is defined for all SequenceValues, but its real benefits come for a SequenceValue stored extensionally (or for a MemoClosure, once all the values have been read)- Specified by:
itemAtin interfaceGroundedValue<T extends Item<?>>- Parameters:
n- the index of the required item, with 0 representing the first item in the sequence- Returns:
- the n'th item if it exists, or null otherwise
-
subsequence
Get a subsequence of the value- Specified by:
subsequencein interfaceGroundedValue<T extends Item<?>>- Parameters:
start- the index of the first item to be included in the result, counting from zero. A negative value is taken as zero. If the value is beyond the end of the sequence, an empty sequence is returnedlength- the number of items to be included in the result. Specify Integer.MAX_VALUE to get the subsequence up to the end of the base sequence. If the value is negative, an empty sequence is returned. If the value goes off the end of the sequence, the result returns items up to the end of the sequence- Returns:
- the required subsequence. If min is
-
iterate
Return an enumeration of this nodeset value.- Specified by:
iteratein interfaceGroundedValue<T extends Item<?>>- Specified by:
iteratein interfaceSequence<T extends Item<?>>- Returns:
- an iterator (meaning a Saxon
SequenceIteratorrather than a JavaIterator) over all the items in this Sequence.
-
effectiveBooleanValue
Get the effective boolean value- Specified by:
effectiveBooleanValuein interfaceGroundedValue<T extends Item<?>>- Returns:
- the effective boolean value
- Throws:
XPathException- if the sequence has no effective boolean value (for example a sequence of two integers)
-
toString
Returns a string representation of the object (used only for diagnostics). -
reduce
Reduce the sequence to its simplest form. If the value is an empty sequence, the result will be EmptySequence.getInstance(). If the value is a single atomic value, the result will be an instance of AtomicValue. If the value is a single item of any other kind, the result will be an instance of SingletonItem. Otherwise, the result will typically be unchanged.- Specified by:
reducein interfaceGroundedValue<T extends Item<?>>- Returns:
- the simplified sequence
-