Clover coverage report - Code Coverage for hivemind release 1.0-beta-1
Coverage timestamp: Sat Jul 3 2004 09:41:37 EDT
file stats: LOC: 105   Methods: 3
NCLOC: 50   Classes: 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
StringUtils.java 100% 100% 100% 100%
coverage
 1   
 //  Copyright 2004 The Apache Software Foundation
 2   
 //
 3   
 // Licensed under the Apache License, Version 2.0 (the "License");
 4   
 // you may not use this file except in compliance with the License.
 5   
 // You may obtain a copy of the License at
 6   
 //
 7   
 //     http://www.apache.org/licenses/LICENSE-2.0
 8   
 //
 9   
 // Unless required by applicable law or agreed to in writing, software
 10   
 // distributed under the License is distributed on an "AS IS" BASIS,
 11   
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12   
 // See the License for the specific language governing permissions and
 13   
 // limitations under the License.
 14   
 
 15   
 package org.apache.hivemind.util;
 16   
 
 17   
 import java.util.ArrayList;
 18   
 import java.util.List;
 19   
 
 20   
 /**
 21   
  * A subset of the utilities available in commons-lang StringUtils. It's all
 22   
  * about reducing dependencies, baby!
 23   
  *
 24   
  * @author Howard Lewis Ship
 25   
  */
 26   
 public class StringUtils
 27   
 {
 28   
 
 29   
     /**
 30   
      * Splits an input string into a an array of strings, seperating
 31   
      * at commas.
 32   
      * 
 33   
      * @input the string to split, possibly null or empty
 34   
      * @return an array of the strings split at commas
 35   
      */
 36  150
     public static String[] split(String input)
 37   
     {
 38  150
         if (input == null)
 39  106
             return new String[0];
 40   
 
 41  44
         List strings = new ArrayList();
 42   
 
 43  44
         int startx = 0;
 44  44
         int cursor = 0;
 45  44
         int length = input.length();
 46   
 
 47  44
         while (cursor < length)
 48   
         {
 49  528
             if (input.charAt(cursor) == ',')
 50   
             {
 51  12
                 String item = input.substring(startx, cursor);
 52  12
                 strings.add(item);
 53  12
                 startx = cursor + 1;
 54   
             }
 55   
 
 56  528
             cursor++;
 57   
         }
 58   
 
 59  44
         if (startx < length)
 60  43
             strings.add(input.substring(startx));
 61   
 
 62  44
         return (String[]) strings.toArray(new String[strings.size()]);
 63   
     }
 64   
 
 65   
     /**
 66   
      * Converts a string such that the first character is upper case.
 67   
      * 
 68   
      * @param the input string (possibly empty)
 69   
      * @return the string with the first character converted from lowercase to upper case (may
 70   
      * return the string unchanged if already capitalized)
 71   
      */
 72   
 
 73  7
     public static String capitalize(String input)
 74   
     {
 75  7
         if (input.length() == 0)
 76  1
             return input;
 77   
 
 78  5
         char ch = input.charAt(0);
 79   
 
 80  5
         if (Character.isUpperCase(ch))
 81  1
             return input;
 82   
 
 83  4
         return String.valueOf(Character.toUpperCase(ch)) + input.substring(1);
 84   
     }
 85   
 
 86  7
     public static String join(String[] input, char separator)
 87   
     {
 88  7
         if (input == null || input.length == 0)
 89  2
             return null;
 90   
 
 91  5
         StringBuffer buffer = new StringBuffer();
 92   
 
 93  5
         for (int i = 0; i < input.length; i++)
 94   
         {
 95  9
             if (i > 0)
 96  4
                 buffer.append(separator);
 97   
 
 98  9
             buffer.append(input[i]);
 99   
         }
 100   
 
 101  5
         return buffer.toString();
 102   
     }
 103   
 
 104   
 }
 105