org.jscience.architecture.traffic.util
Class StringUtils

java.lang.Object
  extended by org.jscience.architecture.traffic.util.StringUtils

public class StringUtils
extends java.lang.Object

Auxiliary class for processing strings. Used mainly by the XML parser


Constructor Summary
StringUtils()
           
 
Method Summary
static java.lang.String firstLetterToUpperCase(java.lang.String string)
          Convert the first letter of a string to upper case and return the result
static int getIndexObject(java.lang.Object[] data, java.lang.Object object)
          Find the index of an element in an array.
static java.lang.Object lookUpNumber(java.lang.Object[] data, int index)
          Lookup an element in an array
static java.lang.String remove(java.lang.String string, char o)
          Remove all occurences of a char from a string
static java.lang.String remove(java.lang.String string, java.lang.String o)
          Remove all occurences of a string from another string
static java.lang.String repeat(char c, int times)
          Fill a string with several occurences of a char
static java.lang.String replace(java.lang.String string, char o, char n)
          Replace a char in a string with another char
static java.lang.String replace(java.lang.String string, char o, java.lang.String n)
          Replace all occurences of a char in a String with a string
static java.lang.String replace(java.lang.String string, java.lang.String o, java.lang.String n)
          Replace all occurences of a string in another String
static java.lang.String replaceList(java.lang.String string, char[] from, java.lang.String[] to)
          Replace instances of chars in the from-array in the first string with their counterpart in the to-array.
static java.lang.String replaceList(java.lang.String string, java.lang.String[] from, java.lang.String[] to)
          Replace instances of strings in the from-array in the first string with their counterpart in the to-array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringUtils

public StringUtils()
Method Detail

replaceList

public static java.lang.String replaceList(java.lang.String string,
                                           java.lang.String[] from,
                                           java.lang.String[] to)
Replace instances of strings in the from-array in the first string with their counterpart in the to-array.

Parameters:
string - The input string
from - The first column of the translation table (The strings to replace).
to - The second column of the translation table (The strings to replace the elements of the from array with).
Returns:
The resulting string with all stuff replaced

replaceList

public static java.lang.String replaceList(java.lang.String string,
                                           char[] from,
                                           java.lang.String[] to)
Replace instances of chars in the from-array in the first string with their counterpart in the to-array. This method is way more efficient than the replaceList(String,String[],String[]) method.

Parameters:
string - The input string
from - The first column of the translation table (The chars to replace).
to - The second column of the translation table (The strings to replace the elements of the from array with).
Returns:
The resulting string with all stuff replaced

replace

public static java.lang.String replace(java.lang.String string,
                                       java.lang.String o,
                                       java.lang.String n)
Replace all occurences of a string in another String

Parameters:
string - The string to search in
o - the old substring
n - the string with which o has to be replaced
Returns:
The result

replace

public static java.lang.String replace(java.lang.String string,
                                       char o,
                                       java.lang.String n)
Replace all occurences of a char in a String with a string

Parameters:
string - The string to search in
o - the old char
n - the new string to replace the char with
Returns:
The result

replace

public static java.lang.String replace(java.lang.String string,
                                       char o,
                                       char n)
Replace a char in a string with another char

Parameters:
string - The string to search in
o - the old char
n - the new char with which the old char is to be replaced
Returns:
The result

remove

public static java.lang.String remove(java.lang.String string,
                                      char o)
Remove all occurences of a char from a string

Parameters:
string - The string to search in
o - the char to remove
Returns:
The result

remove

public static java.lang.String remove(java.lang.String string,
                                      java.lang.String o)
Remove all occurences of a string from another string

Parameters:
string - The string to search in
o - the string to remove
Returns:
The result

repeat

public static java.lang.String repeat(char c,
                                      int times)
Fill a string with several occurences of a char

Parameters:
c - The char to fill the string with
times - The length of the string
Returns:
A string which consists of "times" times char c

firstLetterToUpperCase

public static java.lang.String firstLetterToUpperCase(java.lang.String string)
Convert the first letter of a string to upper case and return the result

Parameters:
string - The input string
Returns:
The result

lookUpNumber

public static java.lang.Object lookUpNumber(java.lang.Object[] data,
                                            int index)
Lookup an element in an array

Parameters:
data - The array to search in
index - The index of the element you want
Returns:
The element at that position
Throws:
java.util.NoSuchElementException - If the array has no element at the specified index.

getIndexObject

public static int getIndexObject(java.lang.Object[] data,
                                 java.lang.Object object)
Find the index of an element in an array. Elements are compared using the object.equals(otherObject) method.

Parameters:
data - The array to search in
object - The element to search for
Returns:
The index of that element
Throws:
java.util.NoSuchElementException - If the specified object cannot be found