ValueRepresentation<T>
AtomicValue
, Closure
, EmptySequence
, IntegerRange
, SequenceExtent
, ShareableSequence
, SingletonItem
public abstract class Value<T extends Item> extends java.lang.Object implements ValueRepresentation<T>
Modifier and Type | Field | Description |
---|---|---|
static int |
INDETERMINATE_ORDERING |
Constant returned by compareTo() method to indicate an indeterminate ordering between two values
|
EMPTY_VALUE_ARRAY
Constructor | Description |
---|---|
Value() |
Modifier and Type | Method | Description |
---|---|---|
Item |
asItem() |
Return the value in the form of an Item
|
static Item |
asItem(ValueRepresentation value) |
Static method to make an Item from a Value
|
static <T extends Item> |
asIterator(ValueRepresentation<T> val) |
Static method to get an Iterator over any ValueRepresentation (which may be either a Value
or a NodeInfo or a FunctionItem
|
static <T extends Item> |
asValue(ValueRepresentation<T> val) |
Static method to make a Value from a given Item (which may be either an AtomicValue
or a NodeInfo or a FunctionItem
|
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.
|
static java.lang.Object |
convertToJava(Item item) |
Convert an XPath value to a Java object.
|
boolean |
effectiveBooleanValue() |
Get the effective boolean value of the expression.
|
boolean |
equals(java.lang.Object obj) |
Compare two (sequence) values for equality.
|
static Value |
fromItem(Item item) |
Static method to get a Value from an Item
|
java.lang.CharSequence |
getCanonicalLexicalRepresentation() |
Get the canonical lexical representation as defined in XML Schema.
|
int |
getCardinality() |
Determine the cardinality
|
ItemType |
getItemType(TypeHierarchy th) |
Determine the data type of the items in the expression, if possible
|
static SequenceIterator |
getIterator(ValueRepresentation val) |
Get a SequenceIterator over a ValueRepresentation
|
int |
getLength() |
Get the length of the sequence
|
java.lang.Comparable |
getSchemaComparable() |
Get a Comparable value that implements the XML Schema ordering comparison semantics for this value.
|
static int |
getSequenceLength(ValueRepresentation val) |
Static method to get the length of a ValueRepresentation (the number
of items in the sequence)
|
java.lang.String |
getStringValue() |
Convert the value to a string, using the serialization rules.
|
java.lang.CharSequence |
getStringValueCS() |
Get the value of the item as a CharSequence.
|
int |
hashCode() |
|
boolean |
isIdentical(Value v) |
Determine whether two values are identical, as determined by XML Schema rules.
|
T |
itemAt(int n) |
Get the n'th item in the sequence (starting from 0).
|
abstract SequenceIterator<T> |
iterate() |
Iterate over the items contained in this value.
|
void |
process(XPathContext context) |
Process the value as an instruction, without returning any tail calls
|
Value |
reduce() |
Reduce a value to its simplest form.
|
public static final int INDETERMINATE_ORDERING
public static <T extends Item> Value<T> asValue(ValueRepresentation<T> val)
val
- The supplied value, or null, indicating the empty sequence.public static int getSequenceLength(ValueRepresentation val) throws XPathException
val
- The supplied value, or null, indicating the empty sequence.XPathException
- if an error occurs (for example, if the supplied
value is a Closure and needs to be evaluated to determine the length of the result)public static Item asItem(ValueRepresentation value) throws XPathException
value
- the value to be convertedXPathException
- if the Value contains multiple itemspublic Item asItem() throws XPathException
XPathException
- if an error occurs, notably if this value is a sequence
containing more than one itempublic static Value fromItem(Item item)
item
- the supplied itempublic static <T extends Item> SequenceIterator<T> asIterator(ValueRepresentation<T> val) throws XPathException
val
- The supplied value, or null, indicating the empty sequence.XPathException
- if an error occurspublic static SequenceIterator getIterator(ValueRepresentation val) throws XPathException
val
- the value to iterate overXPathException
- if an error occurs (typically when the value
is a Closure that needs to be evaluated)public abstract SequenceIterator<T> iterate() throws XPathException
XPathException
- if a dynamic error occurs. This is possible only in the case of values
that are materialized lazily, that is, where the iterate() method leads to computation of an
expression that delivers the values.public java.lang.CharSequence getStringValueCS() throws XPathException
getStringValueCS
in interface ValueRepresentation<T extends Item>
XPathException
- The method can fail if evaluation of the value
has been deferred, and if a failure occurs during the deferred evaluation.
It can also occur for values such as function items and maps that have no string value.
No failure is possible in the case of an AtomicValue or a Node.public java.lang.CharSequence getCanonicalLexicalRepresentation()
public ItemType getItemType(TypeHierarchy th)
th
- The TypeHierarchy. If null is supplied, the resulting item type may
be less precise.public int getCardinality()
public T itemAt(int n) throws XPathException
n
- position of the required item, counting from zero.XPathException
- if an error occurs (for example if the
value is a Closure that needs to be evaluated to find the Nth item)public int getLength() throws XPathException
XPathException
- if an error occurs (for example if the value is
a closure that needs to be read to determine its length)public void process(XPathContext context) throws XPathException
context
- The dynamic context, giving access to the current node,
the current variables, etc.XPathException
- if an error occurs (for example if the value is
a closure that needs to be evaluated)public java.lang.String getStringValue() throws XPathException
getStringValue
in interface ValueRepresentation<T extends Item>
XPathException
- The method can fail if evaluation of the value
has been deferred, and if a failure occurs during the deferred evaluation.
No failure is possible in the case of an AtomicValue.public boolean effectiveBooleanValue() throws XPathException
XPathException
- if any dynamic error occurs evaluating the
expressionpublic java.lang.Comparable getSchemaComparable()
In the case of data types that are partially ordered, the returned Comparable extends the standard
semantics of the compareTo() method by returning the value INDETERMINATE_ORDERING
when there
is no defined order relationship between two given values.
public boolean equals(java.lang.Object obj)
Consider creating an XPathComparable from each value, and comparing those; or creating a SchemaComparable to achieve equality comparison as defined in XML Schema.
equals
in class java.lang.Object
java.lang.UnsupportedOperationException
- (always)public int hashCode()
hashCode
in class java.lang.Object
public boolean isIdentical(Value v)
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.
Although the schema rules cover atomic values only, this method also handles values that include nodes, using node identity in this case.
The empty sequence is considered identical to the empty sequence.
NaN is identical to itself.
Function items are not identical to anything except themselves
v
- the other value to be compared with this onepublic void checkPermittedContents(SchemaType parentType, StaticContext env, boolean whole) throws XPathException
parentType
- The schema typeenv
- the static contextwhole
- true if this value accounts for the entire content of the containing nodeXPathException
- if the expression doesn't match the required content typepublic Value reduce() throws XPathException
XPathException
- if an error occurspublic static java.lang.Object convertToJava(Item item) throws XPathException
item
- the item to be convertedXPathException
- if an error occurs: for example, if the XPath value is
an integer and is too big to fit in a Java long