net.sf.saxon.value

Class BooleanValue

public final class BooleanValue extends AtomicValue implements Comparable

A boolean XPath value
Field Summary
static BooleanValueFALSE
The boolean value FALSE
static BooleanValueTRUE
The boolean value TRUE
Constructor Summary
BooleanValue(boolean value, AtomicType typeLabel)
Create a new Boolean value with a user-supplied type label.
Method Summary
intcompareTo(Object other)
Compare the value to another boolean value
ConversionResultconvertPrimitive(BuiltInAtomicType requiredType, boolean validate, XPathContext context)
Convert to target data type
AtomicValuecopyAsSubType(AtomicType typeLabel)
Create a copy of this atomic value (usually so that the type label can be changed).
booleaneffectiveBooleanValue()
Get the effective boolean value of this expression
booleanequals(Object other)
Determine whether two boolean values are equal
static ConversionResultfromString(CharSequence s)
Convert a string to a boolean value, using the XML Schema rules (including whitespace trimming)
static BooleanValueget(boolean value)
Factory method: get a BooleanValue
booleangetBooleanValue()
Get the value
StringgetPrimitiveStringValue()
Convert to string
BuiltInAtomicTypegetPrimitiveType()
Determine the primitive type of the value.
ComparablegetSchemaComparable()
Get a Comparable value that implements the XML Schema ordering comparison semantics for this value.
ObjectgetXPathComparable(boolean ordered, StringCollator collator, XPathContext context)
Get a Comparable value that implements the XPath ordering comparison semantics for this value.
inthashCode()
Get a hash code for comparing two BooleanValues
StringtoString()
Diagnostic display of this value as a string

Field Detail

FALSE

public static final BooleanValue FALSE
The boolean value FALSE

TRUE

public static final BooleanValue TRUE
The boolean value TRUE

Constructor Detail

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 Detail

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.

Throws: ClassCastException if the other value is not a BooleanValue (the parameter is declared as Object to satisfy the Comparable interface)

convertPrimitive

public ConversionResult convertPrimitive(BuiltInAtomicType requiredType, boolean validate, XPathContext context)
Convert to target data type

Parameters: requiredType an integer identifying the required atomic type context XPath dynamic context

Returns: an AtomicValue, a value of the required type

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.

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

Returns: the boolean value

equals

public boolean equals(Object other)
Determine whether two boolean values are equal

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

Throws: ClassCastException if other value is not xs:boolean or derived therefrom

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

getPrimitiveStringValue

public String getPrimitiveStringValue()
Convert to string

Returns: "true" or "false"

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.

getSchemaComparable

public Comparable getSchemaComparable()
Get a Comparable value that implements the XML Schema ordering comparison semantics for this value. The default implementation returns "this". This is overridden for particular atomic types.

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 BooleanValue when there is no defined order relationship between two given values.

Returns: a Comparable that follows XML Schema comparison rules

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.

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

Returns: a string representation of this value: "true()" or "false()"