org.joone.util
Class CSVParser

java.lang.Object
  extended by org.joone.util.CSVParser

public class CSVParser
extends java.lang.Object

Comma Separated Values Parser This helper class parses a string containing comma separated tokens. Each token can contain a single value or a range represented by two values separated by a separator.

Author:
pmarrone

Constructor Summary
CSVParser(java.lang.String values)
          Creates a new instance of CSVParser
CSVParser(java.lang.String values, boolean range)
          Creates a new instance of CSVParser
 
Method Summary
static void main(java.lang.String[] args)
          Test
 double[] parseDouble()
          Parse the string and returns an array containing all the values encountered.
 int[] parseInt()
          Parse the string and returns an array containing all the values encountered.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CSVParser

public CSVParser(java.lang.String values)
Creates a new instance of CSVParser

Parameters:
values - The string containing the values to parse

CSVParser

public CSVParser(java.lang.String values,
                 boolean range)
Creates a new instance of CSVParser

Parameters:
values - The string containing the values to parse
range - true (default) if ranges allowed
Method Detail

parseInt

public int[] parseInt()
               throws java.lang.NumberFormatException
Parse the string and returns an array containing all the values encountered. Let we have a string containing: '1,3-5,8,10-12' The method parseInt() will return an array containing: [1,3,4,5,8,10,11,12] WARNING: A RANGE CANNOT CONTAIN NEGATIVE NUMBERS

Returns:
an array of integer containing all the values parsed
Throws:
java.lang.NumberFormatException

parseDouble

public double[] parseDouble()
                     throws java.lang.NumberFormatException
Parse the string and returns an array containing all the values encountered. Let we have a string containing: '1.0,-1.0,0.0' The method parseDouble() will return an array containing: [1.0,-1.0,0.0] WARNING: RANGE NOT ALLOWED, AS IT MAKES NO SENSE IN THIS CASE

Returns:
an array of double containing all the values parsed
Throws:
java.lang.NumberFormatException

main

public static void main(java.lang.String[] args)
Test



Submit Feedback to pmarrone@users.sourceforge.net