public static double [ ] parseCoordinateString ( String coordinatesString , int numberOfCoordinates ) { StringTokenizer stringTokenizer = new StringTokenizer ( coordinatesString , DELIMITER , true ) ; boolean isDelimiter = true ; List < String > tokens = new ArrayList <> ( numberOfCoordinates ) ; while ( stringTokenizer . hasMoreTokens ( ) ) { String token = stringTokenizer . nextToken ( ) ; isDelimiter = ! isDelimiter ; if ( isDelimiter ) { continue ; } tokens . add ( token ) ; } if ( isDelimiter ) { throw new IllegalArgumentException ( "invalid coordinate delimiter: " + coordinatesString ) ; } else if ( tokens . size ( ) != numberOfCoordinates ) { throw new IllegalArgumentException ( "invalid number of coordinate values: " + coordinatesString ) ; } double [ ] coordinates = new double [ numberOfCoordinates ] ; for ( int i = 0 ; i < numberOfCoordinates ; ++ i ) { coordinates [ i ] = Double . parseDouble ( tokens . get ( i ) ) ; } return coordinates ; }
Parses a given number of comma - separated coordinate values from the supplied string .