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 2002/07/16 22:07:04 UTC

cvs commit: jakarta-commons-sandbox/lang/src/java/org/apache/commons/lang CharRange.java NumberUtils.java CharSet.java RandomStringUtils.java StringUtils.java ObjectUtils.java NumberRange.java

scolebourne    2002/07/16 13:07:04

  Modified:    lang/src/java/org/apache/commons/lang CharRange.java
                        NumberUtils.java CharSet.java
                        RandomStringUtils.java StringUtils.java
                        ObjectUtils.java NumberRange.java
  Log:
  Javadoc tidy for commons proper
  Formatting tidy for commons proper
  
  Revision  Changes    Path
  1.2       +42 -15    jakarta-commons-sandbox/lang/src/java/org/apache/commons/lang/CharRange.java
  
  Index: CharRange.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/lang/src/java/org/apache/commons/lang/CharRange.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- CharRange.java	5 Jul 2002 06:33:05 -0000	1.1
  +++ CharRange.java	16 Jul 2002 20:07:04 -0000	1.2
  @@ -56,10 +56,11 @@
   
   /**
    * A range of characters. Able to understand the idea of a contiguous 
  - * sublist of an alphbet, a negated concept, and a set of characters.
  - * Used by StringUtil to handle sets of characters.
  + * sublist of an alphabet, a negated concept, and a set of characters.
  + * Used by CharSet to handle sets of characters.
    *
  - * @author bayard@generationjava.com
  + * @author <a href="bayard@generationjava.com">Henri Yandell</a>
  + * @author <a href="mailto:scolebourne@joda.org">Stephen Colebourne</a>
    * @version $Id$
    */
   class CharRange {
  @@ -67,7 +68,7 @@
       /**
        * Used internally to represent null in a char.
        */
  -    static private char UNSET;
  +    private static char UNSET;
   
       private char start;
       private char close;
  @@ -85,8 +86,8 @@
       /**
        * Construct a CharRange over a set of characters.
        *
  -     * @param start char start character in this range. inclusive
  -     * @param close char close character in this range. inclusive
  +     * @param start  char start character in this range. inclusive
  +     * @param close  char close character in this range. inclusive
        */
       public CharRange(char start, char close) {
           this.start = start;
  @@ -96,8 +97,8 @@
       /**
        * Construct a CharRange over a set of characters.
        *
  -     * @param start String start first character is in this range (inclusive).
  -     * @param close String first character is close character in this
  +     * @param start  String start first character is in this range (inclusive).
  +     * @param close  String first character is close character in this
        * range (inclusive).
        */
       public CharRange(String start, String close) {
  @@ -105,18 +106,38 @@
           this.close = close.charAt(0);
       }
   
  +    /**
  +     * Get the start character for this character range
  +     * 
  +     * @return start char (inclusive)
  +     */
       public char getStart() {
           return this.start;
       }
   
  +    /**
  +     * Get the end character for this character range
  +     * 
  +     * @return end char (inclusive)
  +     */
       public char getEnd() {
           return this.close;
       }
   
  +    /**
  +     * Set the start character for this character range
  +     * 
  +     * @param ch  start char (inclusive)
  +     */
       public void setStart(char ch) {
           this.start = ch;
       }
   
  +    /**
  +     * Set the end character for this character range
  +     * 
  +     * @param ch  start char (inclusive)
  +     */
       public void setEnd(char ch) {
           this.close = ch;
       }
  @@ -144,7 +165,7 @@
       }
   
       /**
  -     * Is this CharRange negated
  +     * Checks if this CharRange is negated.
        *
        * @return boolean true is negated
        */
  @@ -153,14 +174,21 @@
       }
   
       /**
  -     * Make this character range be negated. 
  +     * Sets this character range to be negated or not. 
        * This implies that this CharRange is over all characters except 
        * the ones in this range.
  +     * 
  +     * @param negated  true to negate the range
        */
  -    public void setNegated(boolean b) {
  -        this.negated = b;
  +    public void setNegated(boolean negated) {
  +        this.negated = negated;
       }
   
  +    /**
  +     * Output a string representation of the character range
  +     * 
  +     * @return string representation
  +     */
       public String toString() {
           String str = "";
           if(isNegated()) {
  @@ -173,6 +201,5 @@
           }
           return str;
       }
  +    
   }
  -
  -
  
  
  
  1.2       +8 -2      jakarta-commons-sandbox/lang/src/java/org/apache/commons/lang/NumberUtils.java
  
  Index: NumberUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/lang/src/java/org/apache/commons/lang/NumberUtils.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- NumberUtils.java	16 Jul 2002 02:00:28 -0000	1.1
  +++ NumberUtils.java	16 Jul 2002 20:07:04 -0000	1.2
  @@ -77,7 +77,7 @@
       }
   
       /**
  -     * Convert a String to an Int, returning a default value if the 
  +     * Convert a String to an int, returning a default value if the 
        * conversion fails.
        * 
        * @param str  the string to convert
  @@ -317,6 +317,7 @@
        * 
        * @param val  a String to convert
        * @return converted Float
  +     * @throws NumberFormatException if the value cannot be converted
        */
       public static Float createFloat(String val) {
           return Float.valueOf(val);
  @@ -327,6 +328,7 @@
        * 
        * @param val  a String to convert
        * @return converted Double
  +     * @throws NumberFormatException if the value cannot be converted
        */
       public static Double createDouble(String val) {
           return Double.valueOf(val);
  @@ -338,6 +340,7 @@
        * 
        * @param val  a String to convert
        * @return converted Integer
  +     * @throws NumberFormatException if the value cannot be converted
        */
       public static Integer createInteger(String val) {
           // decode() handles 0xAABD and 0777 (hex and octal) as well.
  @@ -349,6 +352,7 @@
        * 
        * @param val  a String to convert
        * @return converted Long
  +     * @throws NumberFormatException if the value cannot be converted
        */
       public static Long createLong(String val) {
           return Long.valueOf(val);
  @@ -359,6 +363,7 @@
        * 
        * @param val  a String to convert
        * @return converted BigInteger
  +     * @throws NumberFormatException if the value cannot be converted
        */
       public static BigInteger createBigInteger(String val) {
           BigInteger bi = new BigInteger(val);
  @@ -370,6 +375,7 @@
        * 
        * @param val  a String to convert
        * @return converted BigDecimal
  +     * @throws NumberFormatException if the value cannot be converted
        */
       public static BigDecimal createBigDecimal(String val) {
           BigDecimal bd = new BigDecimal(val);
  
  
  
  1.4       +78 -33    jakarta-commons-sandbox/lang/src/java/org/apache/commons/lang/CharSet.java
  
  Index: CharSet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/lang/src/java/org/apache/commons/lang/CharSet.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- CharSet.java	5 Jul 2002 06:57:35 -0000	1.3
  +++ CharSet.java	16 Jul 2002 20:07:04 -0000	1.4
  @@ -57,16 +57,38 @@
   import java.util.Iterator;
   import java.util.List;
   import java.util.LinkedList;
  -
   /**
    * A set of characters. You can iterate over the characters in the 
  - * set. Also provided
  + * set. Also provided are numerous routines to manipulate a character set.
    *
  - * @author bayard@generationjava.com
  + * @author <a href="bayard@generationjava.com">Henri Yandell</a>
  + * @author <a href="mailto:scolebourne@joda.org">Stephen Colebourne</a>
    * @version $Id$
    */
   public class CharSet {
   
  +    /**
  +     * Creates a CharSet object which allows a certain amount of 
  +     * set logic to be performed upon the following syntax:
  +     *
  +     * "aeio" which implies 'a','e',..
  +     * "^e" implies not e. However it only negates, it's not 
  +     * a set in itself due to the size of that set in unicode.
  +     * "ej-m" implies e,j->m. e,j,k,l,m.
  +     */
  +    public static CharSet evaluateSet(String[] set) {
  +        return new CharSet(set); 
  +    }
  +
  +    /**
  +     * Squeezes any repititions of a character that is mentioned in the 
  +     * supplied set. An example is:
  +     *    squeeze("hello", "el")  => "helo"
  +     * See evaluateSet for set-syntax.
  +     * 
  +     * @param str  the string to work from
  +     * @param set  the character set to use for manipulation
  +     */
       public static String squeeze(String str, String set) {
           String[] strs = new String[1];
           strs[0] = set;
  @@ -78,6 +100,9 @@
        * supplied set. An example is:
        *    squeeze("hello", {"el"})  => "helo"
        * See evaluateSet for set-syntax.
  +     * 
  +     * @param str  the string to work from
  +     * @param set  the character set to use for manipulation
        */
       public static String squeeze(String str, String[] set) {
           CharSet chars = evaluateSet(set);
  @@ -86,10 +111,10 @@
           int sz = chrs.length;
           char lastChar = ' ';
           char ch = ' ';
  -        for(int i=0; i<sz; i++) {
  +        for (int i = 0; i < sz; i++) {
               ch = chrs[i];
  -            if(chars.contains(ch)) {
  -                if( (ch == lastChar) && (i != 0) ) {
  +            if (chars.contains(ch)) {
  +                if ((ch == lastChar) && (i != 0)) {
                       continue;
                   }
               }
  @@ -100,30 +125,26 @@
       }
   
       /**
  -     * Creates a CharSet object which allows a certain amount of 
  -     * set logic to be performed upon the following syntax:
  +     * Takes an argument in set-syntax, see evaluateSet,
  +     * and returns the number of characters present in the specified string.
  +     * An example would be:   count("hello", {"c-f","o"}) returns 2.
        *
  -     * "aeio" which implies 'a','e',..
  -     * "^e" implies not e. However it only negates, it's not 
  -     * a set in itself due to the size of that set in unicode.
  -     * "ej-m" implies e,j->m. e,j,k,l,m.
  +     * @param str  String target to count characters in
  +     * @param set  String set of characters to count
        */
  -    public static CharSet evaluateSet(String[] set) {
  -        return new CharSet(set); 
  -    }
  -
       public static int count(String str, String set) {
           String[] strs = new String[1];
           strs[0] = set;
           return count(str, strs);
       }
  +    
       /**
        * Takes an argument in set-syntax, see evaluateSet,
        * and returns the number of characters present in the specified string.
        * An example would be:   count("hello", {"c-f","o"}) returns 2.
        *
  -     * @param str String target to count characters in
  -     * @param str String[] set of characters to count
  +     * @param str  String target to count characters in
  +     * @param set  String[] set of characters to count
        */
       public static int count(String str, String[] set) {
           CharSet chars = evaluateSet(set);
  @@ -138,18 +159,27 @@
           return count;
       }
   
  +    /**
  +     * Takes an argument in set-syntax, see evaluateSet,
  +     * and deletes any of characters present in the specified string.
  +     * An example would be:   delete("hello", {"c-f","o"}) returns "hll"
  +     *
  +     * @param str  String target to delete characters from
  +     * @param set  String set of characters to delete
  +     */
       public static String delete(String str, String set) {
           String[] strs = new String[1];
           strs[0] = set;
           return delete(str, strs);
       }
  +    
       /**
        * Takes an argument in set-syntax, see evaluateSet,
        * and deletes any of characters present in the specified string.
        * An example would be:   delete("hello", {"c-f","o"}) returns "hll"
        *
  -     * @param str String target to delete characters from
  -     * @param str String[] set of characters to delete
  +     * @param str  String target to delete characters from
  +     * @param set  String[] set of characters to delete
        */
       public static String delete(String str, String[] set) {
           CharSet chars = evaluateSet(set);
  @@ -196,27 +226,35 @@
           return buffer.toString();
       }
   
  -    // used to be a com.generationjava.collections.typed.TypedList
       private LinkedList set = new LinkedList();
   
  -    public CharSet(String[] set) {
  +    /**
  +     * Restricted consructor. Use the factory method evaluateSet().
  +     */
  +    protected CharSet(String[] set) {
           int sz = set.length;
  -        for(int i=0; i<sz; i++) {
  +        for (int i = 0; i < sz; i++) {
               add(set[i]);
           }
       }
   
  +    /**
  +     * Does the set contain the character specified
  +     * 
  +     * @param ch  the character to check for
  +     * @return true if it does contain it
  +     */
       public boolean contains(char ch) {
           Iterator iterator = set.iterator();
           boolean bool = false;
  -        while(iterator.hasNext()) {
  -            CharRange range = (CharRange)iterator.next();
  -            if(range.isNegated()) {
  -                if(!range.inRange(ch)) {
  +        while (iterator.hasNext()) {
  +            CharRange range = (CharRange) iterator.next();
  +            if (range.isNegated()) {
  +                if (!range.inRange(ch)) {
                       bool = true;
                   }
               } else {
  -                if(range.inRange(ch)) {
  +                if (range.inRange(ch)) {
                       bool = true;
                   }
               }
  @@ -224,7 +262,12 @@
           return bool;
       }
   
  -    public void add(String str) {
  +    /**
  +     * Add a set definition string to the set
  +     * 
  +     * @param str  set definition string
  +     */
  +    protected void add(String str) {
           int sz = str.length();
           CharRange range = null;
   
  @@ -256,11 +299,13 @@
           }
       }
   
  +    /**
  +     * Returns a string representation of the set
  +     * 
  +     * @return string representation
  +     */
       public String toString() {
           return set.toString();
       }
   
   }
  -
  -
  -
  
  
  
  1.2       +5 -5      jakarta-commons-sandbox/lang/src/java/org/apache/commons/lang/RandomStringUtils.java
  
  Index: RandomStringUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/lang/src/java/org/apache/commons/lang/RandomStringUtils.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- RandomStringUtils.java	16 Jul 2002 02:00:28 -0000	1.1
  +++ RandomStringUtils.java	16 Jul 2002 20:07:04 -0000	1.2
  @@ -68,17 +68,17 @@
    * @author <a href="mailto:bayard@generationjava.com">Bayard</a>
    * @author <a href="mailto:ed@apache.org">Ed Korthof</a>
    * @author <a href="mailto:steven@caswell.name">Steven Caswell</a>
  + * @author <a href="mailto:scolebourne@joda.org">Stephen Colebourne</a>
    * @version $Id$
    */
  -public class RandomStringUtils
  -{
  +public class RandomStringUtils {
   
       /**
        * Random object used by random method. This has to be not local 
        * to the random method so as to not return the same value in the 
        * same millisecond. 
        */
  -    private static Random RANDOM = new Random();
  +    private static final Random RANDOM = new Random();
   
       /**
        * Prevent construction of RandomStringUtils instances
  @@ -248,6 +248,6 @@
        * @return the random string
        */
       public static String random(int count, char[] set) {
  -        return random(count,0,set.length-1,false,false,set);
  +        return random(count, 0, set.length - 1, false, false, set);
       }
   }
  
  
  
  1.3       +161 -125  jakarta-commons-sandbox/lang/src/java/org/apache/commons/lang/StringUtils.java
  
  Index: StringUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/lang/src/java/org/apache/commons/lang/StringUtils.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- StringUtils.java	16 Jul 2002 02:12:03 -0000	1.2
  +++ StringUtils.java	16 Jul 2002 20:07:04 -0000	1.3
  @@ -89,6 +89,12 @@
        */
       public static int CHAR_BUFFER_SIZE = 4 * 1024;
       
  +    /**
  +     * Prevent construction of StringUtils instances
  +     */
  +    private StringUtils() {
  +    }
  +
       // Empty
       //--------------------------------------------------------------------------
   
  @@ -140,26 +146,26 @@
       //--------------------------------------------------------------------------
   
       /**
  -     * Compares two StringUtils, returning true if they are equal.
  +     * Compares two Strings, returning true if they are equal.
        * Nulls are handled without exceptions. Two <code>null</code>
        * references are considered equal. Comparison is case sensitive.
        *
        * @param str1  the first string
        * @param str2  the second string
  -     * @return true if the StringUtils are equal, case sensitive, or both null
  +     * @return true if the Strings are equal, case sensitive, or both null
        */
       public static boolean equals(String str1, String str2) {
           return (str1 == null ? str2 == null : str1.equals(str2));
       }
   
       /**
  -     * Compares two StringUtils, returning true if they are equal ignoring case.
  +     * Compares two Strings, returning true if they are equal ignoring case.
        * Nulls are handled without exceptions. Two <code>null</code>
        * references are considered equal. Comparison is case insensitive.
        *
        * @param str1  the first string
        * @param str2  the second string
  -     * @return true if the StringUtils are equal, case insensitive, or both null
  +     * @return true if the Strings are equal, case insensitive, or both null
        */
       public static boolean equalsIgnoreCase(String str1, String str2) {
           return (str1 == null ? str2 == null : str1.equalsIgnoreCase(str2));
  @@ -380,10 +386,9 @@
        * The separator is not included in the returned String array.
        *
        * @param str  the string to parse
  -     * @return an array of parsed StringUtils 
  +     * @return an array of parsed Strings 
        */
  -    public static String[] split(String text)
  -    {
  +    public static String[] split(String text) {
           return split(text, null, -1);
       }
   
  @@ -395,10 +400,9 @@
        * @param str  the string to parse
        * @param separator  The separator character. If <code>null</code>, splits
        *  on whitespace.
  -     * @return an array of parsed StringUtils 
  +     * @return an array of parsed Strings 
        */
  -    public static String[] split(String text, String separator)
  -    {
  +    public static String[] split(String text, String separator) {
           return split(text, separator, -1);
       }
   
  @@ -413,10 +417,9 @@
        *  on whitespace.
        * @param max  The maximum number of elements to include in the
        *  list.  A zero or negative value implies no limit.
  -     * @return an array of parsed StringUtils 
  +     * @return an array of parsed Strings 
        */
  -    public static String[] split(String text, String separator, int max)
  -    {
  +    public static String[] split(String text, String separator, int max) {
           StringTokenizer tok = null;
           if (separator == null) {
               // Null separator means we're using StringTokenizer's default
  @@ -468,8 +471,7 @@
        * @param separator  the separator character to use
        * @return the joined String
        */
  -    public static String join(Object[] array, String separator)
  -    {
  +    public static String join(Object[] array, String separator) {
           if (separator == null) {
               separator = "";
           }
  @@ -497,8 +499,7 @@
        * @param separator  the separator character to use
        * @return the joined String
        */
  -    public static String join(Iterator iterator, String separator)
  -    {
  +    public static String join(Iterator iterator, String separator) {
           if (separator == null) {
               separator = "";
           }
  @@ -521,17 +522,25 @@
        * Replace a string with another string inside a larger string, once.
        *
        * @see #replace(String text, String repl, String with, int max)
  +     * @param text  text to search and replace in
  +     * @param repl  String to search for
  +     * @param with  String to replace with
  +     * @return the text with any replacements processed
        */
  -    public static String replaceOnce(String text, String repl, String with)
  -    {
  +    public static String replaceOnce(String text, String repl, String with) {
           return replace(text, repl, with, 1);
       }
   
       /**
  +     * Replace all occurances of a string within another string.
  +     *
        * @see #replace(String text, String repl, String with, int max)
  +     * @param text  text to search and replace in
  +     * @param repl  String to search for
  +     * @param with  String to replace with
  +     * @return the text with any replacements processed
        */
  -    public static String replace(String text, String repl, String with)
  -    {
  +    public static String replace(String text, String repl, String with) {
           return replace(text, repl, with, -1);
       }
   
  @@ -541,32 +550,26 @@
        * <code>null</code> reference is passed to this method is a
        * no-op.
        *
  -     * @param text Text to search and replace in.
  -     * @param repl String to search for
  -     * @param with String to replace with
  -     * @param max Maximum number of values to replace, or
  -     * <code>-1</code> if no maximum.
  -     * @return The text with any replacements processed.
  +     * @param text  text to search and replace in
  +     * @param repl  String to search for
  +     * @param with  String to replace with
  +     * @param max  maximum number of values to replace, or
  +     * <code>-1</code> if no maximum
  +     * @return the text with any replacements processed
        */
       public static String replace(String text, String repl, String with,
  -                                 int max)
  -    {
  -        if (text == null)
  -        {
  +                                 int max) {
  +        if (text == null) {
               return null;
           }
   
           StringBuffer buf = new StringBuffer(text.length());
           int start = 0, end = 0;
  -        while ( (end = text.indexOf(repl, start)) != -1 )
  -        {
  -            //System.err.println("end=" + end);
  +        while ( (end = text.indexOf(repl, start)) != -1 ) {
               buf.append(text.substring(start, end)).append(with);
               start = end + repl.length();
  -            //System.err.println("new start=" + start);
   
  -            if (--max == 0)
  -            {
  +            if (--max == 0) {
                   break;
               }
           }
  @@ -581,7 +584,6 @@
        * @param overlay String to overlay
        * @param start int to start overlaying at
        * @param end   int to stop overlaying before
  -     *
        * @return String with overlayed text
        */
       public static String overlayString(String text, String overlay, int start, int end) {
  @@ -599,33 +601,31 @@
        * Center a string in a larger string of size n.
        * Uses spaces as the value to buffer the string with..
        *
  -     * @param str String to center
  -     * @param n   int    size of new String
  -     *
  +     * @param str  String to center
  +     * @param size  int size of new String
        * @return String containing centered String
        */
  -    public static String center(String str, int n) {
  -        return center(str, n, " ");
  +    public static String center(String str, int size) {
  +        return center(str, size, " ");
       }
   
       /**
        * Center a string in a larger string of size n.
        * Uses a supplied String as the value to buffer the string with..
        *
  -     * @param str String to center
  -     * @param n   int    size of new String
  -     * @param delim String to buffer the new String with
  -     *
  +     * @param str  String to center
  +     * @param size  int size of new String
  +     * @param delim  String to buffer the new String with
        * @return String containing centered String
        */
  -    public static String center(String str, int n, String delim) {
  +    public static String center(String str, int size, String delim) {
           int sz = str.length();
  -        int p = n-sz;
  -        if(p < 1) {
  +        int p = size - sz;
  +        if (p < 1) {
               return str;
           }
  -        str = leftPad(str,sz+p/2, delim);
  -        str = rightPad(str, n, delim);
  +        str = leftPad(str, sz + p / 2, delim);
  +        str = rightPad(str, size, delim);
           return str;
       }
   
  @@ -635,8 +635,7 @@
       /** 
        * Remove the last newline, and everything after it from a String.
        *
  -     * @param str String to chomp the newline from
  -     *
  +     * @param str  String to chomp the newline from
        * @return String without chomped newline
        */
       public static String chomp(String str) {
  @@ -647,14 +646,13 @@
        * Remove the last value of a supplied String, and everything after it 
        * from a String.
        *
  -     * @param str String to chomp from
  -     * @param sep String to chomp
  -     *
  +     * @param str  String to chomp from
  +     * @param sep  String to chomp
        * @return String without chomped ending
        */
       public static String chomp(String str, String sep) {
           int idx = str.lastIndexOf(sep);
  -        if(idx != -1) {
  +        if (idx != -1) {
               return str.substring(0,idx);
           } else {
               return str;
  @@ -664,17 +662,28 @@
       /**
        * Remove a newline if and only if it is at the end 
        * of the supplied string.
  +     * 
  +     * @param str  String to chomp from
  +     * @return String without chomped ending
        */
       public static String chompLast(String str) {
           return chompLast(str, "\n");
       }
  +    
  +    /**
  +     * Remove a value if and only if the string ends with that value.
  +     * 
  +     * @param str  String to chomp from
  +     * @param sep  String to chomp
  +     * @return String without chomped ending
  +     */
       public static String chompLast(String str, String sep) {
  -        if(str.length() == 0) {
  +        if (str.length() == 0) {
               return str;
           }
           String sub = str.substring(str.length() - sep.length());
  -        if(sep.equals(sub)) {
  -            return str.substring(0,str.length()-sep.length());
  +        if (sep.equals(sub)) {
  +            return str.substring(0, str.length() - sep.length());
           } else {
               return str;
           }
  @@ -686,15 +695,13 @@
        *
        * @param str String to chomp from
        * @param sep String to chomp
  -     *
        * @return String chomped
        */
       public static String getChomp(String str, String sep) {
           int idx = str.lastIndexOf(sep);
  -        if(idx == str.length()-sep.length()) {
  +        if (idx == str.length() - sep.length()) {
               return sep;
  -        } else
  -        if(idx != -1) {
  +        } else if (idx != -1) {
               return str.substring(idx);
           } else {
               return "";
  @@ -707,13 +714,12 @@
        *
        * @param str String to chomp from
        * @param sep String to chomp
  -     *
        * @return String without chomped beginning
        */
       public static String prechomp(String str, String sep) {
           int idx = str.indexOf(sep);
  -        if(idx != -1) {
  -            return str.substring(idx+sep.length());
  +        if (idx != -1) {
  +            return str.substring(idx + sep.length());
           } else {
               return str;
           }
  @@ -725,13 +731,12 @@
        *
        * @param str String to chomp from
        * @param sep String to chomp
  -     *
        * @return String prechomped
        */
       public static String getPrechomp(String str, String sep) {
           int idx = str.indexOf(sep);
  -        if(idx != -1) {
  -            return str.substring(0,idx+sep.length());
  +        if (idx != -1) {
  +            return str.substring(0, idx + sep.length());
           } else {
               return "";
           }
  @@ -745,22 +750,21 @@
        * ends in \r\n, then remove both of them.
        *
        * @param str String to chop last character from
  -     *
        * @return String without last character
        */
       public static String chop(String str) {
  -        if("".equals(str)) {
  +        if ("".equals(str)) {
               return "";
           }
  -        if(str.length() == 1) {
  +        if (str.length() == 1) {
               return "";
           }
  -        int lastIdx = str.length()-1;
  -        String ret = str.substring(0,lastIdx);
  +        int lastIdx = str.length() - 1;
  +        String ret = str.substring(0, lastIdx);
           char last = str.charAt(lastIdx);
  -        if(last == '\n') {
  -            if(ret.charAt(lastIdx-1) == '\r') {
  -                return ret.substring(0,lastIdx-1);
  +        if (last == '\n') {
  +            if (ret.charAt(lastIdx - 1) == '\r') {
  +                return ret.substring(0, lastIdx - 1);
               }
           }
           return ret;
  @@ -771,8 +775,8 @@
        * If a \r precedes it, then remove that too.
        *
        * @param str String to chop a newline from
  -     *
        * @param String without newline on end
  +     * @return String without newline
        */
       public static String chopNewline(String str) {
           int lastIdx = str.length()-1;
  @@ -877,14 +881,13 @@
       /**
        * Repeat a string n times to form a new string.
        *
  -     * @param str String to repeat
  -     * @param n   int    number of times to repeat
  -     *
  +     * @param str  String to repeat
  +     * @param repeat  int number of times to repeat
        * @return String with repeated string
        */
  -    public static String repeat(String str, int n) {
  -        StringBuffer buffer = new StringBuffer(n*str.length());
  -        for(int i=0; i<n; i++) {
  +    public static String repeat(String str, int repeat) {
  +        StringBuffer buffer = new StringBuffer(repeat * str.length());
  +        for (int i = 0; i < repeat; i++) {
               buffer.append(str);
           }
           return buffer.toString();
  @@ -892,42 +895,50 @@
   
       /**
        * Right pad a String with spaces. Pad to a size of n.
  +     * 
  +     * @param str  String to repeat
  +     * @param size  int number of times to repeat
  +     * @return String with repeated string
        */
  -    public static String rightPad(String str, int n) {
  -        return rightPad(str, n, " ");
  +    public static String rightPad(String str, int size) {
  +        return rightPad(str, size, " ");
       }
  +    
       /**
        * Right pad a String with a specified string. Pad to a size of n.
        *
  -     * @param str   String to pad out
  -     * @param n     int    size to pad to
  -     * @param delim String to pad with
  -     */
  -    public static String rightPad(String str, int n, String delim) {
  -        n = (n - str.length())/delim.length();
  -        if(n > 0) {
  -            str += repeat(delim,n);
  +     * @param str  String to pad out
  +     * @param size  int size to pad to
  +     * @param delim  String to pad with
  +     */
  +    public static String rightPad(String str, int size, String delim) {
  +        size = (size - str.length()) / delim.length();
  +        if (size > 0) {
  +            str += repeat(delim, size);
           }
           return str;
       }
   
       /**
        * Left pad a String with spaces. Pad to a size of n.
  +     *
  +     * @param str  String to pad out
  +     * @param size  int size to pad to
        */
  -    public static String leftPad(String str, int n) {
  -        return leftPad(str, n, " ");
  +    public static String leftPad(String str, int size) {
  +        return leftPad(str, size, " ");
       }
       /**
        * Left pad a String with a specified string. Pad to a size of n.
        *
  -     * @param str   String to pad out
  -     * @param n     int    size to pad to
  -     * @param delim String to pad with
  -     */
  -    public static String leftPad(String str, int n, String delim) {
  -        n = (n - str.length())/delim.length();
  -        if(n > 0) {
  -            str = repeat(delim,n) + str;
  +     * @param str  String to pad out
  +     * @param size  int size to pad to
  +     * @param delim  String to pad with
  +     */
  +    public static String leftPad(String str, int size, String delim) {
  +        size = (size - str.length()) / delim.length();
  +        if (size > 0) {
  +            str = repeat(delim, size) + str;
           }
           return str;
       }
  @@ -937,6 +948,9 @@
       
       /**
        * Remove whitespace from the front and back of a String.
  +     * 
  +     * @param str  the string to remove whitespace from
  +     * @return the stripped string
        */
       public static String strip(String str) {
           return strip(str, null);
  @@ -945,6 +959,10 @@
        * Remove a specified String from the front and back of a 
        * String. If Whitespace is wanted to be removed, used the 
        * strip(String) method.
  +     * 
  +     * @param str  the string to remove a string from
  +     * @param delim  the string to remove at start and end
  +     * @return the stripped string
        */
       public static String strip(String str, String delim) {
           str = stripStart(str, delim);
  @@ -954,6 +972,9 @@
       /**
        * Strip whitespace from the front and back of every string
        * in the array.
  +     * 
  +     * @param strs  the strings to remove whitespace from
  +     * @return the stripped strings
        */
       public static String[] stripAll(String[] strs) {
           return stripAll(strs, null);
  @@ -962,45 +983,60 @@
       /**
        * Strip the specified delimiter from the front and back of
        * every String in the array.
  +     * 
  +     * @param strs  the strings to remove a string from
  +     * @param delim  the string to remove at start and end
  +     * @return the stripped strings
        */
       public static String[] stripAll(String[] strs, String delimiter) {
  -        if( (strs == null) || (strs.length == 0) ) {
  +        if ((strs == null) || (strs.length == 0)) {
               return strs;
           }
           int sz = strs.length;
           String[] newArr = new String[sz];
  -        for(int i=0; i<sz; i++) {
  +        for (int i = 0; i < sz; i++) {
               newArr[i] = strip(strs[i], delimiter);
           }
           return newArr;
       }   
   
       /**
  -     * Strip any of a supplied substring from the end of a String..
  +     * Strip any of a supplied string (first letter) from the end of a String..
  +     * If the strip string is null, whitespace is stripped.
  +     * 
  +     * @param str  the string to remove characters from
  +     * @param strip  the string to remove
  +     * @return the stripped string
        */
  -    public static String stripEnd(String str, String ch) {
  -        if(str == null) {
  +    public static String stripEnd(String str, String strip) {
  +        if (str == null) {
               return null;
           }
           int end = str.length();
    
  -        if(ch == null) {
  -            while( (end != 0) && Character.isWhitespace( str.charAt(end-1) ) ) {                end--;
  +        if (strip == null) {
  +            while ((end != 0) && Character.isWhitespace(str.charAt(end - 1))) {
  +                end--;
               }
           } else {
  -            char chr = ch.charAt(0);
  -            while( (end != 0) && (str.charAt(end-1) == chr) ) {
  +            char chr = strip.charAt(0);
  +            while ((end != 0) && (str.charAt(end - 1) == chr)) {
                   end--;
               }
  -        }      
  +        }
           return str.substring(0, end);
       }
   
       /**
  -     * Strip any of a supplied substring from the start of a String..
  +     * Strip any of a supplied string (first letter) from the start of a String.
  +     * If the strip string is null, whitespace is stripped.
  +     * 
  +     * @param str  the string to remove characters from
  +     * @param strip  the string to remove
  +     * @return the stripped string
        */
  -    public static String stripStart(String str, String ch) {
  -        if(str == null) {
  +    public static String stripStart(String str, String strip) {
  +        if (str == null) {
               return null;
           }
    
  @@ -1008,17 +1044,17 @@
    
           int sz = str.length();
    
  -        if(ch == null) {
  -            while( (start != sz) && Character.isWhitespace( str.charAt(start) ) ) {
  +        if (strip == null) {
  +            while ((start != sz) && Character.isWhitespace(str.charAt(start))) {
                   start++;
               }
           } else {
  -            char chr = ch.charAt(0);
  -            while( (start != sz) && (str.charAt(start) == chr ) ) {
  +            char chr = strip.charAt(0);
  +            while ((start != sz) && (str.charAt(start) == chr)) {
                   start++;
               }
           }
  -        return str.substring(start);     
  +        return str.substring(start);
       }
   
       // Case conversion
  
  
  
  1.2       +7 -1      jakarta-commons-sandbox/lang/src/java/org/apache/commons/lang/ObjectUtils.java
  
  Index: ObjectUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/lang/src/java/org/apache/commons/lang/ObjectUtils.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ObjectUtils.java	16 Jul 2002 02:00:28 -0000	1.1
  +++ ObjectUtils.java	16 Jul 2002 20:07:04 -0000	1.2
  @@ -66,6 +66,12 @@
   public class ObjectUtils {
       
       /**
  +     * Prevent construction of ObjectUtils instances
  +     */
  +    private ObjectUtils() {
  +    }
  +
  +    /**
        * Returns a default value if the object passed is null.
        *
        * @param object  the object to test.
  
  
  
  1.3       +6 -15     jakarta-commons-sandbox/lang/src/java/org/apache/commons/lang/NumberRange.java
  
  Index: NumberRange.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/lang/src/java/org/apache/commons/lang/NumberRange.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- NumberRange.java	5 Jul 2002 06:33:51 -0000	1.2
  +++ NumberRange.java	16 Jul 2002 20:07:04 -0000	1.3
  @@ -58,9 +58,9 @@
    * Represents a range of {@link Number} objects.
    *
    * @author <a href="mailto:chrise@esha.com">Christopher Elkins</a>
  + * @author <a href="mailto:scolebourne@joda.org">Stephen Colebourne</a>
    * @version $Revision$ $Date$
    */
  -
   public final class NumberRange {
   
   
  @@ -83,10 +83,10 @@
               throw new NullPointerException("num cannot be null");
           }
   
  -        this.min = this.max = num;
  +        this.min = num;
  +        this.max = num;
       }
   
  -
       /**
        * Constructs a new instance with the specified minimum and maximum
        * numbers.
  @@ -111,7 +111,6 @@
           }
       }
   
  -
       /**
        * Returns the minimum number in this range.
        *
  @@ -121,7 +120,6 @@
           return min;
       }
   
  -
       /**
        * Returns the maximum number in this range.
        *
  @@ -131,7 +129,6 @@
           return min;
       }
   
  -
       /**
        * Tests whether the specified number occurs within this range.
        *
  @@ -148,7 +145,6 @@
           }
       }
   
  -
       /**
        * Tests whether the specified range occurs entirely within this range.
        *
  @@ -164,7 +160,6 @@
           }
       }
   
  -
       /**
        * Tests whether the specified range overlaps with this range.
        *
  @@ -181,7 +176,6 @@
           }
       }
   
  -
       /**
        * Indicates whether some other object is "equal" to this one.
        *
  @@ -200,7 +194,6 @@
           }
       }
   
  -
       /**
        * Returns a hash code value for this object.
        *
  @@ -208,12 +201,11 @@
        */
       public int hashCode() {
           int result = 17;
  -        result = 37*result + min.hashCode();
  -        result = 37*result + max.hashCode();
  +        result = 37 * result + min.hashCode();
  +        result = 37 * result + max.hashCode();
           return result;
       }
   
  -
       /**
        * Returns the string representation of this range. This string is the
        * string representation of the minimum and maximum numbers in the range,
  @@ -245,6 +237,5 @@
   
           return sb.toString();
       }
  -
   
   }
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>