From d04ee66ac7a02e7e226478bdc0eebdd97f060e14 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Mon, 26 May 2008 17:39:03 +0000 Subject: Vector type introduced @ VSPrefs. --- sources/utils/VSTools.java | 49 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) (limited to 'sources/utils/VSTools.java') diff --git a/sources/utils/VSTools.java b/sources/utils/VSTools.java index 3423fe5..ca65fe6 100644 --- a/sources/utils/VSTools.java +++ b/sources/utils/VSTools.java @@ -4,8 +4,8 @@ */ package utils; +import java.util.Vector; -// TODO: Auto-generated Javadoc /** * The Class VSTools. */ @@ -45,4 +45,51 @@ public final class VSTools { return 0; } + + /** + * Gets the integer vector represented by a string comma separated. + * + * @param string the string + * + * @return the parsed vector + */ + public static Vector parseIntegerVector(String string) + throws exceptions.ParseIntegerVectorException { + System.out.println("parse " + string); + Vector vec = new Vector(); + + int index = string.indexOf('['); + if (index == -1) + throw new exceptions.ParseIntegerVectorException(); + + string = string.substring(index+1); + + index = string.indexOf(']'); + if (index == -1) + throw new exceptions.ParseIntegerVectorException(); + + string = string.substring(0, index); + + try { + while ( (index = string.indexOf(',')) != -1 ) { + String substring = string.substring(0, index); + + /* Remove leading whitespaces */ + while (substring.charAt(0) == ' ') + substring = substring.substring(1); + + vec.add(Integer.parseInt(substring)); + string = string.substring(index+1); + } + /* Remove leading whitespaces */ + while (string.charAt(0) == ' ') + string = string.substring(1); + vec.add(Integer.parseInt(string)); + + } catch (StringIndexOutOfBoundsException e) { + } catch (NumberFormatException e) { + } + + return vec; + } } -- cgit v1.2.3