svn commit: r835453 - in /ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion: AbstractCollectionConverter.java AbstractConverter.java CollectionConverters.java NumberConverters.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r835453 - in /ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion: AbstractCollectionConverter.java AbstractConverter.java CollectionConverters.java NumberConverters.java

doogie-3
Author: doogie
Date: Thu Nov 12 17:15:01 2009
New Revision: 835453

URL: http://svn.apache.org/viewvc?rev=835453&view=rev
Log:
Simplied the object graph, removed AbstractCollectionConverter.  All
collection conversions now have proper generification.

Removed:
    ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/AbstractCollectionConverter.java
Modified:
    ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/AbstractConverter.java
    ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/CollectionConverters.java
    ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/NumberConverters.java

Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/AbstractConverter.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/AbstractConverter.java?rev=835453&r1=835452&r2=835453&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/AbstractConverter.java (original)
+++ ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/AbstractConverter.java Thu Nov 12 17:15:01 2009
@@ -24,10 +24,10 @@
  * and it implements the <code>canConvert</code> method.
  */
 public abstract class AbstractConverter<S, T> implements Converter<S, T> {
-    private final Class<S> sourceClass;
-    private final Class<T> targetClass;
+    private final Class<? super S> sourceClass;
+    private final Class<? super T> targetClass;
 
-    protected AbstractConverter(Class<S> sourceClass, Class<T> targetClass) {
+    protected AbstractConverter(Class<? super S> sourceClass, Class<? super T> targetClass) {
         this.sourceClass = sourceClass;
         this.targetClass = targetClass;
         Converters.registerConverter(this);
@@ -37,11 +37,11 @@
         return ObjectType.instanceOf(sourceClass, this.getSourceClass()) && ObjectType.instanceOf(targetClass, this.getTargetClass());
     }
 
-    public final Class<S> getSourceClass() {
+    public final Class<? super S> getSourceClass() {
         return sourceClass;
     }
 
-    public final Class<T> getTargetClass() {
+    public final Class<? super T> getTargetClass() {
         return targetClass;
     }
 }

Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/CollectionConverters.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/CollectionConverters.java?rev=835453&r1=835452&r2=835453&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/CollectionConverters.java (original)
+++ ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/CollectionConverters.java Thu Nov 12 17:15:01 2009
@@ -32,7 +32,7 @@
 
 /** Collection Converter classes. */
 public class CollectionConverters implements ConverterLoader {
-    public static class ArrayToList extends AbstractConverter<Object[], List> {
+    public static class ArrayToList<T> extends AbstractConverter<T[], List<T>> {
         public ArrayToList() {
             super(Object[].class, List.class);
         }
@@ -42,56 +42,56 @@
             return sourceClass.isArray() && ObjectType.instanceOf(targetClass, this.getTargetClass());
         }
 
-        public List<?> convert(Object[] obj) throws ConversionException {
+        public List<T> convert(T[] obj) throws ConversionException {
             return Arrays.asList(obj);
         }
     }
 
-    public static class ListToString extends AbstractConverter<List, String> {
+    public static class ListToString<T> extends AbstractConverter<List<T>, String> {
         public ListToString() {
             super(List.class, String.class);
         }
 
-        public String convert(List obj) throws ConversionException {
+        public String convert(List<T> obj) throws ConversionException {
             return obj.toString();
         }
     }
 
-    public static class MapToList extends AbstractCollectionConverter<Map, List<Map>> {
+    public static class MapToList<K, V> extends AbstractConverter<Map<K, V>, List<Map<K, V>>> {
         public MapToList() {
             super(Map.class, List.class);
         }
 
-        public List<Map> convert(Map obj) throws ConversionException {
-            List<Map> tempList = FastList.newInstance();
+        public List<Map<K, V>> convert(Map<K, V> obj) throws ConversionException {
+            List<Map<K, V>> tempList = FastList.newInstance();
             tempList.add(obj);
             return tempList;
         }
     }
 
-    public static class MapToSet extends AbstractCollectionConverter<Map, Set<Map>> {
+    public static class MapToSet<K, V> extends AbstractConverter<Map<K, V>, Set<Map<K, V>>> {
         public MapToSet() {
             super(Map.class, Set.class);
         }
 
-        public Set<Map> convert(Map obj) throws ConversionException {
-            Set<Map> tempSet = FastSet.newInstance();
+        public Set<Map<K, V>> convert(Map<K, V> obj) throws ConversionException {
+            Set<Map<K, V>> tempSet = FastSet.newInstance();
             tempSet.add(obj);
             return tempSet;
         }
     }
 
-    public static class MapToString extends AbstractConverter<Map, String> {
+    public static class MapToString<K, V> extends AbstractConverter<Map<K, V>, String> {
         public MapToString() {
             super(Map.class, String.class);
         }
 
-        public String convert(Map obj) throws ConversionException {
+        public String convert(Map<K, V> obj) throws ConversionException {
             return obj.toString();
         }
     }
 
-    public static class StringToList extends AbstractCollectionConverter<String, List<String>> {
+    public static class StringToList extends AbstractConverter<String, List<String>> {
         public StringToList() {
             super(String.class, List.class);
         }
@@ -107,12 +107,12 @@
         }
     }
 
-    public static class StringToMap extends AbstractConverter<String, Map> {
+    public static class StringToMap extends AbstractConverter<String, Map<String, String>> {
         public StringToMap() {
             super(String.class, Map.class);
         }
 
-        public Map convert(String obj) throws ConversionException {
+        public Map<String, String> convert(String obj) throws ConversionException {
             if (obj.startsWith("{") && obj.endsWith("}")) {
                 return StringUtil.toMap(obj);
             }
@@ -120,7 +120,7 @@
         }
     }
 
-    public static class StringToSet extends AbstractCollectionConverter<String, Set<String>> {
+    public static class StringToSet extends AbstractConverter<String, Set<String>> {
         public StringToSet() {
             super(String.class, Set.class);
         }

Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/NumberConverters.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/NumberConverters.java?rev=835453&r1=835452&r2=835453&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/NumberConverters.java (original)
+++ ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/NumberConverters.java Thu Nov 12 17:15:01 2009
@@ -94,7 +94,7 @@
         }
     }
 
-    public static class BigDecimalToList extends AbstractCollectionConverter<BigDecimal, List<BigDecimal>> {
+    public static class BigDecimalToList extends AbstractConverter<BigDecimal, List<BigDecimal>> {
         public BigDecimalToList() {
             super(BigDecimal.class, List.class);
         }
@@ -116,7 +116,7 @@
         }
     }
 
-    public static class BigDecimalToSet extends AbstractCollectionConverter<BigDecimal, Set<BigDecimal>> {
+    public static class BigDecimalToSet extends AbstractConverter<BigDecimal, Set<BigDecimal>> {
         public BigDecimalToSet() {
             super(BigDecimal.class, Set.class);
         }
@@ -169,7 +169,7 @@
         }
     }
 
-    public static class DoubleToList extends AbstractCollectionConverter<Double, List<Double>> {
+    public static class DoubleToList extends AbstractConverter<Double, List<Double>> {
         public DoubleToList() {
             super(Double.class, List.class);
         }
@@ -191,7 +191,7 @@
         }
     }
 
-    public static class DoubleToSet extends AbstractCollectionConverter<Double, Set<Double>> {
+    public static class DoubleToSet extends AbstractConverter<Double, Set<Double>> {
         public DoubleToSet() {
             super(Double.class, Set.class);
         }
@@ -244,7 +244,7 @@
         }
     }
 
-    public static class FloatToList extends AbstractCollectionConverter<Float, List<Float>> {
+    public static class FloatToList extends AbstractConverter<Float, List<Float>> {
         public FloatToList() {
             super(Float.class, List.class);
         }
@@ -266,7 +266,7 @@
         }
     }
 
-    public static class FloatToSet extends AbstractCollectionConverter<Float, Set<Float>> {
+    public static class FloatToSet extends AbstractConverter<Float, Set<Float>> {
         public FloatToSet() {
             super(Float.class, Set.class);
         }
@@ -319,7 +319,7 @@
         }
     }
 
-    public static class IntegerToList extends AbstractCollectionConverter<Integer, List<Integer>> {
+    public static class IntegerToList extends AbstractConverter<Integer, List<Integer>> {
         public IntegerToList() {
             super(Integer.class, List.class);
         }
@@ -341,7 +341,7 @@
         }
     }
 
-    public static class IntegerToSet extends AbstractCollectionConverter<Integer, Set<Integer>> {
+    public static class IntegerToSet extends AbstractConverter<Integer, Set<Integer>> {
         public IntegerToSet() {
             super(Integer.class, Set.class);
         }
@@ -404,7 +404,7 @@
         }
     }
 
-    public static class LongToList extends AbstractCollectionConverter<Long, List<Long>> {
+    public static class LongToList extends AbstractConverter<Long, List<Long>> {
         public LongToList() {
             super(Long.class, List.class);
         }
@@ -416,7 +416,7 @@
         }
     }
 
-    public static class LongToSet extends AbstractCollectionConverter<Long, Set<Long>> {
+    public static class LongToSet extends AbstractConverter<Long, Set<Long>> {
         public LongToSet() {
             super(Long.class, Set.class);
         }