geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject cvs commit: incubator-geronimo/modules/twiddle/src/java/org/apache/geronimo/twiddle/command CommandExecutor.java
Date Wed, 03 Sep 2003 13:53:05 GMT
jdillon     2003/09/03 06:53:05

  Modified:    modules/common/src/java/org/apache/geronimo/common
                        Strings.java
               modules/common/src/test/org/apache/geronimo/common
                        StringsTest.java
               modules/core project.xml
               modules/twiddle project.xml
               modules/twiddle/src/java/org/apache/geronimo/twiddle/command
                        CommandExecutor.java
  Log:
   o Use commons-lang StringUtils instead of Strings
   o Removed cruft from Strings
  
  Revision  Changes    Path
  1.11      +3 -371    incubator-geronimo/modules/common/src/java/org/apache/geronimo/common/Strings.java
  
  Index: Strings.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/common/src/java/org/apache/geronimo/common/Strings.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- Strings.java	26 Aug 2003 11:02:43 -0000	1.10
  +++ Strings.java	3 Sep 2003 13:53:04 -0000	1.11
  @@ -58,11 +58,7 @@
   
   import java.util.Map;
   
  -import java.net.URL;
  -import java.net.MalformedURLException;
  -
  -import java.io.IOException;
  -import java.io.File;
  +import org.apache.commons.lang.StringUtils;
   
   /**
    * A collection of String utilities.
  @@ -70,64 +66,11 @@
    * @version $Revision$ $Date$
    */
   public final class Strings
  +    extends StringUtils
   {
       /** An empty string constant */
       public static final String EMPTY = "";
       
  -    /** New line string constant */
  -    public static final String NEWLINE = org.apache.geronimo.common.platform.Constants.LINE_SEPARATOR;
  -    
  -    
  -    /////////////////////////////////////////////////////////////////////////
  -    //                         Substitution Methods                        //
  -    /////////////////////////////////////////////////////////////////////////
  -    
  -    /**
  -     * Substitute sub-strings in side of a string.
  -     *
  -     * @param buff    Stirng buffer to use for substitution (buffer is not reset)
  -     * @param from    String to substitute from
  -     * @param to      String to substitute to
  -     * @param string  String to look for from in
  -     * @return        Substituted string
  -     */
  -    public static String subst(final StringBuffer buff, final String from,
  -                               final String to, final String string)
  -    {
  -        int begin = 0, end = 0;
  -        
  -        while ((end = string.indexOf(from, end)) != -1) {
  -            // append the first part of the string
  -            buff.append(string.substring(begin, end));
  -            
  -            // append the replaced string
  -            buff.append(to);
  -            
  -            // update positions
  -            begin = end + from.length();
  -            end = begin;
  -        }
  -        
  -        // append the rest of the string
  -        buff.append(string.substring(begin, string.length()));
  -        
  -        return buff.toString();
  -    }
  -    
  -    /**
  -     * Substitute sub-strings in side of a string.
  -     *
  -     * @param from    String to substitute from
  -     * @param to      String to substitute to
  -     * @param string  String to look for from in
  -     * @return        Substituted string
  -     */
  -    public static String subst(final String from, final String to, 
  -                               final String string)
  -    {
  -        return subst(new StringBuffer(), from, to, string);
  -    }
  -    
       /**
        * Substitute sub-strings in side of a string.
        *
  @@ -249,22 +192,6 @@
           return subst(new StringBuffer(), string, replace, token);
       }
       
  -    /**
  -     * Substitute index identifiers (with <code>%</code> for the index token)
  -     * with the replacement value from the given array for the corresponding
  -     * index.
  -     *
  -     * @param string     String substitution format.
  -     * @param replace    Array of strings whose values will be used as 
  -     *                   replacements in the given string when a token with
  -     *                   their index is found.
  -     * @return           Substituted string.
  -     */
  -    public static String subst(final String string, final String replace[]) {
  -        return subst(new StringBuffer(), string, replace, '%');
  -    }
  -    
  -    
       /////////////////////////////////////////////////////////////////////////
       //                             Range Methods                           //
       /////////////////////////////////////////////////////////////////////////
  @@ -335,118 +262,6 @@
           return rangeOf(beginToken, endToken, string, 0);
       }
       
  -    
  -    /////////////////////////////////////////////////////////////////////////
  -    //                           Spliting Methods                          //
  -    /////////////////////////////////////////////////////////////////////////
  -    
  -    /**
  -     * Split up a string into multiple strings based on a delimiter.
  -     *
  -     * @param string  String to split up.
  -     * @param delim   Delimiter.
  -     * @param limit   Limit the number of strings to split into
  -     *                (-1 for no limit).
  -     * @return        Array of strings.
  -     */
  -    public static String[] split(final String string, final String delim,
  -                                 final int limit)
  -    {
  -        // get the count of delim in string, if count is > limit 
  -        // then use limit for count.  The number of delimiters is less by one
  -        // than the number of elements, so add one to count.
  -        int count = count(string, delim) + 1;
  -        if (limit > 0 && count > limit) {
  -            count = limit;
  -        }
  -        
  -        String strings[] = new String[count];
  -        int begin = 0;
  -        
  -        for (int i=0; i<count; i++) {
  -            // get the next index of delim
  -            int end = string.indexOf(delim, begin);
  -            
  -            // if the end index is -1 or if this is the last element
  -            // then use the string's length for the end index
  -            if (end == -1 || i + 1 == count)
  -                end = string.length();
  -            
  -            // if end is 0, then the first element is empty
  -            if (end == 0)
  -                strings[i] = EMPTY;
  -            else
  -                strings[i] = string.substring(begin, end);
  -            
  -            // update the begining index
  -            begin = end + 1;
  -        }
  -        
  -        return strings;
  -    }
  -    
  -    /**
  -     * Split up a string into multiple strings based on a delimiter.
  -     *
  -     * @param string  String to split up.
  -     * @param delim   Delimiter.
  -     * @return        Array of strings.
  -     */
  -    public static String[] split(final String string, final String delim) {
  -        return split(string, delim, -1);
  -    }
  -    
  -    
  -    /////////////////////////////////////////////////////////////////////////
  -    //                    Joining/Concatenation Methods                    //
  -    /////////////////////////////////////////////////////////////////////////
  -    
  -    /**
  -     * Join an array of strings into one delimited string.
  -     *
  -     * @param buff    String buffered used for join (buffer is not reset).
  -     * @param array   Array of objects to join as strings.
  -     * @param delim   Delimiter to join strings with or <i>null</i>.
  -     * @return        Joined string.
  -     */
  -    public static String join(final StringBuffer buff, final Object array[],
  -                              final String delim)
  -    {
  -        boolean haveDelim = (delim != null);
  -        
  -        for (int i=0; i<array.length; i++) {
  -            buff.append(array[i]);
  -            
  -            // if this is the last element then don't append delim
  -            if (haveDelim && (i + 1) < array.length) {
  -                buff.append(delim);
  -            }
  -        }
  -        
  -        return buff.toString();
  -    }
  -    
  -    /**
  -     * Join an array of strings into one delimited string.
  -     *
  -     * @param array   Array of objects to join as strings.
  -     * @param delim   Delimiter to join strings with or <i>null</i>.
  -     * @return        Joined string.
  -     */
  -    public static String join(final Object array[], final String delim) {
  -        return join(new StringBuffer(), array, delim);
  -    }
  -    
  -    /**
  -     * Convert and join an array of objects into one string.
  -     *
  -     * @param array   Array of objects to join as strings.
  -     * @return        Converted and joined objects.
  -     */
  -    public static String join(final Object array[]) {
  -        return join(array, null);
  -    }
  -    
       /**
        * Convert and join an array of bytes into one string.
        *
  @@ -462,44 +277,6 @@
           return join(bytes, null);
       }
       
  -    /**
  -     * Return a string composed of the given array.
  -     *
  -     * @param buff       Buffer used to construct string value (not reset).
  -     * @param array      Array of objects.
  -     * @param prefix     String prefix.
  -     * @param separator  Element sepearator.
  -     * @param suffix     String suffix.
  -     * @return           String in the format of:
  -     *                   prefix + n ( + separator + n+i)* + suffix.
  -     */
  -    public static String join(final StringBuffer buff, final Object[] array, 
  -                              final String prefix, final String separator,
  -                              final String suffix)
  -    {
  -        buff.append(prefix);
  -        join(buff, array, separator);
  -        buff.append(suffix);
  -        
  -        return buff.toString();
  -    }
  -    
  -    /**
  -     * Return a string composed of the given array.
  -     *
  -     * @param array      Array of objects.
  -     * @param prefix     String prefix.
  -     * @param separator  Element sepearator.
  -     * @param suffix     String suffix.
  -     * @return           String in the format of:
  -     *                   prefix + n ( + separator + n+i)* + suffix.
  -     */
  -    public static String join(final Object[] array, final String prefix, 
  -                              final String separator, final String suffix)
  -    {
  -        return join(new StringBuffer(), array, prefix, separator, suffix);
  -    }
  -    
       
       /////////////////////////////////////////////////////////////////////////
       //                          Counting Methods                           //
  @@ -537,52 +314,6 @@
       
       
       /////////////////////////////////////////////////////////////////////////
  -    //                            Padding Methods                          //
  -    /////////////////////////////////////////////////////////////////////////
  -    
  -    /**
  -     * Return a string padded with the given string for the given count.
  -     *
  -     * @param buff       String buffer used for padding (buffer is not reset).
  -     * @param string     Pad element.
  -     * @param count      Pad count.
  -     * @return           Padded string.
  -     */
  -    public static String pad(final StringBuffer buff, final String string,
  -                             final int count)
  -    {
  -        for (int i=0; i<count; i++) {
  -            buff.append(string);
  -        }
  -        
  -        return buff.toString();
  -    }
  -    
  -    /**
  -     * Return a string padded with the given string for the given count.
  -     *
  -     * @param string     Pad element.
  -     * @param count      Pad count.
  -     * @return           Padded string.
  -     */
  -    public static String pad(final String string, final int count) {
  -        return pad(new StringBuffer(), string, count);
  -    }
  -    
  -    /**
  -     * Return a string padded with the given string value of an object
  -     * for the given count.
  -     *
  -     * @param obj     Object to convert to a string.
  -     * @param count   Pad count.
  -     * @return        Padded string.
  -     */
  -    public static String pad(final Object obj, final int count) {
  -        return pad(new StringBuffer(), String.valueOf(obj), count);
  -    }
  -    
  -    
  -    /////////////////////////////////////////////////////////////////////////
       //                              Misc Methods                           //
       /////////////////////////////////////////////////////////////////////////
       
  @@ -639,105 +370,6 @@
           }
           
           return j;
  -    }
  -    
  -    /**
  -     * Capitalize the first character of the given string.
  -     *
  -     * @param string     String to capitalize.
  -     * @return           Capitalized string.
  -     *
  -     * @throws IllegalArgumentException    String is <kk>null</kk> or empty.
  -     */
  -    public static String capitalize(final String string) {
  -        if (string == null)
  -            throw new NullArgumentException("string");
  -        if (string.equals(""))
  -            throw new IllegalArgumentException("string is empty");
  -        
  -        return Character.toUpperCase(string.charAt(0)) + string.substring(1);
  -    }
  -    
  -    /**
  -     * Trim each string in the given string array.
  -     *
  -     * <p>This modifies the string array.
  -     *
  -     * @param strings    String array to trim.
  -     * @return           String array with each element trimmed.
  -     */
  -    public static String[] trim(final String[] strings) {
  -        for (int i=0; i<strings.length; i++) {
  -            strings[i] = strings[i].trim();
  -        }
  -        
  -        return strings;
  -    }
  -    
  -    /**
  -     * Make a URL from the given string.
  -     *
  -     * <p>
  -     * If the string is an invalid URL then it will be converted into a
  -     * file URL.
  -     *
  -     * @param urlspec           The string to construct a URL for.
  -     * @param relativePrefix    The string to prepend to relative file
  -     *                          paths, or null to disable prepending.
  -     * @return                  A URL for the given string.
  -     *
  -     * @throws MalformedURLException  Could not make a URL for the given string.
  -     */
  -    public static URL toURL(String urlspec, final String relativePrefix) throws MalformedURLException
  -    {
  -        if (urlspec == null) {
  -            throw new NullArgumentException("urlspec");
  -        }
  -        
  -        urlspec = urlspec.trim();
  -        URL url;
  -        
  -        try {
  -            url = new URL(urlspec);
  -            if (url.getProtocol().equals("file")) {
  -                url = makeURLFromFilespec(url.getFile(), relativePrefix);
  -            }
  -        }
  -        catch (Exception e) {
  -            url = makeURLFromFilespec(urlspec, relativePrefix);
  -        }
  -        
  -        return url;
  -    }
  -    
  -    /** A helper to make a URL from a filespec. */
  -    private static URL makeURLFromFilespec(final String filespec, final String relativePrefix)
  -        throws MalformedURLException
  -    {
  -        // make sure the file is absolute 
  -        File file = new File(filespec);
  -        
  -        // if we have a prefix and the file is not abs then prepend
  -        if (relativePrefix != null && !file.isAbsolute()) {
  -            file = new File(relativePrefix, filespec);
  -        }
  -        
  -        return file.toURL();
  -    }
  -    
  -    /**
  -     * Make a URL from the given string.
  -     *
  -     * @see #toURL(String,String)
  -     *
  -     * @param urlspec    The string to construct a URL for.
  -     * @return           A URL for the given string.
  -     *
  -     * @throws MalformedURLException  Could not make a URL for the given string.
  -     */
  -    public static URL toURL(final String urlspec) throws MalformedURLException
  -    {
  -        return toURL(urlspec, null);
       }
   }
   
  
  
  
  1.4       +1 -80     incubator-geronimo/modules/common/src/test/org/apache/geronimo/common/StringsTest.java
  
  Index: StringsTest.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/common/src/test/org/apache/geronimo/common/StringsTest.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- StringsTest.java	16 Aug 2003 19:22:39 -0000	1.3
  +++ StringsTest.java	3 Sep 2003 13:53:04 -0000	1.4
  @@ -68,21 +68,6 @@
    */
   public class StringsTest extends TestCase {
       
  -    public void testCapitalize() {
  -        assertEquals("Apache", Strings.capitalize("apache"));
  -        assertEquals("ALLCAPS", Strings.capitalize("ALLCAPS"));
  -        
  -        try {
  -            Strings.capitalize(null);
  -            fail("Expected IllegalArgumnetException to be thrown");
  -        } catch (IllegalArgumentException ignore) {}
  -        
  -        try {
  -            Strings.capitalize("");
  -            fail("Expected IllegalArgumnetException to be thrown");
  -        } catch (IllegalArgumentException ignore) {}
  -    }
  -    
       public void testIsEmpty() {
           assertTrue(Strings.isEmpty(""));
           assertFalse(Strings.isEmpty("  "));
  @@ -100,20 +85,6 @@
           assertTrue(Strings.compare("Hello", "Hello"));
       }
       
  -    public void testPadWithBuffer() {
  -        StringBuffer buffer = new StringBuffer("Hello");
  -        assertEquals("Hello*****", Strings.pad(buffer, "*", 5));
  -    }
  -    
  -    public void testPad() {
  -        assertEquals("*****", Strings.pad("*", 5));
  -    }
  -    
  -    public void testPadWithObject() {
  -        Integer integer = new Integer(1);
  -        assertEquals("11111", Strings.pad(integer, 5));
  -    }
  -    
       public void testCount() {
           assertEquals(3, Strings.count("Merry go round merry go round go round", "go"));
       }
  @@ -128,13 +99,6 @@
           assertEquals(-1, Strings.nthIndexOf(toSearch, "5", 2));
       }
       
  -    public void testSubst() {
  -        StringBuffer buffer = new StringBuffer();
  -        
  -        assertEquals("The world is not enough", Strings.subst(buffer, "basta", "enough",
"The world is not basta"));
  -        assertEquals("The world is not enough", Strings.subst("basta", "enough", "The world
is not basta"));
  -    }
  -    
       public void testSubstWithMap() {
           StringBuffer buffer = new StringBuffer();
           
  @@ -146,48 +110,5 @@
           
           assertEquals("ilmondononbasta", Strings.subst(buffer, "<The><world><not><enough>",
map, "<", ">"));
           assertEquals("ilmondononbasta", Strings.subst("<The><world><not><enough>",
map, "<", ">"));
  -    }
  -    
  -    public void testTrim() {
  -        String[] toTrim = {"   Hello ", "foo bar", "ciao"};
  -        Strings.trim(toTrim);
  -        
  -        assertEquals("Hello", toTrim[0]);
  -        assertEquals("foo bar", toTrim[1]);
  -        assertEquals("ciao", toTrim[2]);
  -    }
  -    
  -    public void testJoin() {
  -        StringBuffer buffer = new StringBuffer();
  -        Object[] objArray = {"Java", new Integer(2), "rocks"};
  -        
  -        assertEquals("Java 2 rocks", Strings.join(buffer, objArray, " "));
  -        
  -        buffer = new StringBuffer();
  -        assertEquals("<<Java 2 rocks>>", Strings.join(buffer, objArray, "<<",
" ", ">>"));
  -        
  -        assertEquals("Java 2 rocks", Strings.join(objArray, " "));
  -        assertEquals("Java2rocks", Strings.join(objArray));
  -        
  -    }
  -    
  -    public void testSplit() {
  -        String toSplit = "one,two,three,four,five";
  -        
  -        String[] strArray = Strings.split(toSplit, ",", 3);
  -        
  -        assertEquals(3, strArray.length);
  -        assertEquals("one", strArray[0]);
  -        assertEquals("two", strArray[1]);
  -        assertEquals("three,four,five", strArray[2]);
  -        
  -        strArray = Strings.split(toSplit, ",");
  -        
  -        assertEquals(5, strArray.length);
  -        assertEquals("one", strArray[0]);
  -        assertEquals("two", strArray[1]);
  -        assertEquals("three", strArray[2]);
  -        assertEquals("four", strArray[3]);
  -        assertEquals("five", strArray[4]);
       }
   }
  
  
  
  1.20      +10 -1     incubator-geronimo/modules/core/project.xml
  
  Index: project.xml
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/core/project.xml,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- project.xml	2 Sep 2003 17:04:22 -0000	1.19
  +++ project.xml	3 Sep 2003 13:53:04 -0000	1.20
  @@ -283,6 +283,15 @@
         </properties>
       </dependency>
       
  +    <dependency>
  +      <id>commons-lang</id>
  +      <version>SNAPSHOT</version>
  +      <url>http://jakarta.apache.org/commons/lang</url>
  +      <properties>
  +        <runtime>true</runtime>
  +      </properties>
  +    </dependency>
  +    
     </dependencies>
   
   
  
  
  
  1.12      +10 -1     incubator-geronimo/modules/twiddle/project.xml
  
  Index: project.xml
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/twiddle/project.xml,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- project.xml	30 Aug 2003 08:40:37 -0000	1.11
  +++ project.xml	3 Sep 2003 13:53:04 -0000	1.12
  @@ -114,6 +114,15 @@
       </dependency>
       
       <dependency>
  +      <id>commons-lang</id>
  +      <version>SNAPSHOT</version>
  +      <url>http://jakarta.apache.org/commons/lang</url>
  +      <properties>
  +        <runtime>true</runtime>
  +      </properties>
  +    </dependency>
  +    
  +    <dependency>
         <id>commons-logging</id>
         <version>1.0.3</version>
         <url>http://jakarta.apache.org/commons/logging</url>
  
  
  
  1.8       +6 -4      incubator-geronimo/modules/twiddle/src/java/org/apache/geronimo/twiddle/command/CommandExecutor.java
  
  Index: CommandExecutor.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/twiddle/src/java/org/apache/geronimo/twiddle/command/CommandExecutor.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- CommandExecutor.java	28 Aug 2003 13:32:09 -0000	1.7
  +++ CommandExecutor.java	3 Sep 2003 13:53:04 -0000	1.8
  @@ -56,8 +56,10 @@
   
   package org.apache.geronimo.twiddle.command;
   
  +import org.apache.commons.lang.StringUtils;
  +
   import org.apache.geronimo.common.NullArgumentException;
  -import org.apache.geronimo.common.Strings;
  +
   import org.apache.geronimo.twiddle.console.IOContext;
   
   /**
  @@ -176,7 +178,7 @@
               throw new NullArgumentException("input");
           }
           
  -        String[] args = Strings.split(input, " ");
  +        String[] args = StringUtils.split(input, " ");
           return execute(args);
       }
       
  @@ -221,7 +223,7 @@
               throw new NullArgumentException("input");
           }
           
  -        String[] args = Strings.split(input, " ");
  +        String[] args = StringUtils.split(input, " ");
           return execute(path, args);
       }
   }
  
  
  

Mime
View raw message