You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mb...@apache.org on 2012/03/15 23:20:50 UTC

svn commit: r1301248 - in /commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile: DynamicField.java EntityArray.java EntityCollectionSupport.java EntityMap.java FieldSupport.java InputFilteringDynamicField.java

Author: mbenson
Date: Thu Mar 15 22:20:49 2012
New Revision: 1301248

URL: http://svn.apache.org/viewvc?rev=1301248&view=rev
Log:
lang3, remove some remaining com.pgac references + minor cleanup including final members

Modified:
    commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/DynamicField.java
    commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/EntityArray.java
    commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/EntityCollectionSupport.java
    commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/EntityMap.java
    commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/FieldSupport.java
    commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/InputFilteringDynamicField.java

Modified: commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/DynamicField.java
URL: http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/DynamicField.java?rev=1301248&r1=1301247&r2=1301248&view=diff
==============================================================================
--- commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/DynamicField.java (original)
+++ commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/DynamicField.java Thu Mar 15 22:20:49 2012
@@ -117,7 +117,7 @@ public class DynamicField extends PadJus
          * @param maximum int
          */
         public void setMaximum(int maximum) {
-            Validate.isTrue(maximum <= ALL_VALID.getMaximum(), "maximum value > "
+            Validate.isTrue(maximum <= ALL_VALID.getMaximum(), "maximum value > ",
                     + ALL_VALID.getMaximum(), maximum);
             this.maximum = maximum;
         }
@@ -335,8 +335,7 @@ public class DynamicField extends PadJus
      * @param bounds Bounds
      */
     public void setBounds(Bounds bounds) {
-        Validate.notNull(bounds, "bounds cannot be null");
-        this.bounds = bounds;
+        this.bounds = Validate.notNull(bounds, "bounds cannot be null");
     }
 
     /**

Modified: commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/EntityArray.java
URL: http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/EntityArray.java?rev=1301248&r1=1301247&r2=1301248&view=diff
==============================================================================
--- commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/EntityArray.java (original)
+++ commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/EntityArray.java Thu Mar 15 22:20:49 2012
@@ -29,6 +29,7 @@ import java.util.List;
 public class EntityArray extends EntityCollectionSupport implements
         IndexedEntityCollection {
     private static final long serialVersionUID = 8716199462287161060L;
+
     private int size = -1;
     private int minimumSize = 0;
     private int maximumSize = Integer.MAX_VALUE;
@@ -70,9 +71,7 @@ public class EntityArray extends EntityC
     }
 
     /**
-     * Get the child at the specified index.
-     * @param index to return
-     * @return Entity
+     * {@inheritDoc}
      */
     public Entity getChild(int index) {
         initialize();
@@ -126,16 +125,14 @@ public class EntityArray extends EntityC
     }
 
     /**
-     * Get the size (# of child elements) of this IndexedEntityCollection.
-     * @return int
+     * {@inheritDoc}
      */
     public synchronized int size() {
         return size;
     }
 
     /**
-     * Learn whether this EntityArray's size can be set.
-     * @return boolean
+     * {@inheritDoc}
      */
     public synchronized boolean isSizable() {
         return size == -1 || isResizable();

Modified: commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/EntityCollectionSupport.java
URL: http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/EntityCollectionSupport.java?rev=1301248&r1=1301247&r2=1301248&view=diff
==============================================================================
--- commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/EntityCollectionSupport.java (original)
+++ commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/EntityCollectionSupport.java Thu Mar 15 22:20:49 2012
@@ -68,9 +68,7 @@ public abstract class EntityCollectionSu
             }
             e.readFrom(is);
             if (it.hasNext() || isDelimAfter()) {
-                for (int i = 0; i < getDelim().length; i++) {
-                    is.read();
-                }
+                is.skip(getDelim().length);
             }
         }
     }

Modified: commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/EntityMap.java
URL: http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/EntityMap.java?rev=1301248&r1=1301247&r2=1301248&view=diff
==============================================================================
--- commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/EntityMap.java (original)
+++ commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/EntityMap.java Thu Mar 15 22:20:49 2012
@@ -30,6 +30,7 @@ import org.apache.commons.collections.Tr
 import org.apache.commons.collections.list.AbstractSerializableListDecorator;
 
 import org.apache.commons.lang3.ArrayUtils;
+import org.apache.commons.lang3.Validate;
 
 /**
  * Basic implementation of NamedEntityCollection.
@@ -39,7 +40,7 @@ public class EntityMap extends EntityCol
 
     private static final long serialVersionUID = 3162898927743996952L;
 
-    private class Child implements Serializable {
+    private static class Child implements Serializable {
 
         /** Serialization version */
         private static final long serialVersionUID = 2347729609002856564L;
@@ -65,6 +66,7 @@ public class EntityMap extends EntityCol
     /**
      * Expose the Child list as List<Entity>.
      */
+    // TODO switch to functor for full generics
     @SuppressWarnings("unchecked")
     private class ChildrenList extends AbstractSerializableListDecorator {
         private static final long serialVersionUID = 3241482030276238909L;
@@ -108,14 +110,13 @@ public class EntityMap extends EntityCol
 
     /**
      * Add a child.
-     * @param name if null filler element
+     * @param name if {@code null} filler element
      * @param child non-null child Entity
      */
     @SuppressWarnings("unchecked")
     public synchronized void add(String name, Entity child) {
-        if (child == null) {
-            throw new IllegalArgumentException("child entity is null");
-        }
+        Validate.notNull(child, "child entity is null");
+
         if (children == null) {
             children = new ArrayList<Child>();
             exposeChildrenList = new ChildrenList();
@@ -141,7 +142,6 @@ public class EntityMap extends EntityCol
 
     /**
      * {@inheritDoc}
-     * @see com.pgac.flatfile.NamedEntityCollection#getChildNames()
      */
     public synchronized String[] getChildNames() {
         return childMap == null ? ArrayUtils.EMPTY_STRING_ARRAY : childMap.keySet().toArray(
@@ -150,7 +150,6 @@ public class EntityMap extends EntityCol
 
     /**
      * {@inheritDoc}
-     * @see com.pgac.flatfile.NamedEntityCollection#getChild(java.lang.String)
      */
     public Entity getChild(String name) {
         return getChildMap().get(name);
@@ -158,7 +157,6 @@ public class EntityMap extends EntityCol
 
     /**
      * {@inheritDoc}
-     * @see com.pgac.flatfile.NamedEntityCollection#hasChild(java.lang.String)
      */
     public boolean hasChild(String name) {
         return getChildMap().containsKey(name);
@@ -166,7 +164,6 @@ public class EntityMap extends EntityCol
 
     /**
      * {@inheritDoc}
-     * @see com.pgac.flatfile.EntityCollection#getChildren()
      */
     public synchronized Collection<Entity> getChildren() {
         return children == null ? Collections.<Entity> emptyList() : Collections
@@ -175,7 +172,6 @@ public class EntityMap extends EntityCol
 
     /**
      * {@inheritDoc}
-     * @see com.pgac.flatfile.EntitySupport#clone()
      */
     public synchronized EntityMap clone() {
         EntityMap result = (EntityMap) super.clone();

Modified: commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/FieldSupport.java
URL: http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/FieldSupport.java?rev=1301248&r1=1301247&r2=1301248&view=diff
==============================================================================
--- commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/FieldSupport.java (original)
+++ commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/FieldSupport.java Thu Mar 15 22:20:49 2012
@@ -19,6 +19,8 @@ package org.apache.commons.flatfile;
 import java.io.IOException;
 import java.io.InputStream;
 
+import org.apache.commons.lang3.Validate;
+
 /**
  * Support and basic field options.
  * @version $Revision$ $Date$
@@ -38,10 +40,8 @@ public abstract class FieldSupport exten
              * {@inheritDoc}
              */
             protected void check(byte[] b, int len) {
-                if (b.length > len) {
-                    throw new IllegalArgumentException(new String(b) + " too large for field ("
-                            + len + ")");
-                }
+                Validate.isTrue(b.length <= len,
+                    "Value '%s' too large for field (%s)", new String(b), len);
             }
         },
 
@@ -70,10 +70,8 @@ public abstract class FieldSupport exten
              * {@inheritDoc}
              */
             protected void check(byte[] b, int len) {
-                if (b.length < len) {
-                    throw new IllegalArgumentException(new String(b) + " too small for field ("
-                            + len + ")");
-                }
+                Validate.isTrue(b.length >= len,
+                    "Value '%s' too small for field (%s)", new String(b), len);
             }
         },
 

Modified: commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/InputFilteringDynamicField.java
URL: http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/InputFilteringDynamicField.java?rev=1301248&r1=1301247&r2=1301248&view=diff
==============================================================================
--- commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/InputFilteringDynamicField.java (original)
+++ commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/InputFilteringDynamicField.java Thu Mar 15 22:20:49 2012
@@ -20,6 +20,7 @@ import java.io.IOException;
 import java.io.InputStream;
 
 import org.apache.commons.flatfile.util.FilterFactory;
+import org.apache.commons.lang3.Validate;
 
 /**
  * Dynamic field with filtered input. This allows a user to set up a means by which an Entity containing a nested
@@ -71,14 +72,11 @@ public class InputFilteringDynamicField 
      * {@inheritDoc}
      */
     public synchronized void readFrom(InputStream is) throws IOException {
-        if (filterFactory == null) {
-            throw new IllegalStateException("filterFactory has not been set");
-        }
-        InputStream filter = filterFactory.getFilter(is);
-        if (filter == null) {
-            throw new IllegalArgumentException("Filter factory "
-                    + filterFactory + " cannot filter " + is);
-        }
+        Validate.validState(filterFactory != null, "filterFactory has not been set");
+        final InputStream filter = filterFactory.getFilter(is);
+
+        Validate.validState(filter != null,
+            "Filter factory %s cannot filter %s", filterFactory, is);
         super.readFrom(filter);
     }