deegree 2.5 (2011/06/29 09:44 build-8-official)

org.deegree.framework.util
Class StringTools

java.lang.Object
  extended by org.deegree.framework.util.StringTools

public class StringTools
extends java.lang.Object

this is a collection of some methods that extends the functionality of the sun-java string class.

Version:
$Revision: 29560 $, $Date: 2011-02-07 15:35:13 +0100 (Mo, 07 Feb 2011) $
Author:
Andreas Poth, last edited by: $Author: apoth $

Constructor Summary
StringTools()
           
 
Method Summary
static java.lang.String arrayToString(double[] s, char delimiter)
          transforms a double array to one string. the array fields are separated by the submitted delimiter:
static java.lang.String arrayToString(float[] s, char delimiter)
          transforms a float array to one string. the array fields are separated by the submitted delimiter:
static java.lang.String arrayToString(int[] s, char delimiter)
          transforms a int array to one string. the array fields are separated by the submitted delimiter:
static java.lang.String arrayToString(java.lang.String[] s, char delimiter)
          transforms a string array to one string. the array fields are separated by the submitted delimiter:
static java.lang.String concat(int size, java.lang.Object... objects)
          concatenates an array of strings using a
static boolean contains(java.lang.String[] target, java.lang.String value)
          checks if the submitted array contains the string value
static int countString(java.lang.String target, java.lang.String token)
          countString count the occurrences of token into target
static java.lang.String[] deleteDoubles(java.lang.String[] s)
          deletes all double entries from the submitted array
static java.lang.String extractString(java.lang.String target, java.lang.String startDel, java.lang.String endDel, boolean delStart, boolean delEnd)
          extract a string contained between startDel and endDel, you can remove the delimiters if set true the parameters delStart and delEnd
static java.lang.String[] extractStrings(java.lang.String target, java.lang.String startString, java.lang.String endString)
          Extract all the strings that begin with "start" and end with "end" and store it into an array of String
static java.lang.String listToString(java.util.List<?> s, char delimiter)
          transforms a list to one string. the array fields are separated by the submitted delimiter:
static java.lang.String normalizeString(java.lang.String source, java.lang.String locale)
          The passed string gets normalized along the rules for the given locale as they are set in the file ".
static void printMap(java.util.Map<?,?> map, java.io.PrintStream ps)
          prints a map with one line for each key-value pair
static void printStacktrace()
          prints current stactrace
static java.lang.String[] removeFromArray(java.lang.String[] target, java.lang.String s)
          removes all fields from the array that equals s
static java.lang.String replace(java.lang.String target, java.lang.String from, java.lang.String to, boolean all)
          replaces occurences of a string fragment within a string by a new string.
static java.lang.String stackTraceToString(java.lang.StackTraceElement[] se)
          transforms an array of StackTraceElements into a String
static java.lang.String stackTraceToString(java.lang.Throwable e)
          Get the message and the class, as well as the stack trace of the passed Throwable and transforms it into a String
static java.lang.String[] toArray(java.lang.String s, java.lang.String delimiter, boolean deleteDoubles)
          parse a string and return its tokens as array
static double[] toArrayDouble(java.lang.String s, java.lang.String delimiter)
          convert the array of string like [(x1,y1),(x2,y2)...] into an array of double [x1,y1,x2,y2...]
static float[] toArrayFloat(java.lang.String s, java.lang.String delimiter)
          convert the array of string like [(x1,y1),(x2,y2)...] into an array of float values [x1,y1,x2,y2...]
static java.util.List<java.lang.String> toList(java.lang.String s, java.lang.String delimiter, boolean deleteDoubles)
          parse a string and return its tokens as typed List. empty fields will be removed from the list.
static java.lang.String validateString(java.lang.String s, java.lang.String mark)
          clears the begin and end of a string from the strings submitted
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringTools

public StringTools()
Method Detail

concat

public static java.lang.String concat(int size,
                                      java.lang.Object... objects)
concatenates an array of strings using a

Parameters:
size - estimated size of the target string
objects - toString() will be called for each object to append it to the result string
Returns:
the concatenated String
See Also:
StringBuffer

replace

public static java.lang.String replace(java.lang.String target,
                                       java.lang.String from,
                                       java.lang.String to,
                                       boolean all)
replaces occurences of a string fragment within a string by a new string.

Parameters:
target - is the original string
from - is the string to be replaced
to - is the string which will used to replace
all - if it's true all occurences of the string to be replaced will be replaced. else only the first occurence will be replaced.
Returns:
the changed target string

toArray

public static java.lang.String[] toArray(java.lang.String s,
                                         java.lang.String delimiter,
                                         boolean deleteDoubles)
parse a string and return its tokens as array

Parameters:
s - string to parse
delimiter - delimiter that marks the end of a token
deleteDoubles - if it's true all string that are already within the resulting array will be deleted, so that there will only be one copy of them.
Returns:
an Array of Strings

toList

public static java.util.List<java.lang.String> toList(java.lang.String s,
                                                      java.lang.String delimiter,
                                                      boolean deleteDoubles)
parse a string and return its tokens as typed List. empty fields will be removed from the list.

Parameters:
s - string to parse
delimiter - delimiter that marks the end of a token
deleteDoubles - if it's true all string that are already within the resulting array will be deleted, so that there will only be one copy of them.
Returns:
a list of Strings

arrayToString

public static java.lang.String arrayToString(java.lang.String[] s,
                                             char delimiter)
transforms a string array to one string. the array fields are separated by the submitted delimiter:

Parameters:
s - stringarray to transform
delimiter -
Returns:
the String representation of the given array

listToString

public static java.lang.String listToString(java.util.List<?> s,
                                            char delimiter)
transforms a list to one string. the array fields are separated by the submitted delimiter:

Parameters:
s - stringarray to transform
delimiter -
Returns:
the String representation of the given list.

arrayToString

public static java.lang.String arrayToString(double[] s,
                                             char delimiter)
transforms a double array to one string. the array fields are separated by the submitted delimiter:

Parameters:
s - string array to transform
delimiter -
Returns:
the String representation of the given array

arrayToString

public static java.lang.String arrayToString(float[] s,
                                             char delimiter)
transforms a float array to one string. the array fields are separated by the submitted delimiter:

Parameters:
s - float array to transform
delimiter -
Returns:
the String representation of the given array

arrayToString

public static java.lang.String arrayToString(int[] s,
                                             char delimiter)
transforms a int array to one string. the array fields are separated by the submitted delimiter:

Parameters:
s - stringarray to transform
delimiter -
Returns:
the String representation of the given array

validateString

public static java.lang.String validateString(java.lang.String s,
                                              java.lang.String mark)
clears the begin and end of a string from the strings submitted

Parameters:
s - string to validate
mark - string to remove from begin and end of s
Returns:
the substring of the given String without the mark at the and and the begin, and trimmed

deleteDoubles

public static java.lang.String[] deleteDoubles(java.lang.String[] s)
deletes all double entries from the submitted array

Parameters:
s - to remove the doubles from
Returns:
The string array without all doubled values

removeFromArray

public static java.lang.String[] removeFromArray(java.lang.String[] target,
                                                 java.lang.String s)
removes all fields from the array that equals s

Parameters:
target - array where to remove the submitted string
s - string to remove
Returns:
the String array with all exact occurrences of given String removed.

contains

public static boolean contains(java.lang.String[] target,
                               java.lang.String value)
checks if the submitted array contains the string value

Parameters:
target - array to check if it contains value
value - string to check if it within the array
Returns:
true if the given value is contained (without case comparison) in the array, caution, if the value ends with a comma ',' a substring will be taken to remove it (rb: For whatever reason??).

toArrayDouble

public static double[] toArrayDouble(java.lang.String s,
                                     java.lang.String delimiter)
convert the array of string like [(x1,y1),(x2,y2)...] into an array of double [x1,y1,x2,y2...]

Parameters:
s -
delimiter -
Returns:
the array representation of the given String

toArrayFloat

public static float[] toArrayFloat(java.lang.String s,
                                   java.lang.String delimiter)
convert the array of string like [(x1,y1),(x2,y2)...] into an array of float values [x1,y1,x2,y2...]

Parameters:
s -
delimiter -
Returns:
the array representation of the given String

printStacktrace

public static void printStacktrace()
prints current stactrace


stackTraceToString

public static java.lang.String stackTraceToString(java.lang.StackTraceElement[] se)
transforms an array of StackTraceElements into a String

Parameters:
se - to put to String
Returns:
a String representation of the given Stacktrace.

stackTraceToString

public static java.lang.String stackTraceToString(java.lang.Throwable e)
Get the message and the class, as well as the stack trace of the passed Throwable and transforms it into a String

Parameters:
e - to get information from
Returns:
the String representation of the given Throwable

countString

public static int countString(java.lang.String target,
                              java.lang.String token)
countString count the occurrences of token into target

Parameters:
target -
token -
Returns:
the number of occurrences of the given token in the given String

extractStrings

public static java.lang.String[] extractStrings(java.lang.String target,
                                                java.lang.String startString,
                                                java.lang.String endString)
Extract all the strings that begin with "start" and end with "end" and store it into an array of String

Parameters:
target -
startString -
endString -
Returns:
null if no strings were found!!

extractString

public static java.lang.String extractString(java.lang.String target,
                                             java.lang.String startDel,
                                             java.lang.String endDel,
                                             boolean delStart,
                                             boolean delEnd)
extract a string contained between startDel and endDel, you can remove the delimiters if set true the parameters delStart and delEnd

Parameters:
target - to extract from
startDel - to remove from the start
endDel - string to remove from the end
delStart - true if the start should be removed
delEnd - true if the end should be removed
Returns:
the extracted string from the given target. rb: Caution this method may not do what it should.

normalizeString

public static java.lang.String normalizeString(java.lang.String source,
                                               java.lang.String locale)
                                        throws java.io.IOException,
                                               org.xml.sax.SAXException,
                                               XMLParsingException
The passed string gets normalized along the rules for the given locale as they are set in the file "./normalization.xml". If such rules are specified, the following order is obeyed:
  1. if the attribute "case" is set with "toLower" or "toUpper", the letters are switched to lower case or to upper case respectively.
  2. all rules given in the "Rule" elements are performed.
  3. if the attribute "removeDoubles" is set and not empty, all multi occurences of the letters given in this attribute are reduced to a single occurence.

Parameters:
source - the String to normalize
locale - the locale language defining the rules to choose, e.g. "de"
Returns:
the normalized String
Throws:
java.io.IOException
org.xml.sax.SAXException
XMLParsingException

printMap

public static final void printMap(java.util.Map<?,?> map,
                                  java.io.PrintStream ps)
prints a map with one line for each key-value pair

Parameters:
map -
ps - if ps is null System.out will be used

deegree 2.5 (2011/06/29 09:44 build-8-official)

an open source project founded by lat/lon, Bonn, Germany.
For more information visit: http://www.deegree.org