org.joone.util
Class CSVParser
- java.lang.Object
-
- org.joone.util.CSVParser
-
public class CSVParser extends java.lang.ObjectComma 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.
-
-
Constructor Summary
Constructors Constructor and Description CSVParser(java.lang.String values)Creates a new instance of CSVParserCSVParser(java.lang.String values, boolean range)Creates a new instance of CSVParser
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description static voidmain(java.lang.String[] args)Testdouble[]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.
-
-
-
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 parserange- true (default) if ranges allowed
-
-
Method Detail
-
parseInt
public int[] parseInt() throws java.lang.NumberFormatExceptionParse 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.NumberFormatExceptionParse 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
-
-
DataMelt 3.0 © DataMelt by jWork.ORG