net.sf.saxon.value
Class BooleanValue

java.lang.Object
  extended by net.sf.saxon.value.Value
      extended by net.sf.saxon.value.AtomicValue
          extended by net.sf.saxon.value.BooleanValue
All Implemented Interfaces:
Serializable, Comparable, PullEvent, SequenceIterable, GroundedValue, Item, ValueRepresentation, ConversionResult

public final class BooleanValue
extends AtomicValue
implements Comparable

A boolean XPath value

See Also:
Serialized Form

Field Summary
static BooleanValue FALSE
          The boolean value FALSE
static BooleanValue TRUE
          The boolean value TRUE
 
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
 
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, getCardinality, getComponent, getItemType, getLength, getStringValueCS, getTypedValue, getTypeLabel, isNaN, itemAt, iterate, process, setTypeLabel, subsequence
 
Methods inherited from class net.sf.saxon.value.Value
asItem, asItem, asIterator, asValue, convertJavaObjectToXPath, convertToJava, fromItem, getCanonicalLexicalRepresentation, getIterator, iterate, makeQNameValue, reduce, stringToNumber
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

TRUE

public static final BooleanValue TRUE
The boolean value TRUE


FALSE

public static final BooleanValue FALSE
The boolean value FALSE

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

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

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.

Specified by:
copyAsSubType in class AtomicValue
Parameters:
typeLabel - the atomic type label to be added to the copied value
Returns:
the copied 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.

getBooleanValue

public boolean getBooleanValue()
Get the value

Returns:
true or false, the actual boolean value of this BooleanValue

effectiveBooleanValue

public boolean effectiveBooleanValue()
Get the effective boolean value of this expression

Overrides:
effectiveBooleanValue in class AtomicValue
Returns:
the boolean value

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.

Specified by:
getPrimitiveType in class AtomicValue
Returns:
the primitive type

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
validate - true if validation is required. If set to false, the caller guarantees that the value is valid for the target data type, and that further validation is therefore not required. Note that a validation failure may be reported even if validation was not requested.
Returns:
an AtomicValue, a value of the required type

getStringValue

public String getStringValue()
Convert to string

Specified by:
getStringValue in interface Item
Specified by:
getStringValue in interface ValueRepresentation
Specified by:
getStringValue in class AtomicValue
Returns:
"true" or "false"
See Also:
Item.getStringValueCS()

convertToJava

public Object convertToJava(Class target,
                            XPathContext context)
                     throws XPathException
Convert to Java object (for passing to external functions)

Overrides:
convertToJava in class Value
Parameters:
target - the Java class to which conversion is required
context - the XPath dynamic evaluation context
Returns:
An object of the specified Java class
Throws:
XPathException - if conversion is not possible or fails

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

Specified by:
getSchemaComparable in class AtomicValue
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.

Specified by:
getXPathComparable in class AtomicValue
Parameters:
ordered -
collator -
context -
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

compareTo

public int compareTo(Object other)
Compare the value to another boolean value

Specified by:
compareTo in interface Comparable
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)

equals

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

Specified by:
equals in class 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
Throws:
ClassCastException - if other value is not xs:boolean or derived therefrom

hashCode

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

Overrides:
hashCode in class Object
Returns:
the hash code

toString

public String toString()
Diagnostic display of this value as a string

Overrides:
toString in class AtomicValue
Returns:
a string representation of this value: "true()" or "false()"


Copyright (C) Michael H. Kay. All rights reserved.