commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r1301244 - in /commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/util: ApplyOptions.java BasicFilterFactory.java FilterFactory.java ThresholdingInputStream.java
Date Thu, 15 Mar 2012 22:16:23 GMT
Author: mbenson
Date: Thu Mar 15 22:16:23 2012
New Revision: 1301244

URL: http://svn.apache.org/viewvc?rev=1301244&view=rev
Log:
lang3 and simple cleanup

Modified:
    commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/util/ApplyOptions.java
    commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/util/BasicFilterFactory.java
    commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/util/FilterFactory.java
    commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/util/ThresholdingInputStream.java

Modified: commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/util/ApplyOptions.java
URL: http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/util/ApplyOptions.java?rev=1301244&r1=1301243&r2=1301244&view=diff
==============================================================================
--- commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/util/ApplyOptions.java
(original)
+++ commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/util/ApplyOptions.java
Thu Mar 15 22:16:23 2012
@@ -52,8 +52,8 @@ public abstract class ApplyOptions {
      * @param options option map
      * @return <code>o</code>.
      */
-    public static <T> T apply(T o, Map<String, ? extends Object> options) {
-        for (Map.Entry<String, ? extends Object> option : options.entrySet()) {
+    public static <T> T apply(T o, Map<String, ?> options) {
+        for (Map.Entry<String, ?> option : options.entrySet()) {
             apply(o, option.getKey(), option.getValue());
         }
         return o;

Modified: commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/util/BasicFilterFactory.java
URL: http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/util/BasicFilterFactory.java?rev=1301244&r1=1301243&r2=1301244&view=diff
==============================================================================
--- commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/util/BasicFilterFactory.java
(original)
+++ commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/util/BasicFilterFactory.java
Thu Mar 15 22:16:23 2012
@@ -19,42 +19,39 @@ package org.apache.commons.flatfile.util
 import java.io.InputStream;
 import java.lang.reflect.Constructor;
 
+import org.apache.commons.lang3.Validate;
+import org.apache.commons.lang3.reflect.ConstructorUtils;
+
 /**
  * Basic FilterFactory that creates an instance of a given InputStream subclass with a (InputStream)
constructor.
  * @version $Revision$ $Date$
  */
 public class BasicFilterFactory extends FilterFactory {
     private static final long serialVersionUID = 9080292216759574895L;
-    private static final Class<?>[] PARAMETER_TYPES = new Class[] { InputStream.class
};
-    private static final String HIERARCHY_ERROR = " does not inherit from "
-            + InputStream.class.getName();
 
-    private Constructor<? extends InputStream> constructor;
+    private final Constructor<? extends InputStream> constructor;
 
     /**
      * Create a new BasicFilterFactory instance.
-     * @param clazz (Filter)InputStream type to instantiate.
+     * @param type (Filter)InputStream type to instantiate.
      */
-    public BasicFilterFactory(Class<? extends InputStream> clazz) {
-        if (!InputStream.class.isAssignableFrom(clazz)) {
-            throw new IllegalArgumentException(clazz + HIERARCHY_ERROR);
-        }
-        try {
-            constructor = clazz.getConstructor(PARAMETER_TYPES);
-        } catch (Exception e) {
-            throw new IllegalArgumentException(clazz + ": " + e.toString());
-        }
+    public BasicFilterFactory(Class<? extends InputStream> type) {
+        Validate.isAssignableFrom(InputStream.class, type);
+        this.constructor =
+            Validate.notNull(ConstructorUtils.getAccessibleConstructor(type,
+                InputStream.class), String.format(
+                "Constructor %s(%s) not found", type.getName(),
+                InputStream.class.getName()));
     }
 
     /**
      * {@inheritDoc}
      */
     protected InputStream iGetFilter(InputStream markIsSupported) {
-        if (constructor == null) {
-            throw new IllegalStateException();
-        }
         try {
-            return constructor.newInstance(new Object[] { markIsSupported });
+            return constructor.newInstance(markIsSupported);
+        } catch (RuntimeException e) {
+            throw e;
         } catch (Exception e) {
             throw new RuntimeException(e);
         }

Modified: commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/util/FilterFactory.java
URL: http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/util/FilterFactory.java?rev=1301244&r1=1301243&r2=1301244&view=diff
==============================================================================
--- commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/util/FilterFactory.java
(original)
+++ commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/util/FilterFactory.java
Thu Mar 15 22:16:23 2012
@@ -20,8 +20,10 @@ import java.io.BufferedInputStream;
 import java.io.InputStream;
 import java.io.Serializable;
 
+import org.apache.commons.lang3.Validate;
+
 /**
- * Filter factory interface designed for use with {@link InputFilteringDynamicField}.
+ * Filter factory designed for use with {@link InputFilteringDynamicField}.
  * @version $Revision$ $Date$
  */
 public abstract class FilterFactory implements Serializable {
@@ -33,8 +35,9 @@ public abstract class FilterFactory impl
      * @param is the {@link InputStream} to filter
      * @return an {@link InputStream}
      */
-    public final InputStream getFilter(InputStream is) {
-        return iGetFilter(is.markSupported() ? is : new BufferedInputStream(is));
+    public final InputStream getFilter(final InputStream is) {
+        return iGetFilter(Validate.notNull(is).markSupported() ? is
+            : new BufferedInputStream(is));
     }
 
     /**

Modified: commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/util/ThresholdingInputStream.java
URL: http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/util/ThresholdingInputStream.java?rev=1301244&r1=1301243&r2=1301244&view=diff
==============================================================================
--- commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/util/ThresholdingInputStream.java
(original)
+++ commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/util/ThresholdingInputStream.java
Thu Mar 15 22:16:23 2012
@@ -28,7 +28,7 @@ import org.apache.commons.io.input.Count
 public class ThresholdingInputStream extends CountingInputStream {
     private static final int EOF = -1;
 
-    private int maximum;
+    private final int maximum;
     private boolean closed;
 
     /**



Mime
View raw message