You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by ps...@apache.org on 2003/09/13 05:11:30 UTC

cvs commit: jakarta-commons/lang/src/java/org/apache/commons/lang/reflect MethodUtils.java

psteitz     2003/09/12 20:11:30

  Modified:    lang/src/java/org/apache/commons/lang Entities.java
               lang/src/java/org/apache/commons/lang/exception
                        NestableDelegate.java
               lang/src/java/org/apache/commons/lang/math NumberUtils.java
               lang/src/java/org/apache/commons/lang/reflect
                        MethodUtils.java
  Log:
  Formatting changes (inserting missing {}s) in Entities, NestableDelagate, NumberUtils, MethodUtils.
  Added javadoc examples for string conversion methods in NumberUtils.
  Patch submitted by Fredrik Westermarck
  Reviewed by Phil Steitz
  
  Revision  Changes    Path
  1.15      +15 -8     jakarta-commons/lang/src/java/org/apache/commons/lang/Entities.java
  
  Index: Entities.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/lang/src/java/org/apache/commons/lang/Entities.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- Entities.java	7 Sep 2003 14:32:34 -0000	1.14
  +++ Entities.java	13 Sep 2003 03:11:29 -0000	1.15
  @@ -431,8 +431,9 @@
   
           public int value(String name) {
               Object value = mapNameToValue.get(name);
  -            if (value == null)
  +            if (value == null) {
                   return -1;
  +            }
               return ((Integer) value).intValue();
           }
       }
  @@ -453,8 +454,9 @@
   
           public int value(String name) {
               Object value = mapNameToValue.get(name);
  -            if (value == null)
  +            if (value == null) {
                   return -1;
  +            }
               return ((Integer) value).intValue();
           }
       }
  @@ -572,12 +574,13 @@
                   int mid = (low + high) >> 1;
                   int midVal = values[mid];
   
  -                if (midVal < key)
  +                if (midVal < key) {
                       low = mid + 1;
  -                else if (midVal > key)
  +                } else if (midVal > key) {
                       high = mid - 1;
  -                else
  +                } else {
                       return mid; // key found
  +                }
               }
               return -(low + 1);  // key not found.
           }
  @@ -585,7 +588,9 @@
           public void add(String name, int value) {
               ensureCapacity(size + 1);
               int insertAt = binarySearch(value);
  -            if (insertAt > 0) return;    // note: this means you can't insert the same value twice
  +            if (insertAt > 0) {
  +                return;    // note: this means you can't insert the same value twice
  +            }
               insertAt = -(insertAt + 1);  // binarySearch returns it negative and off-by-one
               System.arraycopy(values, insertAt, values, insertAt + 1, size - insertAt);
               values[insertAt] = value;
  @@ -596,7 +601,9 @@
   
           public String name(int value) {
               int index = binarySearch(value);
  -            if (index < 0) return null;
  +            if (index < 0) {
  +                return null;
  +            }
               return names[index];
           }
       }
  
  
  
  1.22      +6 -3      jakarta-commons/lang/src/java/org/apache/commons/lang/exception/NestableDelegate.java
  
  Index: NestableDelegate.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/lang/src/java/org/apache/commons/lang/exception/NestableDelegate.java,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- NestableDelegate.java	7 Sep 2003 14:32:35 -0000	1.21
  +++ NestableDelegate.java	13 Sep 2003 03:11:30 -0000	1.22
  @@ -344,7 +344,9 @@
           }
   
           // Remove the repeated lines in the stack
  -        if (trimStackFrames) trimStackFrames(stacks);
  +        if (trimStackFrames) {
  +          trimStackFrames(stacks);
  +        }
   
           synchronized (out) {
               for (Iterator iter=stacks.iterator(); iter.hasNext();) {
  @@ -352,8 +354,9 @@
                   for (int i=0, len=st.length; i < len; i++) {
                       out.println(st[i]);
                   }
  -                if (iter.hasNext())
  +                if (iter.hasNext()) {
                       out.print(separatorLine);
  +                }
               }
           }
       }
  
  
  
  1.14      +51 -3     jakarta-commons/lang/src/java/org/apache/commons/lang/math/NumberUtils.java
  
  Index: NumberUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/lang/src/java/org/apache/commons/lang/math/NumberUtils.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- NumberUtils.java	7 Sep 2003 14:32:35 -0000	1.13
  +++ NumberUtils.java	13 Sep 2003 03:11:30 -0000	1.14
  @@ -129,6 +129,12 @@
        *
        * <p>If the string is <code>null</code>, <code>zero</code> is returned.</p>
        * 
  +     * <pre>
  +     *   NumberUtils.stringToInt(null) = 0
  +     *   NumberUtils.stringToInt("")   = 0
  +     *   NumberUtils.stringToInt("1")  = 1
  +     * </pre>
  +     *
        * @param str  the string to convert, may be null
        * @return the int represented by the string, or <code>zero</code> if
        *  conversion fails
  @@ -143,6 +149,12 @@
        *
        * <p>If the string is <code>null</code>, the default value is returned.</p>
        * 
  +     * <pre>
  +     *   NumberUtils.stringToInt(null, 1) = 1
  +     *   NumberUtils.stringToInt("", 1)   = 1
  +     *   NumberUtils.stringToInt("1", 0)  = 1
  +     * </pre>
  +     *
        * @param str  the string to convert, may be null
        * @param defaultValue  the default value
        * @return the int represented by the string, or the default if conversion fails
  @@ -161,6 +173,12 @@
        *
        * <p>If the string is <code>null</code>, <code>zero</code> is returned.</p>
        *
  +     * <pre>
  +     *   NumberUtils.stringToLong(null) = 0L
  +     *   NumberUtils.stringToLong("")   = 0L
  +     *   NumberUtils.stringToLong("1")  = 1L
  +     * </pre>
  +     *
        * @param str  the string to convert, may be null
        * @return the long represented by the string, or <code>0</code> if
        *  conversion fails
  @@ -176,6 +194,12 @@
        *
        * <p>If the string is <code>null</code>, the default value is returned.</p>
        *
  +     * <pre>
  +     *   NumberUtils.stringToLong(null, 1L) = 1L
  +     *   NumberUtils.stringToLong("", 1L)   = 1L
  +     *   NumberUtils.stringToLong("1", 0L)  = 1L
  +     * </pre>
  +     *
        * @param str  the string to convert, may be null
        * @param defaultValue  the default value
        * @return the long represented by the string, or the default if conversion fails
  @@ -196,6 +220,12 @@
        * <p>If the string <code>str</code> is <code>null</code>,
        * <code>0.0f</code> is returned.</p>
        *
  +     * <pre>
  +     *   NumberUtils.stringToFloat(null)   = 0.0f
  +     *   NumberUtils.stringToFloat("")     = 0.0f
  +     *   NumberUtils.stringToFloat("1.5")  = 1.5f
  +     * </pre>
  +     *
        * @param str the string to convert, may be <code>null</code>
        * @return the float represented by the string, or <code>0.0f</code>
        *  if conversion fails
  @@ -212,6 +242,12 @@
        * <p>If the string <code>str</code> is <code>null</code>, the default
        * value is returned.</p>
        *
  +     * <pre>
  +     *   NumberUtils.stringToFloat(null, 1.1f)   = 1.0f
  +     *   NumberUtils.stringToFloat("", 1.1f)     = 1.1f
  +     *   NumberUtils.stringToFloat("1.5", 0.0f)  = 1.5f
  +     * </pre>
  +     *
        * @param str the string to convert, may be <code>null</code>
        * @param defaultValue the default value
        * @return the float represented by the string, or defaultValue
  @@ -219,7 +255,7 @@
        * @since 2.1
        */
       public static float stringToFloat(String str, float defaultValue) {
  -      if(str==null) {
  +      if (str == null) {
             return defaultValue;
         }     
         try {
  @@ -236,6 +272,12 @@
        * <p>If the string <code>str</code> is <code>null</code>,
        * <code>0.0d</code> is returned.</p>
        *
  +     * <pre>
  +     *   NumberUtils.stringToDouble(null)   = 0.0d
  +     *   NumberUtils.stringToDouble("")     = 0.0d
  +     *   NumberUtils.stringToDouble("1.5")  = 1.5d
  +     * </pre>
  +     *
        * @param str the string to convert, may be <code>null</code>
        * @return the double represented by the string, or <code>0.0d</code>
        *  if conversion fails
  @@ -252,6 +294,12 @@
        * <p>If the string <code>str</code> is <code>null</code>, the default
        * value is returned.</p>
        *
  +     * <pre>
  +     *   NumberUtils.stringToDouble(null, 1.1d)   = 1.1d
  +     *   NumberUtils.stringToDouble("", 1.1d)     = 1.1d
  +     *   NumberUtils.stringToDouble("1.5", 0.0d)  = 1.5d
  +     * </pre>
  +     *
        * @param str the string to convert, may be <code>null</code>
        * @param defaultValue the default value
        * @return the double represented by the string, or defaultValue
  @@ -259,7 +307,7 @@
        * @since 2.1
        */
       public static double stringToDouble(String str, double defaultValue) {
  -      if(str==null) {
  +      if (str == null) {
             return defaultValue;
         }
         try {
  
  
  
  1.17      +10 -6     jakarta-commons/lang/src/java/org/apache/commons/lang/reflect/MethodUtils.java
  
  Index: MethodUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/lang/src/java/org/apache/commons/lang/reflect/MethodUtils.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- MethodUtils.java	7 Sep 2003 14:32:35 -0000	1.16
  +++ MethodUtils.java	13 Sep 2003 03:11:30 -0000	1.17
  @@ -400,10 +400,11 @@
                   object.getClass(),
                   methodName,
                   parameterTypes);
  -        if (method == null)
  +        if (method == null) {
               throw new ReflectionException("No such accessible method: " +
                       methodName + "() on object: " + object.getClass().getName());
  -        
  +        }
  +
           try {
           
               return method.invoke(object, args);
  @@ -491,8 +492,9 @@
               for (int i = 0; i < interfaces.length; i++) {
   
                   // Is this interface public?
  -                if (!Modifier.isPublic(interfaces[i].getModifiers()))
  +                if (!Modifier.isPublic(interfaces[i].getModifiers())) {
                       continue;
  +                }
   
                   // Does the method exist on this interface?
                   try {
  @@ -501,16 +503,18 @@
                   } catch (NoSuchMethodException e) {
                       // empty
                   }
  -                if (method != null)
  +                if (method != null) {
                       break;
  +                }
   
                   // Recursively check our parent interfaces
                   method =
                           getAccessibleMethodFromInterfaceNest(interfaces[i],
                                   methodName,
                                   parameterTypes);
  -                if (method != null)
  +                if (method != null) {
                       break;
  +                }
   
               }