You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by sc...@apache.org on 2003/07/20 17:41:53 UTC

cvs commit: jakarta-commons/lang/src/java/org/apache/commons/lang ObjectUtils.java StringUtils.java

scolebourne    2003/07/20 08:41:53

  Modified:    lang/src/test/org/apache/commons/lang StringUtilsTest.java
                        ObjectUtilsTest.java
               lang/src/java/org/apache/commons/lang ObjectUtils.java
                        StringUtils.java
  Log:
  Remove  defaultString(Object)  from StringUtils
  Add  toString(Object)  to ObjectUtils
  
  Revision  Changes    Path
  1.34      +1 -11     jakarta-commons/lang/src/test/org/apache/commons/lang/StringUtilsTest.java
  
  Index: StringUtilsTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/lang/src/test/org/apache/commons/lang/StringUtilsTest.java,v
  retrieving revision 1.33
  retrieving revision 1.34
  diff -u -r1.33 -r1.34
  --- StringUtilsTest.java	20 Jul 2003 14:47:29 -0000	1.33
  +++ StringUtilsTest.java	20 Jul 2003 15:41:52 -0000	1.34
  @@ -734,16 +734,6 @@
           assertEquals("abc", StringUtils.defaultString("abc", "xyz") );
       }
       
  -    public void testDefault_Object() {
  -        assertEquals("", StringUtils.defaultString((Object) null) );
  -        assertEquals(Boolean.TRUE.toString(), StringUtils.defaultString(Boolean.TRUE) );
  -    }
  -            
  -    public void testDefault_ObjectString() {
  -        assertEquals(BAR, StringUtils.defaultString((Object) null, BAR) );
  -        assertEquals(Boolean.TRUE.toString(), StringUtils.defaultString(Boolean.TRUE, BAR) );
  -    }
  -
       //-----------------------------------------------------------------------
       public void testEscapeFunctions_String() {
           assertEquals("", StringUtils.escape("") );
  
  
  
  1.6       +11 -1     jakarta-commons/lang/src/test/org/apache/commons/lang/ObjectUtilsTest.java
  
  Index: ObjectUtilsTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/lang/src/test/org/apache/commons/lang/ObjectUtilsTest.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ObjectUtilsTest.java	16 Jul 2003 01:47:40 -0000	1.5
  +++ ObjectUtilsTest.java	20 Jul 2003 15:41:52 -0000	1.6
  @@ -132,6 +132,16 @@
           assertEquals(null, ObjectUtils.appendIdentityToString(new StringBuffer(), null));
       }
   
  +    public void testToString_Object() {
  +        assertEquals("", ObjectUtils.toString((Object) null) );
  +        assertEquals(Boolean.TRUE.toString(), ObjectUtils.toString(Boolean.TRUE) );
  +    }
  +            
  +    public void testToString_ObjectString() {
  +        assertEquals(BAR, ObjectUtils.toString((Object) null, BAR) );
  +        assertEquals(Boolean.TRUE.toString(), ObjectUtils.toString(Boolean.TRUE, BAR) );
  +    }
  +
       public void testNull() {
           assertTrue(ObjectUtils.NULL != null);
           assertTrue(ObjectUtils.NULL instanceof ObjectUtils.Null);
  
  
  
  1.13      +44 -3     jakarta-commons/lang/src/java/org/apache/commons/lang/ObjectUtils.java
  
  Index: ObjectUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/lang/src/java/org/apache/commons/lang/ObjectUtils.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- ObjectUtils.java	19 Jul 2003 20:21:39 -0000	1.12
  +++ ObjectUtils.java	20 Jul 2003 15:41:52 -0000	1.13
  @@ -101,8 +101,7 @@
       public ObjectUtils() {
       }
   
  -    //--------------------------------------------------------------------
  -    
  +    //-----------------------------------------------------------------------
       /**
        * <p>Returns a default value if the object passed is
        * <code>null</code>.</p>
  @@ -133,6 +132,7 @@
           return object1.equals(object2);
       }
       
  +    //-----------------------------------------------------------------------
       /**
        * <p>Gets the toString that would be produced by <code>Object</code>
        * if a class did not override toString itself. <code>null</code>
  @@ -172,6 +172,47 @@
               .append(Integer.toHexString(System.identityHashCode(object)));
       }
   
  +    //-----------------------------------------------------------------------
  +    /**
  +     * <p>Gets the <code>toString</code> of an <code>Object</code> returning
  +     * an empty string ("") if <code>null</code> input,</p>
  +     * 
  +     * <pre>
  +     * ObjectUtils.toString(null)         = ""
  +     * ObjectUtils.toString("")           = ""
  +     * ObjectUtils.toString("bat")        = "bat"
  +     * ObjectUtils.toString(Boolean.TRUE) = "true"
  +     * </pre>
  +     * 
  +     * @param obj  the Object to <code>toString</code>, may be null
  +     * @param nullStr  the String to return if <code>null</code> input, may be null
  +     * @return the passed in Object's toString, or nullStr if <code>null</code> input
  +     */
  +    public static String toString(Object obj) {
  +        return (obj == null ? "" : obj.toString());
  +    }
  +
  +    /**
  +     * <p>Gets the <code>toString</code> of an <code>Object</code> returning
  +     * an empty string ("") if <code>null</code> input,</p>
  +     * 
  +     * <pre>
  +     * ObjectUtils.toString(null, null)           = null
  +     * ObjectUtils.toString(null, "null")         = "null"
  +     * ObjectUtils.toString("", "null")           = ""
  +     * ObjectUtils.toString("bat", "null")        = "bat"
  +     * ObjectUtils.toString(Boolean.TRUE, "null") = "true"
  +     * </pre>
  +     * 
  +     * @param obj  the Object to <code>toString</code>, may be null
  +     * @param nullStr  the String to return if <code>null</code> input, may be null
  +     * @return the passed in Object's toString, or nullStr if <code>null</code> input
  +     */
  +    public static String toString(Object obj, String nullStr) {
  +        return (obj == null ? nullStr : obj.toString());
  +    }
  +
  +    //-----------------------------------------------------------------------
       /**
        * <p>Class used as a null placeholder where <code>null</code>
        * has another meaning.</p>
  
  
  
  1.74      +1 -42     jakarta-commons/lang/src/java/org/apache/commons/lang/StringUtils.java
  
  Index: StringUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/lang/src/java/org/apache/commons/lang/StringUtils.java,v
  retrieving revision 1.73
  retrieving revision 1.74
  diff -u -r1.73 -r1.74
  --- StringUtils.java	20 Jul 2003 15:29:44 -0000	1.73
  +++ StringUtils.java	20 Jul 2003 15:41:52 -0000	1.74
  @@ -3415,26 +3415,6 @@
       }
   
       /**
  -     * <p>Returns either the passed in <code>Object</code> as a String,
  -     * or, if the <code>Object</code> is <code>null</code>,
  -     * an empty String ("").</p>
  -     * 
  -     * <pre>
  -     * StringUtils.defaultString(null)         = "null"
  -     * StringUtils.defaultString("")           = ""
  -     * StringUtils.defaultString("bat")        = "bat"
  -     * StringUtils.defaultString(Boolean.TRUE) = "true"
  -     * </pre>
  -     * 
  -     * @param obj  the Object to check, using <code>toString()</code>, may be null
  -     * @return the passed in Object's toString, or the empty String if it
  -     *  was <code>null</code>
  -     */
  -    public static String defaultString(Object obj) {
  -        return (obj == null ? "" : obj.toString());
  -    }
  -
  -    /**
        * <p>Returns either the passed in String, 
        * or if the String is <code>null</code>, an empty String ("").</p>
        * 
  @@ -3451,27 +3431,6 @@
        */
       public static String defaultString(String str, String defaultStr) {
           return (str == null ? defaultStr : str);
  -    }
  -
  -    /**
  -     * <p>Returns either the passed in <code>Object</code> as a String,
  -     * or, if the <code>Object</code> is <code>null</code>, a passed
  -     * in default String.</p>
  -     * 
  -     * <pre>
  -     * StringUtils.defaultString(null, "null")         = "null"
  -     * StringUtils.defaultString("", "null")           = ""
  -     * StringUtils.defaultString("bat", "null")        = "bat"
  -     * StringUtils.defaultString(Boolean.TRUE, "null") = "true"
  -     * </pre>
  -     * 
  -     * @param obj  the Object to check, using <code>toString()</code>, may be null
  -     * @param defaultStr  the default String to return 
  -     *  if the input is <code>null</code>, may be null
  -     * @return the passed in Object's toString, or the default if it was <code>null</code>
  -     */
  -    public static String defaultString(Object obj, String defaultStr) {
  -        return (obj == null ? defaultStr : obj.toString());
       }
   
       // Reversing
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org