net.sf.saxon.value
Class GDateValue

java.lang.Object
  extended by net.sf.saxon.value.Value
      extended by net.sf.saxon.value.AtomicValue
          extended by net.sf.saxon.value.CalendarValue
              extended by net.sf.saxon.value.GDateValue
All Implemented Interfaces:
Serializable, PullEvent, SequenceIterable, GroundedValue, Item, ValueRepresentation, ConversionResult
Direct Known Subclasses:
DateValue, GDayValue, GMonthDayValue, GMonthValue, GYearMonthValue, GYearValue

public abstract class GDateValue
extends CalendarValue

Abstract superclass for the primitive types containing date components: xs:date, xs:gYear, xs:gYearMonth, xs:gMonth, xs:gMonthDay, xs:gDay

See Also:
Serialized Form

Field Summary
 
Fields inherited from class net.sf.saxon.value.CalendarValue
NO_TIMEZONE
 
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
GDateValue()
           
 
Method Summary
 int compareTo(CalendarValue other, XPathContext context)
          Compare this value to another value of the same type, using the supplied context object to get the implicit timezone if required.
 Object convertToJava(Class target, XPathContext context)
          Convert to Java object (for passing to external functions)
 boolean equals(Object o)
          The equals() methods on atomic values is defined to follow the semantics of eq when applied to two atomic values.
 GregorianCalendar getCalendar()
          Get a Java Calendar object that represents this date/time value.
 ComparisonKey getComparisonKey(XPathContext context)
          Get a comparison key for this value.
 byte getDay()
          Get the day component of the date (in local form)
 byte getMonth()
          Get the month component of the date (in local form)
 Comparable getSchemaComparable()
          Get a Comparable value that implements the XML Schema ordering comparison semantics for this value.
 int getYear()
          Get the year component of the date (in local form)
 int hashCode()
           
static boolean isLeapYear(int year)
          Test whether a year is a leap year
static boolean isValidDate(int year, int month, int day)
          Determine whether a given date is valid
 DateTimeValue toDateTime()
          Convert to DateTime.
 
Methods inherited from class net.sf.saxon.value.CalendarValue
add, adjustTimezone, adjustTimezone, appendTimezone, appendTimezone, getStringValue, getTimezoneInMinutes, getXPathComparable, hasTimezone, removeTimezone, setTimezoneInMinutes, subtract
 
Methods inherited from class net.sf.saxon.value.AtomicValue
asAtomic, checkPermittedContents, convert, convert, copyAsSubType, effectiveBooleanValue, getCardinality, getComponent, getItemType, getLength, getPrimitiveType, getStringValueCS, getTypedValue, getTypeLabel, isNaN, itemAt, iterate, process, setTypeLabel, subsequence, toString
 
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
 

Constructor Detail

GDateValue

public GDateValue()
Method Detail

getYear

public int getYear()
Get the year component of the date (in local form)

Returns:
the year component

getMonth

public byte getMonth()
Get the month component of the date (in local form)

Returns:
the month component (1-12)

getDay

public byte getDay()
Get the day component of the date (in local form)

Returns:
the day component (1-31)

getCalendar

public GregorianCalendar getCalendar()
Description copied from class: CalendarValue
Get a Java Calendar object that represents this date/time value. The Calendar object will be newly created for the purpose

Specified by:
getCalendar in class CalendarValue
Returns:
A Calendar object representing the date and time. Note that Java can only represent the time to millisecond precision, and that it does not support the full range of timezones required by XPath (-14:00 to +14:00)

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 required target class
context - the XPath dynamic evaluation context
Returns:
the (boxed) Java object that best represents the XPath value
Throws:
XPathException

isValidDate

public static boolean isValidDate(int year,
                                  int month,
                                  int day)
Determine whether a given date is valid

Parameters:
year - the year
month - the month (1-12)
day - the day (1-31)
Returns:
true if this is a valid date

isLeapYear

public static boolean isLeapYear(int year)
Test whether a year is a leap year

Parameters:
year - the year
Returns:
true if the supplied year is a leap year

equals

public boolean equals(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 returns false.

The hashCode() method is consistent with equals().

This implementation performs a context-free comparison: it fails with ClassCastException if one value has a timezone and the other does not.

Specified by:
equals in class AtomicValue
Parameters:
o - the other value
Returns:
true if the other operand is an atomic value and the two values are equal as defined by the XPath eq operator
Throws:
ClassCastException - if the values are not comparable

hashCode

public int hashCode()
Overrides:
hashCode in class Object

compareTo

public int compareTo(CalendarValue other,
                     XPathContext context)
              throws NoDynamicContextException
Compare this value to another value of the same type, using the supplied context object to get the implicit timezone if required. This method implements the XPath comparison semantics.

Specified by:
compareTo in class CalendarValue
Parameters:
other - the value to be compared
context - the XPath dynamic evaluation context (needed only to get the implicit timezone)
Returns:
-1 if this value is less, 0 if equal, +1 if greater
Throws:
NoDynamicContextException - if the supplied context is an early evaluation context and the result depends on the implicit timezone, which is not available at compile time

toDateTime

public DateTimeValue toDateTime()
Convert to DateTime.

Specified by:
toDateTime in class CalendarValue
Returns:
the starting instant of the GDateValue (with the same timezone)

getSchemaComparable

public Comparable getSchemaComparable()
Description copied from class: AtomicValue
Get a Comparable value that implements the XML Schema ordering comparison semantics for this value. An implementation must be provided for all 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. This value is also returned when two values of different types are compared.

Specified by:
getSchemaComparable in class AtomicValue
Returns:
a Comparable that follows XML Schema comparison rules

getComparisonKey

public ComparisonKey getComparisonKey(XPathContext context)
                               throws NoDynamicContextException
Get a comparison key for this value. Two values are equal if and only if they their comparison keys are equal

Specified by:
getComparisonKey in class CalendarValue
Parameters:
context - XPath dynamic evaluation context
Returns:
a comparison key
Throws:
NoDynamicContextException - if the implicit timezone is required and is not available (because the method is being called at compile time)


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