package baseCode.io;

//import org.apache.commons.lang.time.StopWatch;

/**
 * @author Kiran Keshav *
 * @author Paul Pavlidis
 * @version $Id$
 */
public class StringConverter {

   private String delimiter = "\t"; // it's a regexp.

   public void setDelimiter( String delimiter ) {
      this.delimiter = delimiter;
   }

   /**
    * @param stringToParse
    * @return double[]
    */
   public double[] StringToDoubles( String stringToParse ) {
      
//      StopWatch stopWatch = new StopWatch();
//      stopWatch.start();
      String[]  sArray = stringToParse.split( delimiter );
      double[] result = new double[sArray.length];
      for ( int i = 0; i < sArray.length; i++ ) {
         result[i] = Double.parseDouble( sArray[i] );
      }

//      stopWatch.stop();
//
//      System.err.println( "StringToDoubles: Total doubles processed = " + result.length + " Time taken = "
//            + stopWatch.getTime() + " ms" );

      return result;
   }

   /**
    * Convert a double array to a delimited string.
    * 
    * @param arrayToConvert
    * @return
    */
   public String DoubleArrayToString( double[] arrayToConvert ) {
      StringBuffer buf = new StringBuffer();

//      StopWatch stopWatch = new StopWatch();
//      stopWatch.start();

      for ( int i = 0; i < arrayToConvert.length; i++ ) {
         buf.append( arrayToConvert[i] );
         if ( i > 0 ) buf.append( delimiter );
      }
//
//      stopWatch.stop();
//
//      System.err.println( "DoubleArrayToString: Total doubles processed = " + arrayToConvert.length + " Time taken = "
//            + stopWatch.getTime() + " ms" );

      return buf.toString();
   }

   /**
    * FIXME this is broken.
    * 
    * @param stringToConvert
    * @return byte[]
    */
   public byte[] StringArrayToBytes( String[] stringsToConvert ) {

      for ( int i = 0; i < stringsToConvert.length; i++ ) {
         String s = stringsToConvert[i];
      }

      return null;

   }
}
@@ -92,18 +92,16 @@
 n Keshav
- *
 %0A * @aut
@@ -174,16 +174,17 @@
 r %7B%0A%0A   
+ 
 private 
@@ -226,24 +226,25 @@
 regexp.%0A%0A   
+ 
 public void 
@@ -284,16 +284,18 @@
 %7B%0A      
+ 
+ 
 this.del
@@ -313,27 +313,29 @@
 limiter;%0A   
+ 
 %7D%0A%0A
+ 
    /**%0A    *
@@ -329,24 +329,25 @@
     /**%0A    
+ 
 * @param str
@@ -357,16 +357,17 @@
 ToParse%0A
+ 
     * @r
@@ -377,35 +377,37 @@
 rn double%5B%5D%0A    
+ 
 */%0A
+ 
    public double
@@ -455,89 +455,11 @@
 ) %7B%0A
+%0A
   
-    %0A//      StopWatch stopWatch = new StopWatch();%0A//      stopWatch.start();%0A
     
@@ -468,17 +468,16 @@
 String%5B%5D
- 
  sArray 
@@ -518,16 +518,18 @@
 ;%0A      
+ 
+ 
 double%5B%5D
@@ -565,16 +565,18 @@
 ength%5D;%0A
+  
       fo
@@ -626,16 +626,19 @@
         
+   
 result%5Bi
@@ -684,197 +684,15 @@
     
-%7D%0A%0A//      stopWatch.stop();%0A//%0A//      System.err.println( %22StringToDoubles: Total doubles processed = %22 + result.length + %22 Time taken = %22%0A//            + stopWatch.getTime() + %22 ms%22 );%0A%0A
+  %7D%0A%0A  
     
@@ -707,27 +707,29 @@
  result;%0A   
+ 
 %7D%0A%0A
+ 
    /**%0A    *
@@ -727,16 +727,17 @@
 /**%0A    
+ 
 * Conver
@@ -776,27 +776,29 @@
 string.%0A    
+ 
 * %0A
+ 
     * @param
@@ -809,32 +809,33 @@
 ayToConvert%0A    
+ 
 * @return%0A    */
@@ -828,27 +828,29 @@
 @return%0A    
+ 
 */%0A
+ 
    public St
@@ -899,24 +899,77 @@
 Convert ) %7B%0A
+        if ( arrayToConvert == null ) return null;%0A  
       String
@@ -1005,84 +1005,10 @@
 ();%0A
-%0A//
   
-    StopWatch stopWatch = new StopWatch();%0A//      stopWatch.start();%0A%0A
     
@@ -1053,32 +1053,35 @@
 length; i++ ) %7B%0A
+   
          buf.app
@@ -1111,24 +1111,27 @@
 );%0A         
+   
 if ( i %3E 0 )
@@ -1166,211 +1166,15 @@
     
-%7D%0A//%0A//      stopWatch.stop();%0A//%0A//      System.err.println( %22DoubleArrayToString: Total doubles processed = %22 + arrayToConvert.length + %22 Time taken = %22%0A//            + stopWatch.getTime() + %22 ms%22 );%0A%0A
+  %7D%0A%0A  
     
@@ -1205,18 +1205,21 @@
 %0A   
+ 
 %7D%0A%0A
+ 
    /**%0A
+ 
     
@@ -1242,27 +1242,29 @@
 broken.%0A    
+ 
 * %0A
+ 
     * @param
@@ -1280,24 +1280,25 @@
 Convert%0A    
+ 
 * @return by
@@ -1306,19 +1306,21 @@
 e%5B%5D%0A    
+ 
 */%0A
+ 
    publi
@@ -1374,25 +1374,79 @@
 Convert ) %7B%0A
-%0A
+        if ( stringsToConvert == null ) return null;%0A  
       for ( 
@@ -1498,24 +1498,27 @@
  %7B%0A         
+   
 String s = s
@@ -1539,27 +1539,30 @@
 t%5Bi%5D;%0A      
-%7D%0A%0A
+  %7D%0A  
       return
@@ -1568,15 +1568,15 @@
 n null;%0A
-%0A
+ 
    %7D%0A%7D

add null checks