commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brit...@apache.org
Subject svn commit: r1713245 - in /commons/sandbox/beanutils2/trunk/src: changes/ main/java/org/apache/commons/beanutils2/ test/java/org/apache/commons/beanutils2/
Date Sun, 08 Nov 2015 16:32:47 GMT
Author: britter
Date: Sun Nov  8 16:32:47 2015
New Revision: 1713245

URL: http://svn.apache.org/viewvc?rev=1713245&view=rev
Log:
SANDBOX-506: Use 'Converter' instead of 'Transformer'

Added:
    commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/ConversionException.java
      - copied, changed from r1713238, commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/TransformationException.java
    commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/ConverterRegistry.java
      - copied, changed from r1713244, commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/TransformerRegistry.java
    commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/ConverterRegistryTestCase.java
      - copied, changed from r1713244, commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/TransformerRegistryTestCase.java
Removed:
    commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/TransformationException.java
    commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/TransformerRegistry.java
    commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/TransformerRegistryTestCase.java
Modified:
    commons/sandbox/beanutils2/trunk/src/changes/changes.xml

Modified: commons/sandbox/beanutils2/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/sandbox/beanutils2/trunk/src/changes/changes.xml?rev=1713245&r1=1713244&r2=1713245&view=diff
==============================================================================
--- commons/sandbox/beanutils2/trunk/src/changes/changes.xml (original)
+++ commons/sandbox/beanutils2/trunk/src/changes/changes.xml Sun Nov  8 16:32:47 2015
@@ -23,6 +23,9 @@
   </properties>
   <body>
   <release version="2.0" date="TBA" description="Redesign of beanutils with a fluent API">
+    <action dev="britter" type="update" issue="SANDBOX-506">
+      Use 'Converter' instead of 'Transformer'
+    </action>
     <action dev="britter" type="remove" issue="SANDBOX-501">
       Remove Transformer&lt;S, T&gt; in favor of java.util.function.Function&lt;S,
T&gt;
     </action>

Copied: commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/ConversionException.java
(from r1713238, commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/TransformationException.java)
URL: http://svn.apache.org/viewvc/commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/ConversionException.java?p2=commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/ConversionException.java&p1=commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/TransformationException.java&r1=1713238&r2=1713245&rev=1713245&view=diff
==============================================================================
--- commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/TransformationException.java
(original)
+++ commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/ConversionException.java
Sun Nov  8 16:32:47 2015
@@ -19,7 +19,7 @@
 
 package org.apache.commons.beanutils2;
 
-public class TransformationException extends RuntimeException {
+public class ConversionException extends RuntimeException {
 
 
     /**
@@ -33,7 +33,7 @@ public class TransformationException ext
      * @param message
      *            The message describing this exception
      */
-    public TransformationException(String message) {
+    public ConversionException(String message) {
         super(message);
     }
 
@@ -45,7 +45,7 @@ public class TransformationException ext
      * @param cause
      *            The root cause of this exception
      */
-    public TransformationException(String message, Throwable cause) {
+    public ConversionException(String message, Throwable cause) {
         super(message, cause);
     }
 }

Copied: commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/ConverterRegistry.java
(from r1713244, commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/TransformerRegistry.java)
URL: http://svn.apache.org/viewvc/commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/ConverterRegistry.java?p2=commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/ConverterRegistry.java&p1=commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/TransformerRegistry.java&r1=1713244&r2=1713245&rev=1713245&view=diff
==============================================================================
--- commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/TransformerRegistry.java
(original)
+++ commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/ConverterRegistry.java
Sun Nov  8 16:32:47 2015
@@ -18,45 +18,41 @@
  */
 package org.apache.commons.beanutils2;
 
-import static org.apache.commons.beanutils2.Assertions.checkArgument;
 import static org.apache.commons.beanutils2.Assertions.checkNotNull;
 
 import java.lang.reflect.Type;
-import java.util.Collection;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.function.Function;
 
 /**
  * <p>
- * Container class for holding all the Transformer's which would be used for
- * transformation. This class also provides utility methods for register
- * /deregister transformers and also methods to find/lookup a specific
- * transformer.
+ * Container class for holding all the converters used for automatic type conversion. This
class also provides utility
+ * methods for register/deregister converters and also methods to find/lookup a specific
converter.
  * </p>
  * 
  * <p>
  * This class is currently not thread-safe.
  * </p>
  */
-public class TransformerRegistry {
+public class ConverterRegistry {
 
     /**
-     * Registry to hold all the transformers
+     * Registry to hold all the converters
      */
-    private Map<TransformerMapKey, Function<?, ?>> transformers = null;
+    private Map<ConverterMapKey, Function<?, ?>> converters = null;
 
     /**
      * <p>
-     * Class to be used as internal key for the map holding transformers
+     * Class to be used as internal key for the map holding converters
      * </p>
      * 
      */
-    private static class TransformerMapKey {
+    private static class ConverterMapKey {
         private Type source = null;
         private Type target = null;
 
-        private TransformerMapKey(Type sourceType, Type targetType) {
+        private ConverterMapKey(Type sourceType, Type targetType) {
             source = checkNotNull(sourceType, "Source type must not be null!");
             target = checkNotNull(targetType, "Target type must not be null!");
         }
@@ -93,7 +89,7 @@ public class TransformerRegistry {
                 return false;
             }
 
-            TransformerMapKey paramKey = (TransformerMapKey) obj;
+            ConverterMapKey paramKey = (ConverterMapKey) obj;
 
             return paramKey.getSource() == this.getSource() && paramKey
                     .getTarget() == this.getTarget();
@@ -106,26 +102,26 @@ public class TransformerRegistry {
         }
     }
 
-    public TransformerRegistry() {
-        transformers = new HashMap<>();
+    public ConverterRegistry() {
+        converters = new HashMap<>();
     }
 
     /**
-     * Registers the transformer with the registry
+     * Registers the converter with the registry
      * 
-     * @param transformer
+     * @param converter
      *            instance of the Transformer implementation
      */
-    public <S, T> void register(Class<S> sourceClass, Class<T> targetClass,
Function<S, T> transformer) {
-        checkNotNull(transformer, "Transformer must not be null!");
+    public <S, T> void register(Class<S> sourceClass, Class<T> targetClass,
Function<S, T> converter) {
+        checkNotNull(converter, "Converter must not be null!");
         // TODO if transformer is already registered overwrite ?? or do not
         // allow overwriting
-        transformers.put(new TransformerMapKey(sourceClass,
-                targetClass), transformer);
+        converters.put(new ConverterMapKey(sourceClass,
+                targetClass), converter);
     }
 
     /**
-     * Deregister's or removes a transformer from the registry
+     * Deregister's or removes a converter from the registry
      * 
      * @param sourceClass
      *            Type implementation defining source
@@ -135,8 +131,8 @@ public class TransformerRegistry {
      *         otherwise
      */
     public <S, T> boolean deregister(Class<S> sourceClass, Class<T> targetClass)
{
-        Function<?, ?> previousValue = transformers
-                .remove(new TransformerMapKey(sourceClass, targetClass));
+        Function<?, ?> previousValue = converters
+                .remove(new ConverterMapKey(sourceClass, targetClass));
         boolean returnVal = true;
 
         if (previousValue == null) {
@@ -146,31 +142,31 @@ public class TransformerRegistry {
     }
 
     /**
-     * Deregister's / removes all the transformers from the registry.
+     * Deregister's / removes all the converters from the registry.
      */
     public void deregisterAll() {
-        transformers.clear();
+        converters.clear();
     }
 
     /**
-     * Method to find the instance of transformer to be used for converting from
+     * Method to find the instance of converter to be used for converting from
      * source to target type.
      * 
      * @param sourceType
      *            Class instance defining source
      * @param targetType
      *            Class instance defining target
-     * @return instance of Transformer Implementation if found or null otherwise
+     * @return instance of converter Implementation if found or null otherwise
      */
     @SuppressWarnings("unchecked")
     public <S, T> Function<S, T> lookup(Class<S> sourceType,
             Class<T> targetType) {
-        TransformerMapKey key = new TransformerMapKey(sourceType, targetType);
+        ConverterMapKey key = new ConverterMapKey(sourceType, targetType);
 
-        if (transformers.containsKey(key)) {
-            return (Function<S, T>) transformers.get(key);
+        if (converters.containsKey(key)) {
+            return (Function<S, T>) converters.get(key);
         } else {
-            throw new TransformationException(String.format("Unable to transform from %s
to %s.",
+            throw new ConversionException(String.format("Unable to convert from %s to %s.",
                     sourceType.getName(), targetType.getName()));
         }
     }

Copied: commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/ConverterRegistryTestCase.java
(from r1713244, commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/TransformerRegistryTestCase.java)
URL: http://svn.apache.org/viewvc/commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/ConverterRegistryTestCase.java?p2=commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/ConverterRegistryTestCase.java&p1=commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/TransformerRegistryTestCase.java&r1=1713244&r2=1713245&rev=1713245&view=diff
==============================================================================
--- commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/TransformerRegistryTestCase.java
(original)
+++ commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/ConverterRegistryTestCase.java
Sun Nov  8 16:32:47 2015
@@ -25,15 +25,15 @@ import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 
-public class TransformerRegistryTestCase {
+public class ConverterRegistryTestCase {
 
     Function<String, Integer> transformerStringIntegerImpl = Integer::parseInt;
     Function<String, Float> transformerStringFloatImpl = Float::parseFloat;
-    TransformerRegistry registry = null;
+    ConverterRegistry registry = null;
 
     @Before
     public void setUp() throws Exception {
-        registry = new TransformerRegistry();
+        registry = new ConverterRegistry();
         registry.register(String.class, Integer.class, transformerStringIntegerImpl);
         registry.register(String.class, Float.class, transformerStringFloatImpl);
     }
@@ -67,7 +67,7 @@ public class TransformerRegistryTestCase
         registry.lookup(null, String.class);
     }
 
-    @Test(expected = TransformationException.class)
+    @Test(expected = ConversionException.class)
     public void testLookupThrowsExceptionIfNoTransformerFound() throws Exception {
         registry.lookup(Date.class, String.class);
     }
@@ -75,7 +75,7 @@ public class TransformerRegistryTestCase
     /**
      * Tests for the deregister() method in TransformerRegistry
      */
-    @Test(expected = TransformationException.class)
+    @Test(expected = ConversionException.class)
     public void testDeregister() {
         registry.deregister(String.class, Integer.class);
 
@@ -100,7 +100,7 @@ public class TransformerRegistryTestCase
     /**
      * Tests for the deregisterAll() method in TransformerRegistry
      */
-    @Test(expected = TransformationException.class)
+    @Test(expected = ConversionException.class)
     public void testDeregisterAll() {
         registry.deregisterAll();
 



Mime
View raw message