[portal-commits] JBoss Portal SVN: r5773 - trunk/core/src/main/org/jboss/portal/core/model/portal

portal-commits at lists.jboss.org portal-commits at lists.jboss.org
Fri Dec 8 21:41:28 EST 2006


Author: chris.laprun at jboss.com
Date: 2006-12-08 21:41:26 -0500 (Fri, 08 Dec 2006)
New Revision: 5773

Modified:
   trunk/core/src/main/org/jboss/portal/core/model/portal/PortalObjectId.java
Log:
- PortalObjectId(String, Format) now checks that given format is not null.
- Now uses ParameterValidation where it makes sense to do so.

Modified: trunk/core/src/main/org/jboss/portal/core/model/portal/PortalObjectId.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/model/portal/PortalObjectId.java	2006-12-08 20:07:12 UTC (rev 5772)
+++ trunk/core/src/main/org/jboss/portal/core/model/portal/PortalObjectId.java	2006-12-09 02:41:26 UTC (rev 5773)
@@ -22,8 +22,9 @@
  ******************************************************************************/
 package org.jboss.portal.core.model.portal;
 
-import org.jboss.portal.common.util.Tools;
 import org.jboss.portal.common.NotYetImplemented;
+import org.jboss.portal.common.util.ParameterValidation;
+import org.jboss.portal.common.util.Tools;
 
 import java.util.Iterator;
 
@@ -50,10 +51,7 @@
     */
    public PortalObjectId(PortalObjectId that) throws IllegalArgumentException
    {
-      if (that == null)
-      {
-         throw new IllegalArgumentException();
-      }
+      ParameterValidation.throwIllegalArgExceptionIfNull(that, "PortalObjectId to be copied");
       this.names = that.names;
       this.hashCode = that.hashCode;
    }
@@ -66,22 +64,20 @@
     */
    public PortalObjectId(String[] names) throws IllegalArgumentException
    {
-      if (names == null)
-      {
-         throw new IllegalArgumentException();
-      }
+      ParameterValidation.throwIllegalArgExceptionIfNull(names, "composing names");
       this.names = names;
    }
 
    /**
     * Build an id by parsing a string representation.
     *
-    * @param value the string representation
+    * @param value  the string representation
     * @param format the string format
     * @throws IllegalArgumentException if any argument is null or not well formed
     */
    public PortalObjectId(String value, Format format) throws IllegalArgumentException
    {
+      ParameterValidation.throwIllegalArgExceptionIfNull(format, "Format");
       this.names = format.parse(value);
    }
 
@@ -104,9 +100,9 @@
          }
 
          //
-         for (int i = thisNames.length - 1;i >= 0;i--)
+         for (int i = thisNames.length - 1; i >= 0; i--)
          {
-            if (thisNames[i].equals(thatNames[i]) == false)
+            if (!thisNames[i].equals(thatNames[i]))
             {
                return false;
             }
@@ -123,7 +119,7 @@
       if (hashCode == null)
       {
          int value = 0;
-         for (int i = names.length - 1;i >= 0;i--)
+         for (int i = names.length - 1; i >= 0; i--)
          {
             value = value * 41 + names[i].hashCode();
          }
@@ -147,9 +143,7 @@
       return Tools.iterator(names);
    }
 
-   /**
-    * Returns the canonical representation of the id.
-    */
+   /** Returns the canonical representation of the id. */
    public String toString()
    {
       return CANONICAL_FORMAT.toString(names);
@@ -163,10 +157,7 @@
     */
    public String toString(Format format)
    {
-      if (format == null)
-      {
-         throw new IllegalArgumentException();
-      }
+      ParameterValidation.throwIllegalArgExceptionIfNull(format, "Format");
       return format.toString(names);
    }
 
@@ -175,53 +166,40 @@
       return new PortalObjectId(value, format);
    }
 
-   /**
-    * The format of a string representation of an id.
-    */
+   /** The format of a string representation of an id. */
    public abstract static class Format
    {
       /**
-       *
        * @param value
        * @return
        */
       public abstract String[] parse(String value) throws IllegalArgumentException;
 
       /**
-       *
        * @param names
        * @return
        */
       public abstract String toString(String[] names) throws IllegalArgumentException;
 
       /**
-       * 
        * @param id
        * @return
        */
       public final String toString(PortalObjectId id) throws IllegalArgumentException
       {
-         if (id == null)
-         {
-            throw new IllegalArgumentException("No null id accepted");
-         }
+         ParameterValidation.throwIllegalArgExceptionIfNull(id, "PortalObjectId");
          return toString(id.names);
       }
    }
 
-   /**
-    * Canonical format, smth like /a/b/c.
-    */
+   /** Canonical format, smth like /a/b/c. */
    public static final Format CANONICAL_FORMAT = new Format()
    {
       public String[] parse(String value)
       {
-         if (value == null)
+         ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(value, "value", "Format.parse(value)");
+         if (value.charAt(0) != '/')
          {
-            throw new IllegalArgumentException("Null value not accepted");
-         }
-         if (value.length() == 0 || value.charAt(0) != '/')
-         {
             throw new IllegalArgumentException("Not a canonical value " + value);
          }
          if (value.length() == 1)
@@ -265,10 +243,7 @@
 
       public String toString(String[] names)
       {
-         if (names == null)
-         {
-            throw new IllegalArgumentException("Null string array not accepted");
-         }
+         ParameterValidation.throwIllegalArgExceptionIfNull(names, "name string array");
          if (names.length == 0)
          {
             return "/";
@@ -276,7 +251,7 @@
          else
          {
             StringBuffer tmp = new StringBuffer(names.length * 10);
-            for (int i = 0;i < names.length;i++)
+            for (int i = 0; i < names.length; i++)
             {
                String name = names[i];
                if (name == null)
@@ -290,9 +265,7 @@
       }
    };
 
-   /**
-    * The internal format when it is persisted, smth like a.b.c
-    */
+   /** The internal format when it is persisted, smth like a.b.c */
    public static final Format LEGACY_FORMAT = new Format()
    {
 
@@ -300,10 +273,7 @@
 
       public String[] parse(String value)
       {
-         if (value == null)
-         {
-            throw new IllegalArgumentException("No null value accepted");
-         }
+         ParameterValidation.throwIllegalArgExceptionIfNull(value, "value");
          if (value.length() == 0)
          {
             return EMPTY_STRING_ARRAY;
@@ -311,7 +281,7 @@
 
          // Count the number of names
          int length = 1;
-         for (int next = value.indexOf('.');next != -1;next = value.indexOf('.', next + 1))
+         for (int next = value.indexOf('.'); next != -1; next = value.indexOf('.', next + 1))
          {
             length++;
          }
@@ -320,7 +290,7 @@
          String[] names = new String[length];
          length = 0;
          int previous = 0;
-         for (int next = value.indexOf('.');next != -1;previous = next + 1, next = value.indexOf('.', next + 1))
+         for (int next = value.indexOf('.'); next != -1; previous = next + 1, next = value.indexOf('.', next + 1))
          {
             names[length++] = value.substring(previous, next);
          }
@@ -332,16 +302,13 @@
 
       public String toString(String[] names)
       {
-         if (names == null)
-         {
-            throw new IllegalArgumentException("Null string array not accepted");
-         }
+         ParameterValidation.throwIllegalArgExceptionIfNull(names, "name string array");
          if (names.length == 0)
          {
             return "";
          }
          StringBuffer buffer = new StringBuffer(names.length * 8);
-         for (int i = 0;i < names.length;i++)
+         for (int i = 0; i < names.length; i++)
          {
             if (i > 0)
             {




More information about the portal-commits mailing list