diff options
| author | Paul Buetow <paul@buetow.org> | 2008-05-26 17:39:03 +0000 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2008-05-26 17:39:03 +0000 |
| commit | d04ee66ac7a02e7e226478bdc0eebdd97f060e14 (patch) | |
| tree | 641362ceaaf0f8814c3d732b5e2d26f7616979a7 /sources/utils/VSTools.java | |
| parent | d0b6e434d76cfea9e3096f0d50706c9a286a4b9d (diff) | |
Vector type introduced @ VSPrefs.
Diffstat (limited to 'sources/utils/VSTools.java')
| -rw-r--r-- | sources/utils/VSTools.java | 49 |
1 files changed, 48 insertions, 1 deletions
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<Integer> parseIntegerVector(String string) + throws exceptions.ParseIntegerVectorException { + System.out.println("parse " + string); + Vector<Integer> vec = new Vector<Integer>(); + + 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; + } } |
