You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by an...@apache.org on 2007/08/21 17:46:39 UTC
svn commit: r568172 -
/jackrabbit/trunk/contrib/spi/commons/src/main/java/org/apache/jackrabbit/value/QValueFactoryImpl.java
Author: angela
Date: Tue Aug 21 08:46:38 2007
New Revision: 568172
URL: http://svn.apache.org/viewvc?rev=568172&view=rev
Log:
JCR-1072: SPI-commons: QValueTest.testDateValueEquality2 fails due to changes made with JCR-1018
Modified:
jackrabbit/trunk/contrib/spi/commons/src/main/java/org/apache/jackrabbit/value/QValueFactoryImpl.java
Modified: jackrabbit/trunk/contrib/spi/commons/src/main/java/org/apache/jackrabbit/value/QValueFactoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/commons/src/main/java/org/apache/jackrabbit/value/QValueFactoryImpl.java?rev=568172&r1=568171&r2=568172&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/commons/src/main/java/org/apache/jackrabbit/value/QValueFactoryImpl.java (original)
+++ jackrabbit/trunk/contrib/spi/commons/src/main/java/org/apache/jackrabbit/value/QValueFactoryImpl.java Tue Aug 21 08:46:38 2007
@@ -68,7 +68,7 @@
case PropertyType.BOOLEAN:
return new QValueImpl(Boolean.valueOf(value));
case PropertyType.DATE:
- return new QValueImpl(ISO8601.parse(value));
+ return new DateQValue(value);
case PropertyType.DOUBLE:
return new QValueImpl(Double.valueOf(value));
case PropertyType.LONG:
@@ -95,7 +95,7 @@
throw new IllegalArgumentException("Cannot create QValue from null value.");
}
// Calendar is not constant, must create a clone
- return new QValueImpl((Calendar) value.clone());
+ return new DateQValue((Calendar) value.clone());
}
/**
@@ -163,6 +163,11 @@
private final Object val;
private final int type;
+ private QValueImpl(Object value, int type) {
+ val = value;
+ this.type = type;
+ }
+
private QValueImpl(String value, int type) {
if (!(type == PropertyType.STRING || type == PropertyType.REFERENCE)) {
throw new IllegalArgumentException();
@@ -181,11 +186,6 @@
type = PropertyType.DOUBLE;
}
- private QValueImpl(Calendar value) {
- val = value;
- type = PropertyType.DATE;
- }
-
private QValueImpl(Boolean value) {
val = value;
type = PropertyType.BOOLEAN;
@@ -220,11 +220,7 @@
* @see QValue#getString()
*/
public String getString() throws RepositoryException {
- if (type == PropertyType.DATE) {
- return ISO8601.format((Calendar) val);
- } else {
- return val.toString();
- }
+ return val.toString();
}
/**
@@ -301,7 +297,7 @@
}
if (obj instanceof QValueImpl) {
QValueImpl other = (QValueImpl) obj;
- return val.equals(other.val) && type == other.type;
+ return type == other.type && val.equals(other.val);
}
return false;
}
@@ -313,11 +309,61 @@
public int hashCode() {
return val.hashCode();
}
+ }
+
+ //--------------------------------------------------------< Inner Class >---
+ /**
+ * Extension for values of type {@link PropertyType#DATE}.
+ */
+ private static class DateQValue extends QValueImpl {
- //---------------------------------------------------< Serializable >---
+ private final String formattedStr;
- }
+ private DateQValue(String value) {
+ super(ISO8601.parse(value), PropertyType.DATE);
+ formattedStr = value;
+ }
+
+ private DateQValue(Calendar value) {
+ super(value, PropertyType.DATE);
+ formattedStr = ISO8601.format(value);
+ }
+
+ /**
+ * @return The formatted String of the internal Calendar value.
+ * @throws RepositoryException
+ * @see QValue#getString()
+ * @see ISO8601#format(Calendar)
+ */
+ public String getString() throws RepositoryException {
+ return formattedStr;
+ }
+
+ /**
+ * @param obj
+ * @return true if the given Object is a <code>DateQValue</code> with an
+ * equal String representation.
+ * @see Object#equals(Object)
+ */
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof DateQValue) {
+ DateQValue other = (DateQValue) obj;
+ return formattedStr.equals(other.formattedStr);
+ }
+ return false;
+ }
+ /**
+ * @return the hashCode of the formatted String of the Calender value.
+ * @see Object#hashCode()
+ */
+ public int hashCode() {
+ return formattedStr.hashCode();
+ }
+ }
//--------------------------------------------------------< Inner Class >---
/**