org.deegree.commons.utils
Class StringUtils

java.lang.Object
  extended by org.deegree.commons.utils.StringUtils

public class StringUtils
extends Object

This is a collection of some methods that work with strings, like split or replace. It is complementary to the ArrayTools.

Version:
$Revision: 31514 $, $Date: 2011-08-17 11:28:36 +0200 (Wed, 17 Aug 2011) $
Author:
Oliver Tonnhofer, last edited by: $Author: aschmitz $

Field Summary
static int NO_TRIM_FIELDS
          Do not trim whitespace on fields.
static int REMOVE_DOUBLE_FIELDS
          Remove all double ocurrences of a field.
static int REMOVE_EMPTY_FIELDS
          Remove empty fields.
 
Constructor Summary
StringUtils()
           
 
Method Summary
static String concat(List<String> parts, String separator)
           
static int count(String target, String token)
          Counts the occurrences of token in target.
static List<String> extract(String target, String start, String end)
          Extract all the strings that begin and end with the given tokens.
static boolean isSet(String s)
          Test if given string is not null and not is the empty string "".
static long parseByteSize(String size)
          Convert the given String to the number of bytes they represent.
static String repeat(int count, String str)
           
static String replaceAll(String target, String from, String to)
          Replaces the all substrings of this string that matches the given from string with the given replacement.
static String replaceFirst(String target, String from, String to)
          Replaces the first substring of this string that matches the given from string with the given replacement.
static String[] split(String string, String delimiter)
          Splits a string on all occurrences of delimiter and returns a list with all parts.
static String[] split(String string, String delimiter, int options)
          Splits a string on all occurrences of delimiter and returns a list with all parts.
static String trim(String string, String mark)
          Removes all occurrences of a string from the start and end.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

REMOVE_EMPTY_FIELDS

public static final int REMOVE_EMPTY_FIELDS
Remove empty fields. Used as an option for some StringTools methods.

See Also:
Constant Field Values

REMOVE_DOUBLE_FIELDS

public static final int REMOVE_DOUBLE_FIELDS
Remove all double ocurrences of a field. Used as an option for some StringTools methods.

See Also:
Constant Field Values

NO_TRIM_FIELDS

public static final int NO_TRIM_FIELDS
Do not trim whitespace on fields. Used as an option for some StringTools methods.

See Also:
Constant Field Values
Constructor Detail

StringUtils

public StringUtils()
Method Detail

extract

public static List<String> extract(String target,
                                   String start,
                                   String end)
Extract all the strings that begin and end with the given tokens.

Parameters:
target -
start - start token
end - ent token
Returns:
a list with all extracted strings

replaceFirst

public static String replaceFirst(String target,
                                  String from,
                                  String to)
Replaces the first substring of this string that matches the given from string with the given replacement. Works like String.replaceFirst(String, String) but doesn't use regular expressions. All occurences of special chars will be escaped.

Parameters:
target - is the original string
from - is the string to be replaced
to - is the string which will used to replace
Returns:
the changed target string

replaceAll

public static String replaceAll(String target,
                                String from,
                                String to)
Replaces the all substrings of this string that matches the given from string with the given replacement. Works like String.replaceAll(String, String) but doesn't use regular expressions. All occurences of special chars will be escaped.

Parameters:
target - is the original string
from - is the string to be replaced
to - is the string which will used to replace
Returns:
the changed target string

split

public static String[] split(String string,
                             String delimiter)
Splits a string on all occurrences of delimiter and returns a list with all parts. Each part will be trimmed from whitespace. See split(String, String, int) for further options. If you need regular expressions, use String.split(String).

Parameters:
string - the string to split
delimiter -
Returns:
a list with all parts

split

public static String[] split(String string,
                             String delimiter,
                             int options)
Splits a string on all occurrences of delimiter and returns a list with all parts. If you need regular expressions, use String.split(String). This methods offers some options to modify the behaviour of the splitting. You can combine the options with | (eg. StringTools.split(string, delimiter, REMOVE_EMPTY_FIELDS | REMOVE_DOUBLE_FIELDS)

Parameters:
string -
delimiter -
options - a combination (|) of options
Returns:
a list with all parts

trim

public static String trim(String string,
                          String mark)
Removes all occurrences of a string from the start and end. If you only want to remove whitespaces use String.trim().

Parameters:
string -
mark - string to remove from begin and end of string
Returns:
string where mark has been removed from start and end

count

public static int count(String target,
                        String token)
Counts the occurrences of token in target.

Parameters:
target -
token -
Returns:
number of tokens within a string

isSet

public static final boolean isSet(String s)
Test if given string is not null and not is the empty string "".

Parameters:
s - the string to test.
Returns:
true iff s is not null and s not is the empty string "".

parseByteSize

public static final long parseByteSize(String size)
Convert the given String to the number of bytes they represent. Incoming values could be something like: If the String could not be parsed, 0 will be returned.

Parameters:
size - the size representation
Returns:
the size in bytes, or 0 if not parsable.

concat

public static String concat(List<String> parts,
                            String separator)

repeat

public static String repeat(int count,
                            String str)


Copyright © 2011. All Rights Reserved.