commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bay...@apache.org
Subject svn commit: r1062328 - in /commons/proper/lang/trunk/src: main/java/org/apache/commons/lang3/text/WordUtils.java test/java/org/apache/commons/lang3/text/WordUtilsTest.java
Date Sun, 23 Jan 2011 05:32:46 GMT
Author: bayard
Date: Sun Jan 23 05:32:46 2011
New Revision: 1062328

URL: http://svn.apache.org/viewvc?rev=1062328&view=rev
Log:
Removing WordUtils.abbreviate as it's already found in StringUtils.abbreviate. This was identified
in LANG-673

Modified:
    commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/text/WordUtils.java
    commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/WordUtilsTest.java

Modified: commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/text/WordUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/text/WordUtils.java?rev=1062328&r1=1062327&r2=1062328&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/text/WordUtils.java (original)
+++ commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/text/WordUtils.java Sun
Jan 23 05:32:46 2011
@@ -510,67 +510,4 @@ public class WordUtils {
         return false;
     }
 
-    //-----------------------------------------------------------------------
-    /**
-     * Abbreviates a string nicely.
-     * 
-     * This method searches for the first space after the lower limit and abbreviates
-     * the String there. It will also append any String passed as a parameter
-     * to the end of the String. The upper limit can be specified to forcibly
-     * abbreviate a String.
-     * 
-     * @param str         the string to be abbreviated. If null is passed, null is returned.
-     *                    If the empty String is passed, the empty string is returned.
-     * @param lower       the lower limit.
-     * @param upper       the upper limit; specify -1 if no limit is desired.
-     *                    If the upper limit is lower than the lower limit, it will be
-     *                    adjusted to be the same as the lower limit.
-     * @param appendToEnd String to be appended to the end of the abbreviated string.
-     *                    This is appended ONLY if the string was indeed abbreviated.
-     *                    The append does not count towards the lower or upper limits.
-     * @return the abbreviated String.
-     * @since 2.4
-     */
-    public static String abbreviate(String str, int lower, int upper, String appendToEnd)
{
-        // initial parameter checks
-        if (str == null) {
-            return null;
-        }
-        if (str.length() == 0) {
-            return StringUtils.EMPTY;
-        }
-
-        // if the lower value is greater than the length of the string,
-        // set to the length of the string
-        if (lower > str.length()) {
-            lower = str.length();    
-        }
-        // if the upper value is -1 (i.e. no limit) or is greater
-        // than the length of the string, set to the length of the string
-        if (upper == -1 || upper > str.length()) {
-            upper = str.length();
-        }
-        // if upper is less than lower, raise it to lower
-        if (upper < lower) {
-            upper = lower;
-        }
-
-        StringBuilder result = new StringBuilder();
-        int index = StringUtils.indexOf(str, " ", lower);
-        if (index == -1) {
-            result.append(str.substring(0, upper));
-            // only if abbreviation has occured do we append the appendToEnd value
-            if (upper != str.length()) {
-                result.append(StringUtils.defaultString(appendToEnd));
-            }
-        } else if (index > upper) {
-            result.append(str.substring(0, upper));
-            result.append(StringUtils.defaultString(appendToEnd));
-        } else {
-            result.append(str.substring(0, index));
-            result.append(StringUtils.defaultString(appendToEnd));
-        }
-        return result.toString();
-    }
-
 }

Modified: commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/WordUtilsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/WordUtilsTest.java?rev=1062328&r1=1062327&r2=1062328&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/WordUtilsTest.java
(original)
+++ commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/WordUtilsTest.java
Sun Jan 23 05:32:46 2011
@@ -356,42 +356,4 @@ public class WordUtilsTest extends TestC
         assertEquals(expect, WordUtils.swapCase(test));
     }
 
-    // -----------------------------------------------------------------------
-    public void testAbbreviate() {
-        // check null and empty are returned respectively
-        assertNull(WordUtils.abbreviate(null, 1,-1,""));
-        assertEquals(StringUtils.EMPTY, WordUtils.abbreviate("", 1,-1,""));
-
-        // test upper limit
-        assertEquals("01234", WordUtils.abbreviate("0123456789", 0,5,""));
-        assertEquals("01234", WordUtils.abbreviate("0123456789", 5, 2,""));
-        assertEquals("012", WordUtils.abbreviate("012 3456789", 2, 5,""));
-        assertEquals("012 3", WordUtils.abbreviate("012 3456789", 5, 2,""));
-        assertEquals("0123456789", WordUtils.abbreviate("0123456789", 0,-1,""));
-
-        // test upper limit + append string
-        assertEquals("01234-", WordUtils.abbreviate("0123456789", 0,5,"-"));
-        assertEquals("01234-", WordUtils.abbreviate("0123456789", 5, 2,"-"));
-        assertEquals("012", WordUtils.abbreviate("012 3456789", 2, 5, null));
-        assertEquals("012 3", WordUtils.abbreviate("012 3456789", 5, 2,""));
-        assertEquals("0123456789", WordUtils.abbreviate("0123456789", 0,-1,""));
-
-        // test lower value
-        assertEquals("012", WordUtils.abbreviate("012 3456789", 0,5, null));
-        assertEquals("01234", WordUtils.abbreviate("01234 56789", 5, 10, null));
-        assertEquals("01 23 45 67", WordUtils.abbreviate("01 23 45 67 89", 9, -1, null));
-        assertEquals("01 23 45 6", WordUtils.abbreviate("01 23 45 67 89", 9, 10, null));
-        assertEquals("0123456789", WordUtils.abbreviate("0123456789", 15, 20, null));
-
-        // test lower value + append
-        assertEquals("012", WordUtils.abbreviate("012 3456789", 0,5, null));
-        assertEquals("01234-", WordUtils.abbreviate("01234 56789", 5, 10, "-"));
-        assertEquals("01 23 45 67abc", WordUtils.abbreviate("01 23 45 67 89", 9, -1, "abc"));
-        assertEquals("01 23 45 6", WordUtils.abbreviate("01 23 45 67 89", 9, 10, ""));
-
-        // others
-        assertEquals("", WordUtils.abbreviate("0123456790", 0,0,""));
-        assertEquals("", WordUtils.abbreviate(" 0123456790", 0,-1,""));
-    }
-
 }



Mime
View raw message