commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adri...@apache.org
Subject svn commit: r928215 - in /commons/sandbox/convert/trunk/src/main/java/org/apache/commons/convert: Converters.java DateTimeConverters.java
Date Sat, 27 Mar 2010 15:12:30 GMT
Author: adrianc
Date: Sat Mar 27 15:12:30 2010
New Revision: 928215

URL: http://svn.apache.org/viewvc?rev=928215&view=rev
Log:
Improved the converters that convert one subclass of java.util.Date to another subclass of
java.util.Date - eliminating the need for the converters that threw exceptions for conversions
that are not allowed (which was a kludge).

Modified:
    commons/sandbox/convert/trunk/src/main/java/org/apache/commons/convert/Converters.java
    commons/sandbox/convert/trunk/src/main/java/org/apache/commons/convert/DateTimeConverters.java

Modified: commons/sandbox/convert/trunk/src/main/java/org/apache/commons/convert/Converters.java
URL: http://svn.apache.org/viewvc/commons/sandbox/convert/trunk/src/main/java/org/apache/commons/convert/Converters.java?rev=928215&r1=928214&r2=928215&view=diff
==============================================================================
--- commons/sandbox/convert/trunk/src/main/java/org/apache/commons/convert/Converters.java
(original)
+++ commons/sandbox/convert/trunk/src/main/java/org/apache/commons/convert/Converters.java
Sat Mar 27 15:12:30 2010
@@ -62,6 +62,7 @@ public class Converters {
 
     private Converters() {}
 
+
     /** Returns an appropriate <code>Converter</code> instance for
      * <code>sourceClass</code> and <code>targetClass</code>. If
no matching
      * <code>Converter</code> is found, the method throws

Modified: commons/sandbox/convert/trunk/src/main/java/org/apache/commons/convert/DateTimeConverters.java
URL: http://svn.apache.org/viewvc/commons/sandbox/convert/trunk/src/main/java/org/apache/commons/convert/DateTimeConverters.java?rev=928215&r1=928214&r2=928215&view=diff
==============================================================================
--- commons/sandbox/convert/trunk/src/main/java/org/apache/commons/convert/DateTimeConverters.java
(original)
+++ commons/sandbox/convert/trunk/src/main/java/org/apache/commons/convert/DateTimeConverters.java
Sat Mar 27 15:12:30 2010
@@ -127,6 +127,11 @@ public class DateTimeConverters implemen
             super(Date.class, java.sql.Date.class);
         }
 
+        @Override
+        public boolean canConvert(Class<?> sourceClass, Class<?> targetClass)
{
+            return (java.util.Date.class.equals(sourceClass) || java.sql.Timestamp.class.equals(sourceClass))
&& java.sql.Date.class.equals(targetClass);
+        }
+
         public java.sql.Date convert(Date obj) throws ConversionException {
             return new java.sql.Date(obj.getTime());
         }
@@ -153,6 +158,11 @@ public class DateTimeConverters implemen
             super(Date.class, java.sql.Timestamp.class);
         }
 
+        @Override
+        public boolean canConvert(Class<?> sourceClass, Class<?> targetClass)
{
+            return (java.util.Date.class.equals(sourceClass) || java.sql.Timestamp.class.equals(sourceClass))
&& java.sql.Timestamp.class.equals(targetClass);
+        }
+
         public java.sql.Timestamp convert(Date obj) throws ConversionException {
             return new java.sql.Timestamp(obj.getTime());
         }
@@ -239,6 +249,11 @@ public class DateTimeConverters implemen
             super(java.sql.Date.class, Date.class);
         }
 
+        @Override
+        public boolean canConvert(Class<?> sourceClass, Class<?> targetClass)
{
+            return java.sql.Date.class.equals(sourceClass) && java.util.Date.class.equals(targetClass);
+        }
+
         public Date convert(java.sql.Date obj) throws ConversionException {
             return new Date(obj.getTime());
         }
@@ -282,21 +297,16 @@ public class DateTimeConverters implemen
         }
     }
 
-    public static class SqlDateToTime extends AbstractConverter<java.sql.Date, java.sql.Time>
{
-        public SqlDateToTime() {
-            super(java.sql.Date.class, java.sql.Time.class);
-        }
-
-        public java.sql.Time convert(java.sql.Date obj) throws ConversionException {
-            throw new ConversionException("Conversion from Date to Time not supported");
-       }
-    }
-
     public static class SqlDateToTimestamp extends AbstractConverter<java.sql.Date, java.sql.Timestamp>
{
         public SqlDateToTimestamp() {
             super(java.sql.Date.class, java.sql.Timestamp.class);
         }
 
+        @Override
+        public boolean canConvert(Class<?> sourceClass, Class<?> targetClass)
{
+            return java.sql.Date.class.equals(sourceClass) && java.sql.Timestamp.class.equals(targetClass);
+        }
+
         public java.sql.Timestamp convert(java.sql.Date obj) throws ConversionException {
             return new java.sql.Timestamp(obj.getTime());
        }
@@ -324,16 +334,6 @@ public class DateTimeConverters implemen
         }
     }
 
-    public static class SqlTimeToSqlDate extends AbstractConverter<java.sql.Time, java.sql.Date>
{
-        public SqlTimeToSqlDate() {
-            super(java.sql.Time.class, java.sql.Date.class);
-        }
-
-        public java.sql.Date convert(java.sql.Time obj) throws ConversionException {
-            throw new ConversionException("Conversion from Time to Date not supported");
-        }
-    }
-
     public static class SqlTimeToString extends GenericLocalizedConverter<java.sql.Time,
String> {
         public SqlTimeToString() {
             super(java.sql.Time.class, String.class);
@@ -476,6 +476,11 @@ public class DateTimeConverters implemen
             super(java.sql.Timestamp.class, Date.class);
         }
 
+        @Override
+        public boolean canConvert(Class<?> sourceClass, Class<?> targetClass)
{
+            return java.sql.Timestamp.class.equals(sourceClass) && java.util.Date.class.equals(targetClass);
+        }
+
         public Date convert(java.sql.Timestamp obj) throws ConversionException {
             return new Timestamp(obj.getTime());
         }
@@ -508,6 +513,11 @@ public class DateTimeConverters implemen
             super(Timestamp.class, java.sql.Date.class);
         }
 
+        @Override
+        public boolean canConvert(Class<?> sourceClass, Class<?> targetClass)
{
+            return java.sql.Timestamp.class.equals(sourceClass) && java.sql.Date.class.equals(targetClass);
+        }
+
         public java.sql.Date convert(Timestamp obj) throws ConversionException {
             return new java.sql.Date(obj.getTime());
         }



Mime
View raw message