git-svn-id: https://samskivert.googlecode.com/svn/trunk@2261 6335cc39-0255-0410-8fd6-9bcaacd3b74c

This commit is contained in:
andrzej
2007-11-29 02:16:44 +00:00
parent a4931c3af3
commit 1a29ddd025
@@ -934,6 +934,29 @@ public class StringUtil
return vals; return vals;
} }
/**
* Parses an array of doubles from its string representation. The array should be represented
* as a bare list of numbers separated by commas, for example:
*
* <pre>25.0, .5, 1, 0.99</pre>
*
* Any inability to parse the array will result in the function returning null.
*/
public static double[] parseDoubleArray (String source)
{
StringTokenizer tok = new StringTokenizer(source, ",");
double[] vals = new double[tok.countTokens()];
for (int i = 0; tok.hasMoreTokens(); i++) {
try {
// trim the whitespace from the token
vals[i] = Double.parseDouble(tok.nextToken().trim());
} catch (NumberFormatException nfe) {
return null;
}
}
return vals;
}
/** /**
* Parses an array of booleans from its string representation. The array should be represented * Parses an array of booleans from its string representation. The array should be represented
* as a bare list of numbers separated by commas, for example: * as a bare list of numbers separated by commas, for example: