Author: bcarothers
Date: 2009-07-13 11:01:51 -0400 (Mon, 13 Jul 2009)
New Revision: 1105
Modified:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/DateTime.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/basic/JodaDateTime.java
Log:
DNA-491 JodaDateTime Is Using Overly-Strict Equality Test
Committed patch that swaps the semantics of DateTime.isSameAs and DateTime.equals to be
semantically consistent with the JCR expectation for equality of date times (that they
represent the same logical instant in time).
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/DateTime.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/DateTime.java 2009-07-13
13:31:28 UTC (rev 1104)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/DateTime.java 2009-07-13
15:01:51 UTC (rev 1105)
@@ -263,7 +263,9 @@
boolean isAfter( DateTime other );
/**
- * Return whether this date-time is at the same time as the supplied date-time.
+ * Return whether this date-time is exactly the the same as the supplied date-time.
This differs from {@link #equals(Object)
+ * the equals method} in that it can be arbitrarily more strict, checking, for
example, not only the logical equivalence of
+ * the other date time, but also arbitrary additional fields such as the time zone.
*
* @param other the date-time to compare with
* @return true if this date-time is later than the other, or false otherwise
Modified:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/basic/JodaDateTime.java
===================================================================
---
trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/basic/JodaDateTime.java 2009-07-13
13:31:28 UTC (rev 1104)
+++
trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/basic/JodaDateTime.java 2009-07-13
15:01:51 UTC (rev 1105)
@@ -341,7 +341,13 @@
if (obj == this) return true;
if (obj instanceof JodaDateTime) {
JodaDateTime that = (JodaDateTime)obj;
- return this.instance.equals(that.instance);
+
+ /*
+ * The equals semantics for JodaDateTimes are very strict, implying that not
only are the two instants represented
+ * by the JodaDateTimes logically equivalent, but also that the Chronology
and DateTimeZone are the same.
+ * Instead, use isEqual, which only checks that the two JodaDateTimes are
logically equivalent.
+ */
+ return this.instance.isEqual(that.instance);
}
if (obj instanceof DateTime) {
return this.instance.equals(obj);
@@ -389,7 +395,18 @@
* @see
org.jboss.dna.graph.property.DateTime#isSameAs(org.jboss.dna.graph.property.DateTime)
*/
public boolean isSameAs( org.jboss.dna.graph.property.DateTime other ) {
- return this.compareTo(other) == 0;
+ if (other == this) return true;
+ if (other instanceof JodaDateTime) {
+ JodaDateTime that = (JodaDateTime)other;
+
+ /*
+ * The equals semantics for JodaDateTimes are very strict, implying that not
only are the two instants represented
+ * by the JodaDateTimes logically equivalent, but also that the Chronology
and DateTimeZone are the same.
+ * Here we use equals to ensure that the two DateTimes are equivalent.
+ */
+ return this.instance.equals(that.instance);
+ }
+ return this.instance.equals(other);
}
/**
Show replies by date