You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by br...@apache.org on 2014/08/25 18:00:26 UTC

svn commit: r1620360 - /commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/TransformerRegistry.java

Author: britter
Date: Mon Aug 25 16:00:26 2014
New Revision: 1620360

URL: http://svn.apache.org/r1620360
Log:
Use Assertions class to check arguments to make behavior consistent throughout the library.

Modified:
    commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/TransformerRegistry.java

Modified: 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/TransformerRegistry.java?rev=1620360&r1=1620359&r2=1620360&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/TransformerRegistry.java Mon Aug 25 16:00:26 2014
@@ -18,6 +18,9 @@
  */
 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;
@@ -53,16 +56,8 @@ public class TransformerRegistry {
         private Type target = null;
 
         private TransformerMapKey(Type sourceType, Type targetType) {
-            if (sourceType == null) {
-                throw new IllegalArgumentException("sourceType is missing");
-            }
-
-            if (targetType == null) {
-                throw new IllegalArgumentException("targetType is missing");
-            }
-
-            this.source = sourceType;
-            this.target = targetType;
+            source = checkNotNull(sourceType, "Source type must not be null!");
+            target = checkNotNull(targetType, "Target type must not be null!");
         }
 
         /**
@@ -121,9 +116,7 @@ public class TransformerRegistry {
      *            instance of the Transformer implementation
      */
     public <S, T> void register(Transformer<S, T> transformer) {
-        if (transformer == null) {
-            throw new IllegalArgumentException("Transformer is missing");
-        }
+        checkNotNull(transformer, "Transformer must not be null!");
         // TODO if transformer is already registered overwrite ?? or do not
         // allow overwriting
         transformers.put(new TransformerMapKey(transformer.getSourceType(),
@@ -139,9 +132,9 @@ public class TransformerRegistry {
      */
     public void registerAll(
             Collection<Transformer<? extends Object, ? extends Object>> transformerList) {
-        if (transformerList == null || transformerList.isEmpty()) {
-            throw new IllegalArgumentException("Transformer list is missing");
-        }
+        checkNotNull(transformerList, "Transformer list must not be null!");
+        checkArgument(!transformerList.isEmpty(), "Transformer list must not be empty!");
+
         // TODO if transformer is already registered overwrite ?? or do not
         // allow overwriting
         for (Transformer<? extends Object, ? extends Object> transformer : transformerList) {
@@ -158,9 +151,7 @@ public class TransformerRegistry {
      *         otherwise
      */
     public <S, T> boolean deregister(Transformer<S, T> transformer) {
-        if (transformer == null) {
-            throw new IllegalArgumentException("Transformer is missing");
-        }
+        checkNotNull(transformer, "Transformer must not be null!");
 
         return deregister(transformer.getSourceType(),
                 transformer.getTargetType());