View Javadoc

    1   package baseCode.io;
    2
    3   //import org.apache.commons.lang.time.StopWatch;
    4
    5   /***
    6    * @author Kiran Keshav
    7    * @author Paul Pavlidis
    8    * @version $Id: StringConverter.java,v 1.6 2005/04/08 00:23:42 pavlidis Exp $
    9    */
    10  public class StringConverter {
    11
    12      private String delimiter = "\t"; // it's a regexp.
    13
    14      public void setDelimiter( String delimiter ) {
    15          this.delimiter = delimiter;
    16      }
    17
    18      /***
    19       * @param stringToParse
    20       * @return double[]
    21       */
    22      public double[] StringToDoubles( String stringToParse ) {
    23          if ( stringToParse == null ) return null;
    24          String[] sArray = stringToParse.split( delimiter );
    25          double[] result = new double[sArray.length];
    26          for ( int i = 0; i < sArray.length; i++ ) {
    27              result[i] = Double.parseDouble( sArray[i] );
    28          }
    29
    30          return result;
    31      }
    32
    33      /***
    34       * Convert a double array to a delimited string.
    35       *
    36       * @param arrayToConvert
    37       * @return
    38       */
    39      public String DoubleArrayToString( double[] arrayToConvert ) {
    40          if ( arrayToConvert == null ) return null;
    41          StringBuffer buf = new StringBuffer();
    42          for ( int i = 0; i < arrayToConvert.length; i++ ) {
    43              buf.append( arrayToConvert[i] );
    44              if ( i > 0 ) buf.append( delimiter );
    45          }
    46
    47          return buf.toString();
    48      }
    49
    50      /***
    51       * FIXME this is broken.
    52       *
    53       * @param stringToConvert
    54       * @return byte[]
    55       */
    56      public byte[] StringArrayToBytes( String[] stringsToConvert ) {
    57          if ( stringsToConvert == null ) return null;
    58          for ( int i = 0; i < stringsToConvert.length; i++ ) {
    59              String s = stringsToConvert[i];
    60          }
    61          return null;
    62      }
    63  }