dirk_krause.jtools
Class StringTool

java.lang.Object
  extended by dirk_krause.jtools.StringTool

public class StringTool
extends java.lang.Object

The static methods of the StringTool class can be used to convert strings to integer, colors and booleans.


Field Summary
static java.lang.String[] theBooleanStrings
          Strings which can be converted into booleans.
 
Constructor Summary
StringTool()
           
 
Method Summary
static int getArrayIndex(java.lang.String[] a, java.lang.String s)
          Find index of string s in array a.
static boolean getBoolean(java.lang.String s, boolean d)
          Convert a string into a boolean.
static java.awt.Color getColor(java.lang.String s)
          Convert a String into a color.
static java.awt.Color getColor(java.lang.String s, int dr, int dg, int db)
          Convert string into a color.
static int getIntValue(java.lang.String s)
          Parse string for integer value.
static int getIntValue(java.lang.String s, int d)
          Parse string for integer value.
static int getStartArrayIndex(java.lang.String[] a, java.lang.String s)
          Check whether or not the string s starts with one of the strings from the array a.
static boolean isBoolean(java.lang.String s)
          Check whether or not a string represents a boolean.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

theBooleanStrings

public static final java.lang.String[] theBooleanStrings
Strings which can be converted into booleans.

Constructor Detail

StringTool

public StringTool()
Method Detail

getIntValue

public static int getIntValue(java.lang.String s,
                              int d)
Parse string for integer value. The string may start with "0x" or "0" to indicate hexadecimal or octal numbers.

Parameters:
s - The string to parse.
d - A default value.
Returns:
The result.

getIntValue

public static int getIntValue(java.lang.String s)
Parse string for integer value. The string may start with "0x" or "0" to indicate hexadecimal or octal numbers.

Parameters:
s - The string to parse.
Returns:
The result.

getColor

public static java.awt.Color getColor(java.lang.String s,
                                      int dr,
                                      int dg,
                                      int db)
Convert string into a color.

Parameters:
s - A string like "128,0,0".
dr - Default for red.
dg - Default for green.
db - Default for blue.
Returns:
The color.

getColor

public static java.awt.Color getColor(java.lang.String s)
Convert a String into a color.

Parameters:
s - The string to analyze.
Returns:
The color.

getArrayIndex

public static int getArrayIndex(java.lang.String[] a,
                                java.lang.String s)
Find index of string s in array a.

Parameters:
a - An array of strings.
s - The string to search for.
Returns:
On success: the index of s in a (0, 1, ...) On error: -1.

getStartArrayIndex

public static int getStartArrayIndex(java.lang.String[] a,
                                     java.lang.String s)
Check whether or not the string s starts with one of the strings from the array a.

Parameters:
a - An array of strings, one of the strings is probably at the start of string s.
s - The string to check.
Returns:
The index of that string in a which was found at the start of s. On error -- no matching string found: -1.

isBoolean

public static boolean isBoolean(java.lang.String s)
Check whether or not a string represents a boolean.

Parameters:
s - The string to check.
Returns:
A flag whether or not the string represents a boolean.

getBoolean

public static boolean getBoolean(java.lang.String s,
                                 boolean d)
Convert a string into a boolean.

Parameters:
s - The source string.
d - A default value, returned if the string does not represent a boolean.
Returns:
The boolean value.