net.sf.saxon.value

Class BooleanValue

Implemented Interfaces:
Comparable, ConversionResult, GroundedValue, Item, PullEvent, Serializable, SequenceIterable, ValueRepresentation

public final class BooleanValue
extends AtomicValue
implements Comparable

A boolean XPath value

Field Summary

static BooleanValue
FALSE
The boolean value FALSE
static BooleanValue
TRUE
The boolean value TRUE

Fields inherited from class net.sf.saxon.value.AtomicValue

typeLabel

Fields inherited from class net.sf.saxon.value.Value

EMPTY_CLASS_ARRAY, INDETERMINATE_ORDERING

Fields inherited from interface net.sf.saxon.om.ValueRepresentation

EMPTY_VALUE_ARRAY

Constructor Summary

BooleanValue(boolean value, AtomicType typeLabel)
Create a new Boolean value with a user-supplied type label.

Method Summary

int
compareTo(Object other)
Compare the value to another boolean value
ConversionResult
convertPrimitive(BuiltInAtomicType requiredType, boolean validate, XPathContext context)
Convert to target data type
Object
convertToJava(Class target, XPathContext context)
Convert to Java object (for passing to external functions)
AtomicValue
copyAsSubType(AtomicType typeLabel)
Create a copy of this atomic value (usually so that the type label can be changed).
boolean
effectiveBooleanValue()
Get the effective boolean value of this expression
boolean
equals(Object other)
Determine whether two boolean values are equal
static ConversionResult
fromString(CharSequence s)
Convert a string to a boolean value, using the XML Schema rules (including whitespace trimming)
static BooleanValue
get(boolean value)
Factory method: get a BooleanValue
boolean
getBooleanValue()
Get the value
BuiltInAtomicType
getPrimitiveType()
Determine the primitive type of the value.
Comparable
getSchemaComparable()
Get a Comparable value that implements the XML Schema ordering comparison semantics for this value.
String
getStringValue()
Convert to string
Object
getXPathComparable(boolean ordered, StringCollator collator, XPathContext context)
Get a Comparable value that implements the XPath ordering comparison semantics for this value.
int
hashCode()
Get a hash code for comparing two BooleanValues
String
toString()
Diagnostic display of this value as a string

Methods inherited from class net.sf.saxon.value.AtomicValue

asAtomic, checkPermittedContents, convert, convert, convertPrimitive, copyAsSubType, effectiveBooleanValue, equals, getCardinality, getComponent, getItemType, getLength, getPrimitiveType, getSchemaComparable, getStringValue, getStringValueCS, getTypeLabel, getTypedValue, getXPathComparable, isNaN, itemAt, iterate, process, setTypeLabel, subsequence, toString

Methods inherited from class net.sf.saxon.value.Value

asItem, asItem, asIterator, asValue, checkPermittedContents, convertJavaObjectToXPath, convertToJava, convertToJava, effectiveBooleanValue, equals, fromItem, getCanonicalLexicalRepresentation, getCardinality, getItemType, getIterator, getLength, getSchemaComparable, getStringValue, getStringValueCS, itemAt, iterate, iterate, makeQNameValue, process, reduce, stringToNumber, toString

Field Details

FALSE

public static final BooleanValue FALSE
The boolean value FALSE

TRUE

public static final BooleanValue TRUE
The boolean value TRUE

Constructor Details

BooleanValue

public BooleanValue(boolean value,
                    AtomicType typeLabel)
Create a new Boolean value with a user-supplied type label. It is the caller's responsibility to ensure that the value is valid for the subtype
Parameters:
value - the boolean value
typeLabel - the type label, xs:boolean or a subtype

Method Details

compareTo

public int compareTo(Object other)
Compare the value to another boolean value
Parameters:
other - The other boolean value
Returns:
-1 if this one is the lower, 0 if they are equal, +1 if this one is the higher. False is considered to be less than true.

convertPrimitive

public ConversionResult convertPrimitive(BuiltInAtomicType requiredType,
                                         boolean validate,
                                         XPathContext context)
Convert to target data type
Overrides:
convertPrimitive in interface AtomicValue
Parameters:
requiredType - an integer identifying the required atomic type
context - XPath dynamic context
Returns:
an AtomicValue, a value of the required type

convertToJava

public Object convertToJava(Class target,
                            XPathContext context)
            throws XPathException
Convert to Java object (for passing to external functions)
Overrides:
convertToJava in interface Value
Parameters:
target - the Java class to which conversion is required
Returns:
An object of the specified Java class
Throws:
XPathException - if conversion is not possible or fails

copyAsSubType

public AtomicValue copyAsSubType(AtomicType typeLabel)
Create a copy of this atomic value (usually so that the type label can be changed). The type label of the copy will be reset to the primitive type.
Overrides:
copyAsSubType in interface AtomicValue
Parameters:
typeLabel - the atomic type label to be added to the copied value

effectiveBooleanValue

public boolean effectiveBooleanValue()
Get the effective boolean value of this expression
Overrides:
effectiveBooleanValue in interface AtomicValue
Returns:
the boolean value

equals

public boolean equals(Object other)
Determine whether two boolean values are equal
Overrides:
equals in interface AtomicValue
Parameters:
other - the value to be compared to this value
Returns:
true if the other value is a boolean value and is equal to this value

fromString

public static ConversionResult fromString(CharSequence s)
Convert a string to a boolean value, using the XML Schema rules (including whitespace trimming)
Parameters:
s - the input string
Returns:
the relevant BooleanValue if validation succeeds; or a ValidationFailure if not.

get

public static BooleanValue get(boolean value)
Factory method: get a BooleanValue
Parameters:
value - true or false, to determine which boolean value is required
Returns:
the BooleanValue requested

getBooleanValue

public boolean getBooleanValue()
Get the value
Returns:
true or false, the actual boolean value of this BooleanValue

getPrimitiveType

public 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 AnyAtomicType.
Overrides:
getPrimitiveType in interface AtomicValue

getSchemaComparable

public Comparable getSchemaComparable()
Overrides:
getSchemaComparable in interface AtomicValue
Returns:
a Comparable that follows XML Schema comparison rules

getStringValue

public String getStringValue()
Convert to string
Specified by:
getStringValue in interface Item
getStringValue in interface ValueRepresentation
Overrides:
getStringValue in interface AtomicValue
Returns:
"true" or "false"

getXPathComparable

public Object getXPathComparable(boolean ordered,
                                 StringCollator collator,
                                 XPathContext context)
Get a Comparable value that implements the XPath ordering comparison semantics for this value. Returns null if the value is not comparable according to XPath rules. The default implementation returns null. This is overridden for types that allow ordered comparisons in XPath: numeric, boolean, string, date, time, dateTime, yearMonthDuration, dayTimeDuration, and anyURI.
Overrides:
getXPathComparable in interface AtomicValue
Parameters:
ordered -
collator -
context -

hashCode

public int hashCode()
Get a hash code for comparing two BooleanValues
Returns:
the hash code

toString

public String toString()
Diagnostic display of this value as a string
Overrides:
toString in interface AtomicValue
Returns:
a string representation of this value: "true()" or "false()"