Author: rhauch
Date: 2008-07-09 10:52:15 -0400 (Wed, 09 Jul 2008)
New Revision: 344
Modified:
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/DateTime.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateTime.java
Log:
DNA-115 - Create federation service
http://jira.jboss.com/jira/browse/DNA-115
Added methods to compare DateTime instances (isBefore, isAfter, isSameAs). Also optimized
the 'compareTo' method of JodaDateTime to delegate to the wrapped Joda DateTime
instances if comparing two DNA JodaDateTime instances.
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/DateTime.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/DateTime.java 2008-07-09 14:46:07
UTC (rev 343)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/DateTime.java 2008-07-09 14:52:15
UTC (rev 344)
@@ -31,6 +31,7 @@
*
href="http://jcp.org/en/jsr/detail?id=310">JSR-310</a>, which will
be based upon <a
*
href="http://joda-time.sourceforge.net/">Joda-Time</a>. This class
serves as a stable migration path toward the new JSR 310
* classes.
+ *
* @author Randall Hauch
*/
@Immutable
@@ -55,6 +56,7 @@
* <li>three decimal places for milliseconds, if required;</li>
* <li>time zone offset of the form <code>�HH:mm</code> (or
'0' if UTC)</li>
* </ul>
+ *
* @return the string representation; never null
*/
String getString();
@@ -62,6 +64,7 @@
/**
* Get the number of milliseconds from 1970-01-01T00:00Z. This value is consistent
with the JDK {@link java.util.Date Date}
* and {@link java.util.Calendar Calendar} classes.
+ *
* @return the number of milliseconds from 1970-01-01T00:00Z
*/
long getMilliseconds();
@@ -69,145 +72,202 @@
/**
* Get this instance represented as a standard JDK {@link java.util.Date} instance.
Note that this conversion loses the time
* zone information, as the standard JDK {@link java.util.Date} does not represent
time zones.
+ *
* @return this instance in time as a JDK Date; never null
*/
java.util.Date toDate();
/**
- * Get this instance represented as a standard JDK {@link java.util.Calendar}
instance, in the
- * {@link Locale#getDefault() default locale}.
+ * Get this instance represented as a standard JDK {@link java.util.Calendar}
instance, in the {@link Locale#getDefault()
+ * default locale}.
+ *
* @return this instance in time as a JDK Calendar; never null
*/
java.util.Calendar toCalendar();
/**
- * Get this instance represented as a standard JDK {@link java.util.Calendar}
instance, in the specified {@link Locale locale}.
- * @param locale the locale in which the Calendar instance is desired; may be null if
the
- * {@link Locale#getDefault() default locale} is to be used.
+ * Get this instance represented as a standard JDK {@link java.util.Calendar}
instance, in the specified {@link Locale locale}
+ * .
+ *
+ * @param locale the locale in which the Calendar instance is desired; may be null if
the {@link Locale#getDefault() default
+ * locale} is to be used.
* @return this instance in time as a JDK Calendar; never null
*/
java.util.Calendar toCalendar( Locale locale );
/**
* Get this instance represented as a standard JDK {@link
java.util.GregorianCalendar} instance.
+ *
* @return this instance in time as a JDK GregorianCalendar; never null
*/
java.util.GregorianCalendar toGregorianCalendar();
/**
* Get the era of this instance in time.
+ *
* @return the era
*/
int getEra();
/**
* Get the era of this instance in time.
+ *
* @return the era
*/
int getYear();
/**
* Get the era of this instance in time.
+ *
* @return the era
*/
int getWeekyear();
/**
* Get the era of this instance in time.
+ *
* @return the era
*/
int getCenturyOfEra();
/**
* Get the year of the era of this instance in time.
+ *
* @return the year of the era
*/
int getYearOfEra();
/**
* Get the year of this century of this instance in time.
+ *
* @return the year of the century
*/
int getYearOfCentury();
/**
* Get the month of the year of this instance in time.
+ *
* @return the month number
*/
int getMonthOfYear();
/**
* Get the week of the weekyear of this instance in time.
+ *
* @return the week of the weekyear
*/
int getWeekOfWeekyear();
/**
* Get the day of the year of this instance in time.
+ *
* @return the day of the year
*/
int getDayOfYear();
/**
* Get the day of the month value of this instance in time.
+ *
* @return the day of the month
*/
int getDayOfMonth();
/**
* Get the day of the week value of this instance in time.
+ *
* @return the day of the week
*/
int getDayOfWeek();
/**
* Get the hour of the day of this instance in time.
+ *
* @return the hour of the day
*/
int getHourOfDay();
/**
* Get the minute of this instance in time.
+ *
* @return the minute of the hour
*/
int getMinuteOfHour();
/**
* Get the seconds of the minute value of this instance in time.
+ *
* @return the seconds of the minute
*/
int getSecondOfMinute();
/**
* Get the milliseconds of the second value of this instance in time.
+ *
* @return the milliseconds
*/
int getMillisOfSecond();
/**
* Get the number of hours that this time zone is offset from UTC.
+ *
* @return the number of hours
*/
int getTimeZoneOffsetHours();
/**
* Get the identifier of the time zone in which this instant is defined
+ *
* @return the time zone identifier; never null
*/
String getTimeZoneId();
/**
* Convert this time to the same instant in the UTC time zone.
+ *
* @return this instant in time in the specified time zone
*/
DateTime toUtcTimeZone();
/**
* Convert this time to the time zone given by the supplied identifier.
+ *
* @param timeZoneId the time zone identifier
* @return the instant in the specified time zone
* @throws IllegalArgumentException if the time zone identifier is null or is
invalid
*/
DateTime toTimeZone( String timeZoneId );
+ /**
+ * Return whether this date-time is earlier than the supplied date-time.
+ *
+ * @param other the date-time to compare with
+ * @return true if this date-time is earliar than the other, or false otherwise
+ * @see #compareTo(DateTime)
+ * @see #isSameAs(DateTime)
+ * @see #isAfter(DateTime)
+ */
+ boolean isBefore( DateTime other );
+
+ /**
+ * Return whether this date-time is later than the supplied date-time.
+ *
+ * @param other the date-time to compare with
+ * @return true if this date-time is later than the other, or false otherwise
+ * @see #compareTo(DateTime)
+ * @see #isBefore(DateTime)
+ * @see #isSameAs(DateTime)
+ */
+ boolean isAfter( DateTime other );
+
+ /**
+ * Return whether this date-time is at the same time as the supplied date-time.
+ *
+ * @param other the date-time to compare with
+ * @return true if this date-time is later than the other, or false otherwise
+ * @see #compareTo(DateTime)
+ * @see #isBefore(DateTime)
+ * @see #isAfter(DateTime)
+ */
+ boolean isSameAs( DateTime other );
+
}
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateTime.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateTime.java 2008-07-09
14:46:07 UTC (rev 343)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateTime.java 2008-07-09
14:52:15 UTC (rev 344)
@@ -33,6 +33,7 @@
/**
* Implementation of DateTime based upon the Joda-Time library.
+ *
* @author Randall Hauch
*/
@Immutable
@@ -55,7 +56,8 @@
this.instance = new DateTime(iso8601);
}
- public JodaDateTime( String iso8601, String timeZoneId ) {
+ public JodaDateTime( String iso8601,
+ String timeZoneId ) {
this.instance = new DateTime(iso8601, DateTimeZone.forID(timeZoneId));
}
@@ -63,7 +65,8 @@
this.instance = new DateTime(milliseconds);
}
- public JodaDateTime( long milliseconds, Chronology chronology ) {
+ public JodaDateTime( long milliseconds,
+ Chronology chronology ) {
this.instance = new DateTime(milliseconds, chronology);
}
@@ -71,24 +74,62 @@
this.instance = new DateTime(dateTimeZone);
}
- public JodaDateTime( int year, int monthOfYear, int dayOfMonth, int hourOfDay, int
minuteOfHour, int secondOfMinute, int millisecondsOfSecond ) {
+ public JodaDateTime( int year,
+ int monthOfYear,
+ int dayOfMonth,
+ int hourOfDay,
+ int minuteOfHour,
+ int secondOfMinute,
+ int millisecondsOfSecond ) {
this.instance = new DateTime(year, monthOfYear, dayOfMonth, hourOfDay,
minuteOfHour, secondOfMinute, millisecondsOfSecond);
}
- public JodaDateTime( int year, int monthOfYear, int dayOfMonth, int hourOfDay, int
minuteOfHour, int secondOfMinute, int millisecondsOfSecond, Chronology chronology ) {
- this.instance = new DateTime(year, monthOfYear, dayOfMonth, hourOfDay,
minuteOfHour, secondOfMinute, millisecondsOfSecond, chronology);
+ public JodaDateTime( int year,
+ int monthOfYear,
+ int dayOfMonth,
+ int hourOfDay,
+ int minuteOfHour,
+ int secondOfMinute,
+ int millisecondsOfSecond,
+ Chronology chronology ) {
+ this.instance = new DateTime(year, monthOfYear, dayOfMonth, hourOfDay,
minuteOfHour, secondOfMinute,
+ millisecondsOfSecond, chronology);
}
- public JodaDateTime( int year, int monthOfYear, int dayOfMonth, int hourOfDay, int
minuteOfHour, int secondOfMinute, int millisecondsOfSecond, DateTimeZone dateTimeZone ) {
- this.instance = new DateTime(year, monthOfYear, dayOfMonth, hourOfDay,
minuteOfHour, secondOfMinute, millisecondsOfSecond, dateTimeZone);
+ public JodaDateTime( int year,
+ int monthOfYear,
+ int dayOfMonth,
+ int hourOfDay,
+ int minuteOfHour,
+ int secondOfMinute,
+ int millisecondsOfSecond,
+ DateTimeZone dateTimeZone ) {
+ this.instance = new DateTime(year, monthOfYear, dayOfMonth, hourOfDay,
minuteOfHour, secondOfMinute,
+ millisecondsOfSecond, dateTimeZone);
}
- public JodaDateTime( int year, int monthOfYear, int dayOfMonth, int hourOfDay, int
minuteOfHour, int secondOfMinute, int millisecondsOfSecond, int timeZoneOffsetHours ) {
- this.instance = new DateTime(year, monthOfYear, dayOfMonth, hourOfDay,
minuteOfHour, secondOfMinute, millisecondsOfSecond,
DateTimeZone.forOffsetHours(timeZoneOffsetHours));
+ public JodaDateTime( int year,
+ int monthOfYear,
+ int dayOfMonth,
+ int hourOfDay,
+ int minuteOfHour,
+ int secondOfMinute,
+ int millisecondsOfSecond,
+ int timeZoneOffsetHours ) {
+ this.instance = new DateTime(year, monthOfYear, dayOfMonth, hourOfDay,
minuteOfHour, secondOfMinute,
+ millisecondsOfSecond,
DateTimeZone.forOffsetHours(timeZoneOffsetHours));
}
- public JodaDateTime( int year, int monthOfYear, int dayOfMonth, int hourOfDay, int
minuteOfHour, int secondOfMinute, int millisecondsOfSecond, String timeZoneId ) {
- this.instance = new DateTime(year, monthOfYear, dayOfMonth, hourOfDay,
minuteOfHour, secondOfMinute, millisecondsOfSecond, DateTimeZone.forID(timeZoneId));
+ public JodaDateTime( int year,
+ int monthOfYear,
+ int dayOfMonth,
+ int hourOfDay,
+ int minuteOfHour,
+ int secondOfMinute,
+ int millisecondsOfSecond,
+ String timeZoneId ) {
+ this.instance = new DateTime(year, monthOfYear, dayOfMonth, hourOfDay,
minuteOfHour, secondOfMinute,
+ millisecondsOfSecond,
DateTimeZone.forID(timeZoneId));
}
public JodaDateTime( java.util.Date jdkDate ) {
@@ -274,7 +315,11 @@
* {@inheritDoc}
*/
public int compareTo( org.jboss.dna.spi.graph.DateTime that ) {
- return this.instance.compareTo(that);
+ if (that instanceof JodaDateTime) {
+ return this.instance.compareTo(((JodaDateTime)that).instance);
+ }
+ long diff = this.toUtcTimeZone().getMilliseconds() -
that.toUtcTimeZone().getMilliseconds();
+ return (int)diff;
}
/**
@@ -326,4 +371,31 @@
return new JodaDateTime(jodaTime);
}
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.DateTime#isBefore(org.jboss.dna.spi.graph.DateTime)
+ */
+ public boolean isBefore( org.jboss.dna.spi.graph.DateTime other ) {
+ return this.compareTo(other) < 0;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.DateTime#isSameAs(org.jboss.dna.spi.graph.DateTime)
+ */
+ public boolean isSameAs( org.jboss.dna.spi.graph.DateTime other ) {
+ return this.compareTo(other) == 0;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.DateTime#isAfter(org.jboss.dna.spi.graph.DateTime)
+ */
+ public boolean isAfter( org.jboss.dna.spi.graph.DateTime other ) {
+ return this.compareTo(other) > 0;
+ }
+
}