|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectutil.StringTool
public class StringTool
A package containing various static helper methods for dealing with Strings.
| Nested Class Summary | |
|---|---|
static class |
StringTool.DoubleTest
Test double-list parsing. |
static class |
StringTool.Parse
Test token-parsing. |
static class |
StringTool.PropTest
Test properties tokenization. |
static class |
StringTool.Test
Tests number parsing. |
| Field Summary | |
|---|---|
static String |
COLON
A delimiter String containing additionally the colon. |
static String |
COMMA
A delimiter String containing additionally the comma. |
private static String |
DELIM
The default delimiter characters, as a string. |
static String |
DOLLAR
The dollar sign. |
static String |
EQUAL
A delimiter String containing additionally the equal sign. |
static String |
INNERLIST
The default delimiter for the inner list elements of a double list. |
static String |
MAPDELIM
The default delimiter between individual key-value mappings. |
static String |
MAPKEY
The default delimiter between key and values. |
static String |
OUTERLIST
The default delimiter for the outer list elements of a double list. |
static String |
SEMICOLON
A delimiter String containing additionally the semicolon. |
static char |
UNDERSCORE
The default replacement char for whitespaces. |
| Constructor Summary | |
|---|---|
StringTool()
|
|
| Method Summary | ||
|---|---|---|
static String |
cleanISO(String read)
Removes any ISO-control chars from a string. |
|
static String |
concat(String[] cl)
Concatenates individual strings into a single string separated by os-specific newlines. |
|
static String |
concat(String[] cl,
String sep)
Concatenates individual strings into a single string separated by os-specific newlines. |
|
static String |
concat(String c1,
String c2)
Concatenates individual strings into a single string separated by os-specific newlines. |
|
static String |
concat(String c1,
String c2,
String sep)
Concatenates individual strings into a single string separated by os-specific newlines. |
|
static int |
count(String aim,
char find)
Counts the occurence of the given char in the argument string. |
|
static String |
discardBefore(String token,
String all)
If the token string is found in the argument, we return only the portion of the argument after the last occurence of the token, otherwise we return the entrire string |
|
static List<List<String>> |
doubleTokenize(String target)
Converts a string into a double-list. |
|
static List<List<String>> |
doubleTokenize(String target,
String outdelim,
String indelim)
Converts a string into a double list. |
|
static List<List<String>> |
doubleTokenize(String target,
String outdelim,
String indelim,
boolean trim)
Converts a string into a double list. |
|
static String |
dup(char what,
int howoften)
Returns a String containing howoften representations of char what. |
|
private static
|
getToken(String in,
Class<T> def)
Tries to convert a string into an object of the given class using a single argument constructor. |
|
static String |
leftString(String arg,
int left)
Returns a String of length left, starting from arg index 0. |
|
static Map<String,String> |
linkedMap(String target)
Converts this string into a propertis object. |
|
static Map<String,String> |
linkedMap(String target,
String delim,
String key)
Converts this string into a propertis object. |
|
static Map<String,String> |
linkedMap(String target,
String delim,
String key,
boolean trim)
Converts this string into a propertis object. |
|
static String |
noWhitespace(String replace)
Takes an input string an replaces all occurences of whitespaces with UNDERSCORE. |
|
static String |
noWhitespace(String replace,
char with)
Takes an input string an replaces all occurences of whitespaces with the specified char. |
|
static Number[] |
parseNumbers(String in,
String[] names)
Converts a string that consists of name/value pairs into numbers. |
|
static Number[] |
parseNumbers(String in,
String[] names,
boolean ignorecase,
Class[] types)
Converts a string that consists of name/value pairs into numbers. |
|
static Number[] |
parseNumbers(String in,
String[] names,
Class[] type)
Converts a string that consists of name/value pairs into numbers. |
|
static
|
parseProperties(Map<String,String> target,
Class<K> k,
Class<V> v)
Propertizes a mapping into keys and values of the stated reference. |
|
static
|
parseProperties(String target,
Class<K> k,
Class<V> v)
Propertizes a mapping into keys and values of the stated reference. |
|
static
|
parseToken(String tokens,
Class<T> def)
Converts a tokenizable list into a list of objects that can be constructed via a string. |
|
static
|
parseToken(String tokens,
Class<T> def,
String delim)
Converts a tokenizable list into a list of objects that can be constructed via a string. |
|
static
|
parseToken(String tokens,
Class<T> def,
String delim,
boolean trim,
int length)
Converts a tokenizable list into a list of objects that can be constructed via a string. |
|
static Map<String,String> |
propertize(String target)
Converts this string into a propertis object. |
|
static Map<String,String> |
propertize(String target,
String delim,
String key)
Converts this string into a propertis object. |
|
static Map<String,String> |
propertize(String target,
String delim,
String key,
boolean trim)
Converts this string into a propertis object. |
|
static String |
removeSpace(String arg)
Removes all whitespaces from the argument string. |
|
static String |
rightString(String arg,
int right)
Returns the last right characters of arg as a String. |
|
static String |
stringList(List<?> l)
Converts a list of strings into a single, comma-separated string. |
|
static String |
stringMap(Map<?,?> m)
Converts astring-tostring mapping into a single string, delimited with colons and equal signe. |
|
static String |
stringNumbers(String[] names,
Number[] values)
Takes the array names, adds an equal sign after it and converts the number with the appropriate index into a string and adds it immediately after the equal sign. |
|
static List<String> |
tokenize(String target)
Converts this String of tokens into a vector of tokens using the default delimiters. |
|
static List<String> |
tokenize(String target,
String delim)
Converts this String of tokens into a vector of tokens using the default delimiters. |
|
static List<String> |
tokenize(String target,
String delim,
boolean trim)
Converts this String of tokens into a vector of tokens using the specified delimiters. |
|
static String |
toTokenString(Collection<?> stringlist,
String delim)
Concats a list of strings into a comma-separated list in a single string. |
|
static String[] |
unchain(String all)
Separates a single string into an array of individual lines. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
private static final String DELIM
public static final String COMMA
public static final String SEMICOLON
public static final String COLON
public static final String EQUAL
public static final String DOLLAR
public static final String MAPDELIM
public static final String MAPKEY
public static final String INNERLIST
public static final String OUTERLIST
public static final char UNDERSCORE
| Constructor Detail |
|---|
public StringTool()
| Method Detail |
|---|
public static String stringList(List<?> l)
public static String stringMap(Map<?,?> m)
public static Map<String,String> propertize(String target)
MAPDELIM for separation between individual mappings,
i.e. between key-value pairs. The delimiter separating the key from the
value is MAPKEY. Both, the keys and the values, are trimmed
prior to adding them to the Properties returned.
target - A string consisting of a MAPDELIM separated listing
of individual key-value mapping, which are separated with the
MAPKEY delimiter.
linkedMap(java.lang.String).
public static Map<String,String> propertize(String target,
String delim,
String key)
target - A string consisting of a delim separated listing of individual
key-value mapping, which are separated with the key delimiter.delim - A string used as a separator between individual key-value
mappings.key - The string used to separate the key from the value.
linkedMap(java.lang.String).
public static Map<String,String> propertize(String target,
String delim,
String key,
boolean trim)
target - A string consisting of a delim separated listing of individual
key-value mapping, which are separated with the key delimiter.delim - A string used as a separator between individual key-value
mappings.key - The string used to separate the key from the value. May not be
a subset of delim.trim - If true, both, the keys and values are trimmed prior to adding
them to the properties object.
linkedMap(java.lang.String).public static Map<String,String> linkedMap(String target)
MAPDELIM for separation between individual mappings,
i.e. between key-value pairs. The delimiter separating the key from the
value is MAPKEY. Both, the keys and the values, are trimmed
prior to adding them to the Properties returned.
target - A string consisting of a MAPDELIM separated listing
of individual key-value mapping, which are separated with the
MAPKEY delimiter.
public static Map<String,String> linkedMap(String target,
String delim,
String key)
target - A string consisting of a delim separated listing of individual
key-value mapping, which are separated with the key delimiter.delim - A string used as a separator between individual key-value
mappings.key - The string used to separate the key from the value.
public static Map<String,String> linkedMap(String target,
String delim,
String key,
boolean trim)
target - A string consisting of a delim separated listing of individual
key-value mapping, which are separated with the key delimiter.delim - A string used as a separator between individual key-value
mappings.key - The string used to separate the key from the value. May not be
a subset of delim.trim - If true, both, the keys and values are trimmed prior to adding
them to the properties object.
public static List<String> tokenize(String target)
target - The string to be tokenized.
public static List<String> tokenize(String target,
String delim)
target - The string to be tokenized.
public static List<String> tokenize(String target,
String delim,
boolean trim)
target - The string to be tokenized.delim - The delimiters to use.
public static final List<List<String>> doubleTokenize(String target)
INNERLIST and OUTERLIST delimiters a
string is parsed into a double list as in the example below:
a,b,c,d;1,2;q,w,e,r,t,y;AA,BB,CCThis string will return a list with four elements (separator ';'). Each element is a list, the first one a four-string list (a, b, c, d), the second one a two-string list (1, 2), etc.
public static final List<List<String>> doubleTokenize(String target,
String outdelim,
String indelim)
INNERLIST and OUTERLIST delimiters a
string is parsed into a double list as in the example below:
a,b,c,d;1,2;q,w,e,r,t,y;AA,BB,CCThis string will return a list with four elements (separator ';'). Each element is a list, the first one a four-string list (a, b, c, d), the second one a two-string list (1, 2), etc.
public static final List<List<String>> doubleTokenize(String target,
String outdelim,
String indelim,
boolean trim)
INNERLIST and OUTERLIST delimiters a
string is parsed into a double list as in the example below:
a,b,c,d;1,2;q,w,e,r,t,y;AA,BB,CCThis string will return a list with four elements (separator ';'). Each element is a list, the first one a four-string list (a, b, c, d), the second one a two-string list (1, 2), etc.
target - The string to parse.outdelim - The delimiter list of outer delimiters.indelim - The delimiter list of inner delimiters.trim - If true, the resulting strings are trimmed.public static final String removeSpace(String arg)
arg - The input string
public static String discardBefore(String token,
String all)
token - The normally single-char token stringall - A long string that should be chopped for meaningful info.
public static final String dup(char what,
int howoften)
public static final int count(String aim,
char find)
public static final String leftString(String arg,
int left)
public static final String rightString(String arg,
int right)
public static final String concat(String c1,
String c2)
public static final String concat(String c1,
String c2,
String sep)
public static final String concat(String[] cl)
public static final String concat(String[] cl,
String sep)
public static final String[] unchain(String all)
public static final String toTokenString(Collection<?> stringlist,
String delim)
public static <T> List<T> parseToken(String tokens,
Class<T> def)
throws ParseException
def - A default object, may not be null.
ParseException
public static <T> List<T> parseToken(String tokens,
Class<T> def,
String delim)
throws ParseException
def - A default object, may not be null.
ParseException
public static <T> List<T> parseToken(String tokens,
Class<T> def,
String delim,
boolean trim,
int length)
throws ParseException
def - A default object, may not be null.
ParseException
public static <K,V> Map<K,V> parseProperties(String target,
Class<K> k,
Class<V> v)
throws ParseException
ParseException
public static <K,V> Map<K,V> parseProperties(Map<String,String> target,
Class<K> k,
Class<V> v)
throws ParseException
ParseException
private static <T> T getToken(String in,
Class<T> def)
throws ParseException
ParseException
public static Number[] parseNumbers(String in,
String[] names)
parseNumbers(String, String[], boolean, Class[])
public static Number[] parseNumbers(String in,
String[] names,
Class[] type)
parseNumbers(String, String[], boolean, Class[])
public static Number[] parseNumbers(String in,
String[] names,
boolean ignorecase,
Class[] types)
repeated for n-times. Additionally to the input string, the variable names must be provided at input. Depending on the ignorecase flag, this names are matched to the variable names in the input string. The number-class array provided on input is used for parsing the values to the appropriate type. If it is omitted, all values are parsed as doubles. The returned number array is an array consisting of number objects of the appropriate type and with values according to the input string. The ordering is according to the ordering of the variable names. Variables not found are null. Ordering of the variables within the string is unimportant. Note that at least one whitespace or equal char must separate the variable name from the value.[WS][WS,=][WS] ,
in - The input string.names - The varaible names to extract out of the string.ignorecase - If true, case of variable names is ignored.types - A class array with the number types that should be parsed.
public static String stringNumbers(String[] names,
Number[] values)
parseNumbers(java.lang.String, java.lang.String[])
public static String noWhitespace(String replace)
UNDERSCORE.
public static String noWhitespace(String replace,
char with)
public static String cleanISO(String read)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||