Class AtomicValue
- java.lang.Object
-
- net.sf.saxon.value.AtomicValue
-
- All Implemented Interfaces:
java.lang.Iterable<AtomicValue>
,AtomicSequence
,GroundedValue
,IdentityComparable
,Item
,Sequence
,ConversionResult
- Direct Known Subclasses:
Base64BinaryValue
,BooleanValue
,CalendarValue
,DurationValue
,HexBinaryValue
,NumericValue
,QualifiedNameValue
,StringValue
public abstract class AtomicValue extends java.lang.Object implements Item, AtomicSequence, ConversionResult, IdentityComparable
The AtomicValue class corresponds to the concept of an atomic value in the XPath 2.0 data model. Atomic values belong to one of the 19 primitive types defined in XML Schema; or they are of type xs:untypedAtomic; or they are "external objects", representing a Saxon extension to the XPath 2.0 type system.The AtomicValue class contains some methods that are suitable for applications to use, and many others that are designed for internal use by Saxon itself. These have not been fully classified. At present, therefore, none of the methods on this class should be considered to be part of the public Saxon API.
The AtomicValue class and its subclasses are essentially immutable (since 12.x). There is an exception, in that
DecimalValue
caches the result of converting its value to a double internally.
-
-
Field Summary
Fields Modifier and Type Field Description protected AtomicType
typeLabel
-
Constructor Summary
Constructors Constructor Description AtomicValue(AtomicType typeLabel)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description AtomicValue
asAtomic()
Calling this method on a ConversionResult returns the AtomicValue that results from the conversion if the conversion was successful, and throws a ValidationException explaining the conversion error otherwise.AtomicMatchKey
asMapKey()
Get a value whose equals() method follows the "same key" rules for comparing the keys of a map.AtomicSequence
atomize()
Atomize the item.void
checkPermittedContents(SchemaType parentType, StaticContext env, boolean whole)
Check statically that the results of the expression are capable of constructing the content of a given schema type.void
checkValidInJavascript()
Check that the value can be handled in SaxonJSabstract AtomicValue
copyAsSubType(AtomicType typeLabel)
Create a copy of this atomic value, with a different type labelboolean
effectiveBooleanValue()
Get the effective boolean value of the valueboolean
equals(java.lang.Object o)
The equals() methods on atomic values is defined to follow the semantics of eq when applied to two atomic values.UnicodeString
getCanonicalLexicalRepresentation()
Get the canonical lexical representation as defined in XML Schema.int
getCardinality()
Determine the static cardinalityAtomicValue
getComponent(AccessorFn.Component component)
Method to extract components of a value.Genre
getGenre()
Get the genre of this itemAtomicType
getItemType()
Determine the data type of the valueint
getLength()
Get the length of the sequenceabstract UnicodeString
getPrimitiveStringValue()
Convert the value to a string, using the serialization rules for the primitive type.abstract BuiltInAtomicType
getPrimitiveType()
Determine the primitive type of the value.UnicodeString
getUnicodeStringValue()
Get the value of the item as a UnicodeString.UType
getUType()
Determine the UType of the value.abstract XPathComparable
getXPathComparable(StringCollator collator, int implicitTimezone)
Get an object value that implements the XPath equality and ordering comparison semantics for this value.abstract AtomicMatchKey
getXPathMatchKey(StringCollator collator, int implicitTimezone)
Get an object value that implements the XPath equality comparison semantics for this value.int
hashCode()
Returns a hash code value for the object.AtomicValue
head()
To implementSequence
, this method returns the item itselfint
identityHashCode()
Get a hashCode that offers the guarantee that if A.isIdentical(B), then A.identityHashCode() == B.identityHashCode()boolean
isIdentical(IdentityComparable other)
Determine whether two IdentityComparable objects are identical.boolean
isIdentical(AtomicValue v)
Determine whether two atomic values are identical, as determined by XML Schema rules.boolean
isNaN()
Test whether the value is the special value NaNboolean
isUntypedAtomic()
Ask whether the value is of type xs:untypedAtomicAtomicValue
itemAt(int n)
Get the n'th item in the sequence (starting from 0).SingleAtomicIterator
iterate()
Get an iterator over all the items in the sequencejava.util.Iterator<AtomicValue>
iterator()
Returns a Java iterator over the atomic sequence.java.lang.String
show()
Display the value for diagnostics.java.lang.String
toShortString()
Provide a short string showing the contents of the item, suitable for use in error messagesjava.lang.String
toString()
Get string value.-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface net.sf.saxon.om.GroundedValue
asIterable, concatenate, containsNode, materialize
-
Methods inherited from interface net.sf.saxon.om.Item
getStringValue, isStreamed, reduce, subsequence
-
Methods inherited from interface net.sf.saxon.om.Sequence
makeRepeatable
-
-
-
-
Field Detail
-
typeLabel
protected final AtomicType typeLabel
-
-
Constructor Detail
-
AtomicValue
public AtomicValue(AtomicType typeLabel)
-
-
Method Detail
-
atomize
public AtomicSequence atomize() throws XPathException
Atomize the item.- Specified by:
atomize
in interfaceItem
- Returns:
- the result of atomization
- Throws:
XPathException
- if atomization is not allowed for this kind of item
-
head
public final AtomicValue head()
To implementSequence
, this method returns the item itself- Specified by:
head
in interfaceAtomicSequence
- Specified by:
head
in interfaceGroundedValue
- Specified by:
head
in interfaceItem
- Specified by:
head
in interfaceSequence
- Returns:
- this item
-
getLength
public int getLength()
Get the length of the sequence- Specified by:
getLength
in interfaceAtomicSequence
- Specified by:
getLength
in interfaceGroundedValue
- Specified by:
getLength
in interfaceItem
- Returns:
- the number of items in the sequence (always one)
-
isUntypedAtomic
public boolean isUntypedAtomic()
Ask whether the value is of type xs:untypedAtomic- Returns:
- true if the value is untyped atomic
-
getXPathMatchKey
public abstract AtomicMatchKey getXPathMatchKey(StringCollator collator, int implicitTimezone) throws NoDynamicContextException
Get an object value that implements the XPath equality comparison semantics for this value. A collation is supplied for comparing strings, and an implicit timezone for comparing date/time values that have no saved timezone. The returned object supports equality matching only, not ordering. An atomic value may return itself as its ownAtomicMatchKey
provided that its equality semantics are context-free.- Parameters:
collator
- the collation to be used when comparing stringsimplicitTimezone
- the implicit timezone in the dynamic context, used when comparing dates/times with and without timezone- Returns:
- an Object whose equals() and hashCode() methods implement the XPath comparison semantics with respect to this atomic value. If ordered is specified, the result will either be null if no ordering is defined, or will be a Comparable
- Throws:
NoDynamicContextException
- if the supplied implicit timezone is "NO_TIMEZONE" (meaning unknown), and the implicit timezone is actually required because the value in question is a date/time value with no timezone. This can cause a failure to evaluate expressions statically (because the implicit timezone is not known statically), and it will then be caught, meaning that the expression has to be evaluated dynamically.
-
getXPathComparable
public abstract XPathComparable getXPathComparable(StringCollator collator, int implicitTimezone) throws NoDynamicContextException
Get an object value that implements the XPath equality and ordering comparison semantics for this value. A collation is supplied for comparing strings, and an implicit timezone for comparing date/time values that have no saved timezone. An atomic value may return itself as the result, provided that its ordering rules are independent of the collation and timezone, and provided that it implements the XPathComparable interface: which means that its compareTo, equals, and hashCode methods must be compatible with the rules for XPath value comparisons.- Parameters:
collator
- the collation to be used when comparing stringsimplicitTimezone
- the implicit timezone in the dynamic context, used when comparing dates/times with and without timezone- Returns:
- an Object that implements the XPath value comparison semantics with respect to this atomic value. For an atomic type that is not ordered (according to XPath rules), return null.
- Throws:
NoDynamicContextException
- if the supplied implicit timezone is "NO_TIMEZONE" (meaning unknown), and the implicit timezone is actually required because the value in question is a date/time value with no timezone. This can cause a failure to evaluate expressions statically (because the implicit timezone is not known statically), and it will then be caught, meaning that the expression has to be evaluated dynamically.
-
asMapKey
public AtomicMatchKey asMapKey()
Get a value whose equals() method follows the "same key" rules for comparing the keys of a map.- Returns:
- a value with the property that the equals() and hashCode() methods follow the rules for comparing keys in maps.
-
equals
public boolean equals(java.lang.Object o)
The equals() methods on atomic values is defined to follow the semantics of eq when applied to two atomic values. When the other operand is not an atomic value, the result is undefined (may be false, may be an exception). When the other operand is an atomic value that cannot be compared with this one, the method must throw a ClassCastException.The hashCode() method is consistent with equals().
- Overrides:
equals
in classjava.lang.Object
- Parameters:
o
- the other value- Returns:
- true (in a subclass) if the other operand is an atomic value and the two values are equal as defined by the XPath eq operator
-
hashCode
public int hashCode()
Returns a hash code value for the object.- Overrides:
hashCode
in classjava.lang.Object
-
isIdentical
public boolean isIdentical(AtomicValue v)
Determine whether two atomic values are identical, as determined by XML Schema rules. This is a stronger test than equality (even schema-equality); for example two dateTime values are not identical unless they are in the same timezone.Note that even this check ignores the type annotation of the value. The integer 3 and the short 3 are considered identical, even though they are not fully interchangeable. "Identical" means the same point in the value space, regardless of type annotation.
NaN is identical to itself.
- Parameters:
v
- the other value to be compared with this one- Returns:
- true if the two values are identical, false otherwise.
-
isIdentical
public boolean isIdentical(IdentityComparable other)
Determine whether two IdentityComparable objects are identical. This is a stronger test than equality (even schema-equality); for example two dateTime values are not identical unless they are in the same timezone.- Specified by:
isIdentical
in interfaceIdentityComparable
- Parameters:
other
- the value to be compared- Returns:
- true if the two values are identical, false otherwise
-
identityHashCode
public int identityHashCode()
Get a hashCode that offers the guarantee that if A.isIdentical(B), then A.identityHashCode() == B.identityHashCode()- Specified by:
identityHashCode
in interfaceIdentityComparable
- Returns:
- a hashCode suitable for use when testing for identity.
-
getUnicodeStringValue
public UnicodeString getUnicodeStringValue()
Get the value of the item as a UnicodeString.- Specified by:
getUnicodeStringValue
in interfaceAtomicSequence
- Specified by:
getUnicodeStringValue
in interfaceGroundedValue
- Specified by:
getUnicodeStringValue
in interfaceItem
- Returns:
- the string value (the result of casting to string using the XPath casting rules)
-
getCanonicalLexicalRepresentation
public UnicodeString getCanonicalLexicalRepresentation()
Get the canonical lexical representation as defined in XML Schema. This is not always the same as the result of casting to a string according to the XPath rules.- Specified by:
getCanonicalLexicalRepresentation
in interfaceAtomicSequence
- Returns:
- the canonical lexical representation if defined in XML Schema; otherwise, the result of casting to string according to the XPath 2.0 rules
-
itemAt
public final AtomicValue itemAt(int n)
Get the n'th item in the sequence (starting from 0). This is defined for all Values, but its real benefits come for a sequence Value stored extensionally (or for a MemoClosure, once all the values have been read)- Specified by:
itemAt
in interfaceAtomicSequence
- Specified by:
itemAt
in interfaceGroundedValue
- Specified by:
itemAt
in interfaceItem
- Parameters:
n
- position of the required item, counting from zero.- Returns:
- the n'th item in the sequence, where the first item in the sequence is numbered zero. If n is negative or >= the length of the sequence, returns null.
-
getItemType
public final AtomicType getItemType()
Determine the data type of the value- Returns:
- the type annotation of the atomic value
-
getPrimitiveType
public abstract BuiltInAtomicType getPrimitiveType()
Determine the primitive type of the value. This delivers the same answer as getItemType().getPrimitiveItemType(). The primitive types are the 19 primitive types of XML Schema, plus xs:integer, xs:dayTimeDuration and xs:yearMonthDuration, and xs:untypedAtomic. For external objects, the result is xs:anyAtomicType.- Returns:
- the primitive type
-
getUType
public final UType getUType()
Determine the UType of the value. This delivers the same answer as getItemType().getUType()- Returns:
- the primitive UType
-
getCardinality
public final int getCardinality()
Determine the static cardinality- Returns:
- code identifying the cardinality
- See Also:
Cardinality
-
copyAsSubType
public abstract AtomicValue copyAsSubType(AtomicType typeLabel)
Create a copy of this atomic value, with a different type label- Parameters:
typeLabel
- the type label of the new copy. The caller is responsible for checking that the value actually conforms to this type.- Returns:
- the copied value
-
isNaN
public boolean isNaN()
Test whether the value is the special value NaN- Returns:
- true if the value is float NaN or double NaN or precisionDecimal NaN; otherwise false
-
getPrimitiveStringValue
public abstract UnicodeString getPrimitiveStringValue()
Convert the value to a string, using the serialization rules for the primitive type. This is the result of conversion to a string except that postprocessing defined by the saxon:preprocess facet is not (yet) applied.- Returns:
- the value converted to a string according to the rules for the primitive type
-
effectiveBooleanValue
public boolean effectiveBooleanValue() throws XPathException
Get the effective boolean value of the value- Specified by:
effectiveBooleanValue
in interfaceGroundedValue
- Returns:
- true, unless the value is boolean false, numeric zero, or zero-length string
- Throws:
XPathException
- if effective boolean value is not defined for this type (the default behaviour)
-
getComponent
public AtomicValue getComponent(AccessorFn.Component component) throws XPathException
Method to extract components of a value. Implemented by some subclasses, but defined at this level for convenience- Parameters:
component
- identifies the required component, as a constant defined in classAccessorFn
- Returns:
- the value of the requested component of this value
- Throws:
XPathException
- if a dynamic error occursjava.lang.UnsupportedOperationException
- if applied to a value of a type that has no components
-
checkPermittedContents
public void checkPermittedContents(SchemaType parentType, StaticContext env, boolean whole) throws XPathException
Check statically that the results of the expression are capable of constructing the content of a given schema type.- Parameters:
parentType
- The schema typeenv
- the static contextwhole
- true if this atomic value accounts for the entire content of the containing node- Throws:
XPathException
- if the expression doesn't match the required content type
-
checkValidInJavascript
public void checkValidInJavascript() throws XPathException
Check that the value can be handled in SaxonJS- Throws:
XPathException
- if it can't be handled in SaxonJS
-
asAtomic
public AtomicValue asAtomic()
Calling this method on a ConversionResult returns the AtomicValue that results from the conversion if the conversion was successful, and throws a ValidationException explaining the conversion error otherwise.Use this method if you are calling a conversion method that returns a ConversionResult, and if you want to throw an exception if the conversion fails.
- Specified by:
asAtomic
in interfaceConversionResult
- Returns:
- the atomic value that results from the conversion if the conversion was successful
-
toString
public java.lang.String toString()
Get string value.- Overrides:
toString
in classjava.lang.Object
-
toShortString
public java.lang.String toShortString()
Description copied from interface:Item
Provide a short string showing the contents of the item, suitable for use in error messages- Specified by:
toShortString
in interfaceGroundedValue
- Specified by:
toShortString
in interfaceItem
- Returns:
- a depiction of the item suitable for use in error messages
-
show
public java.lang.String show()
Display the value for diagnostics. In general show() for an atomic value displays the value as it would be written in XPath: that is, as a literal if available, or as a call on a constructor function otherwise.- Returns:
- a string representation of this value
-
iterate
public SingleAtomicIterator iterate()
Get an iterator over all the items in the sequence- Specified by:
iterate
in interfaceAtomicSequence
- Specified by:
iterate
in interfaceGroundedValue
- Specified by:
iterate
in interfaceItem
- Specified by:
iterate
in interfaceSequence
- Returns:
- an iterator over all the items
-
iterator
public java.util.Iterator<AtomicValue> iterator()
Returns a Java iterator over the atomic sequence.- Specified by:
iterator
in interfacejava.lang.Iterable<AtomicValue>
- Returns:
- an Iterator.
-
getGenre
public final Genre getGenre()
Get the genre of this item- Specified by:
getGenre
in interfaceItem
- Returns:
- the genre: specifically,
Genre.ATOMIC
;
-
-