|
Structured Text Toolkit | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectcom.saelist.util.Strings
Various text oriented utilites
| Field Summary | |
static Logger |
logger
A logger for this class. |
| Constructor Summary | |
Strings()
|
|
| Method Summary | |
static java.lang.String |
arrayToString(java.lang.String[] values,
char separator)
Converts String array to a string with delimiter. |
static java.lang.String |
asStackTrace(java.lang.Throwable e)
Returns the stacktrace of the given exception as a string. |
static boolean |
containsAnyOf(java.lang.String text,
java.lang.String chars)
Tests if the text contains any of the characters in chars . |
static java.lang.String |
cutDown(java.lang.String text,
int maxSize,
java.lang.String suffix)
Limits the size of text to maxSize charaters and appends the suffix. |
static java.lang.String |
format(java.lang.String text,
java.lang.String arg)
A conveniance interface to format(String, String[]) for a single
argument. |
static java.lang.String |
format(java.lang.String text,
java.lang.String[] args)
Replaces each occurence of "%" in the text with the eachth element of args. |
static java.lang.String |
format(java.lang.String text,
java.lang.String arg1,
java.lang.String arg2)
A conveniance interface to format(String, String[]) for 2
arguments. |
static java.lang.String |
format(java.lang.String text,
java.lang.String arg1,
java.lang.String arg2,
java.lang.String arg3)
A conveniance interface to format(String, String[]) for 3
arguments. |
static java.lang.String |
format(java.lang.String text,
java.lang.String arg1,
java.lang.String arg2,
java.lang.String arg3,
java.lang.String arg4)
A conveniance interface to format(String, String[]) for 4
arguments. |
static java.lang.String |
front(java.lang.String text,
java.lang.String sep)
Returns the part of text before sep. |
static java.lang.String |
getStackTrace(java.lang.Throwable t)
Returns the stack-trace of a Throwable as String. |
static java.lang.String |
indent(java.lang.String text,
int n)
Indents a string by n characters. |
static java.lang.String |
interpret(java.lang.String text,
java.util.Map substitutions)
Primitive variable substitution for strings. |
static java.lang.String |
join(java.util.List list,
java.lang.String separator)
Joins a List [a, b, c] into a string "a|b|c". |
static java.lang.String |
join(java.lang.Object[] objects,
java.lang.String delimiter)
See join(List, String). |
static java.lang.String |
lastFront(java.lang.String text,
java.lang.String sep)
Returns the part of text before the last sep. |
static java.lang.String |
lastRest(java.lang.String text,
java.lang.String sep)
Returns the rest of text after last sep. |
static java.lang.String |
loadFile(java.lang.String filename)
Load the contents of a file as a string. |
static java.lang.String |
loadReader(java.io.Reader reader)
Loads the content of reader into a String. |
static java.lang.String |
loadResource(java.lang.String name)
Load a resource (file) on the classpath as a string. |
static java.lang.String |
loadResource(java.lang.String name,
java.lang.Class clazz)
Load a resource (file) on the classpath as a string. |
static java.lang.String |
loadStream(java.io.InputStream in)
Load all content from the given stream as string. |
static java.util.List |
makeList()
A convenience method to make an empty list. |
static java.util.List |
makeList(java.lang.Object arg1)
A convenience method to make a one element list. |
static java.util.List |
makeList(java.lang.Object[] args)
A convenience method to enlist an array. |
static java.util.List |
makeList(java.lang.Object arg1,
java.lang.Object arg2)
A convenience method to make a two element list. |
static java.util.List |
makeList(java.lang.Object arg1,
java.lang.Object arg2,
java.lang.Object arg3)
A convenience method to make a three element list. |
static java.util.List |
makeList(java.lang.Object arg1,
java.lang.Object arg2,
java.lang.Object arg3,
java.lang.Object arg4)
A convenience method to make a four element list. |
static java.util.Map |
makeMap(java.lang.Object key1,
java.lang.Object value1)
A convenience method to make a one entry map. |
static java.util.Map |
makeMap(java.lang.Object key1,
java.lang.Object value1,
java.lang.Object key2,
java.lang.Object value2)
A convenience method to make a two entry map. |
static java.util.Map |
makeMap(java.lang.Object key1,
java.lang.Object value1,
java.lang.Object key2,
java.lang.Object value2,
java.lang.Object key3,
java.lang.Object value3)
A convenience method to make a three entry map. |
static java.util.Map |
makeMap(java.lang.Object key1,
java.lang.Object value1,
java.lang.Object key2,
java.lang.Object value2,
java.lang.Object key3,
java.lang.Object value3,
java.lang.Object key4,
java.lang.Object value4)
A convenience method to make a four entry map. |
static boolean |
matches(java.lang.String text,
java.lang.String pattern)
Indicates wether the pattern matches the text. |
static java.lang.String |
removeNull(java.lang.String value)
Returns the empty string if value is null or "null". |
static java.lang.String |
repeat(java.lang.String s,
int n)
Repeat the given string n times. |
static java.lang.String |
replace(java.lang.String text,
java.lang.String pattern,
java.lang.String replacement)
Substitutes all occurances of a pattern in a text replacementwith replacement. |
static java.lang.String |
replace(java.lang.String text,
java.lang.String pattern,
java.lang.String replacement,
int count)
Substitutes the first count occurances of a pattern in a text with replacement. |
static java.lang.String |
rest(java.lang.String text,
java.lang.String sep)
Returns the rest of text after first sep. |
static void |
saveFile(java.lang.String filename,
java.lang.String content)
|
static java.util.List |
split(java.lang.String text,
java.lang.String separator)
Splits a string "a|b|c" into list with elements ["a", "b", "c"] . |
static java.lang.String |
substring(java.lang.String text,
int start)
Tolerant substring. |
static java.lang.String |
substring(java.lang.String text,
int start,
int stop)
Tolerant substring. |
static java.lang.String[] |
tokenize(java.lang.String text,
java.lang.String delimiters,
boolean returndelimiters)
Splits the text on the delimiters and returns an array of the strings. |
static java.util.List |
toList(java.util.Enumeration e)
En lists an enumeration. |
static java.lang.String |
toNonNullString(java.lang.Object object)
Converts null strings to "", all others objects to their Object.toString(). |
static java.lang.String[] |
toStringArray(java.util.List list)
Converts a List of Objects into a array of strings. |
static void |
verify(boolean condition,
java.lang.String message)
Throws an exception with the given message if the condition is true. |
static java.util.List |
wrap(java.lang.String prefix,
java.util.List list,
java.lang.String suffix)
|
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
public static Logger logger
| Constructor Detail |
public Strings()
| Method Detail |
public static java.lang.String asStackTrace(java.lang.Throwable e)
e - the exception to trace.
public static boolean containsAnyOf(java.lang.String text,
java.lang.String chars)
text - the string to search.chars - the chars to find.
public static java.lang.String cutDown(java.lang.String text,
int maxSize,
java.lang.String suffix)
text - the text to constrain.maxSize - the desired maximum length of text.suffix - will be appended to the result if it is actaully cut down.
java.lang.NullPointerException - is text is null.
public static java.lang.String format(java.lang.String text,
java.lang.String arg)
format(String, String[]) for a single
argument.
public static java.lang.String format(java.lang.String text,
java.lang.String arg1,
java.lang.String arg2)
format(String, String[]) for 2
arguments.
public static java.lang.String format(java.lang.String text,
java.lang.String arg1,
java.lang.String arg2,
java.lang.String arg3)
format(String, String[]) for 3
arguments.
public static java.lang.String format(java.lang.String text,
java.lang.String arg1,
java.lang.String arg2,
java.lang.String arg3,
java.lang.String arg4)
format(String, String[]) for 4
arguments.
public static java.lang.String format(java.lang.String text,
java.lang.String[] args)
text - the string to format.args - the replacements for "%" in text.
public static java.lang.String indent(java.lang.String text,
int n)
text - the string to indentn - the number of spaces to indent with.
public static java.lang.String interpret(java.lang.String text,
java.util.Map substitutions)
text - the string to be changedsubstitutions - maps patterns to replacements.
public static java.lang.String join(java.util.List list,
java.lang.String separator)
list - the list to join. Must not be null.separator - will be inserted between the joined elements. If
separator is null the string "null" will be inserted. To insert
nothing provide the empty string.
java.lang.NullPointerException - if list is null.
public static java.lang.String join(java.lang.Object[] objects,
java.lang.String delimiter)
join(List, String).
public static java.lang.String loadFile(java.lang.String filename)
throws java.io.IOException
filename - the name of the file to load.
java.io.IOException - if the file indicated cannot be accessed.
public static void saveFile(java.lang.String filename,
java.lang.String content)
throws java.io.IOException
java.io.IOException
public static java.lang.String loadReader(java.io.Reader reader)
throws java.io.IOException
reader - The reader to empty;
java.io.IOException - if the file indicated cannot be accessed.
public static java.lang.String loadResource(java.lang.String name,
java.lang.Class clazz)
throws java.lang.Exception
name - the fully qualified name of the file to load. E.g.
/com/acme/stardust.xml, the name only if the file is resides in
the same package as clazz.clazz - the class in whose package the resource will be sought.
java.lang.Exception - if the resource is not found.
public static java.lang.String loadResource(java.lang.String name)
throws java.lang.Exception
name - the fully qualified name of the file to load. E.g.
/com/acme/stardust.xml (or the resource must reside in the same
package as this class.
java.lang.Exception - If the resource is not found or cannot be accessed.
public static java.lang.String loadStream(java.io.InputStream in)
throws java.io.IOException
in - the stream to load from.
java.io.IOException - thrown if the Stream throws it.
public static java.lang.String repeat(java.lang.String s,
int n)
s - the string to repeatn - the number of times to repeat
public static java.lang.String replace(java.lang.String text,
java.lang.String pattern,
java.lang.String replacement)
text - the string to be changedpattern - the substring of text to be replacedreplacement - the string to replace pattern in text.
public static java.lang.String replace(java.lang.String text,
java.lang.String pattern,
java.lang.String replacement,
int count)
text - the string to be changedpattern - the substring of text to be replaced must be a nonempty
string.replacement - the string to replace pattern in text. Must not be
null.count - how many of the first instances of pattern to replace.
public static java.util.List split(java.lang.String text,
java.lang.String separator)
text - the entities to put in the list separated by the separator.separator - separates the entities to put in the list.
public static java.lang.String substring(java.lang.String text,
int start,
int stop)
text - the string to take the substring from. Can be null .start - the position of the first character of the substring in text.
Can be less than stop, in which case it is set to the value of
stop .stop - the position after the last character of the substring in
text. Can be beyond the length of text, in which case it is set to
the length text.
public static java.lang.String substring(java.lang.String text,
int start)
text - the string to take the substring from. Can be null .start - the position of the first character of the substring in text.
Can be negative, in which case it is set to null. Can be beyond
the end of the string in which case it is set to the length of the
string.
public static java.util.List toList(java.util.Enumeration e)
lists an enumeration.
e - the enumeration to enlist.
public static java.lang.String arrayToString(java.lang.String[] values,
char separator)
values - to be concatenated.separator - inserted between values in the returned string.
public static java.lang.String removeNull(java.lang.String value)
value - to be converted.
public static java.lang.String toNonNullString(java.lang.Object object)
Object.toString().
object - the object to stringify.
public static java.lang.String[] toStringArray(java.util.List list)
List of Objects into a array of strings.
list - the list to turn into an array. Null values become "null".
Other values become their toString() results.
public static java.lang.String[] tokenize(java.lang.String text,
java.lang.String delimiters,
boolean returndelimiters)
Note: Since it uses StringTokenizer, empty strings are
simply skipped and do not appear in the list. Use split
for more consistent behaviour.
text - the text to splitdelimiters - on which to splitreturndelimiters - true to get the delimiters also.
public static void verify(boolean condition,
java.lang.String message)
throws java.lang.Exception
condition - the condition to test.message - The message to give the exception.
java.lang.Exception - if condition is true.
public static boolean matches(java.lang.String text,
java.lang.String pattern)
text - the text to check for a match.pattern - the pattern to match to text. An asterisk stands for zero
or more characters.
public static java.lang.String getStackTrace(java.lang.Throwable t)
Throwable as String.
t - the Throwable to trace:
public static java.lang.String front(java.lang.String text,
java.lang.String sep)
text - The text to get the front off.sep - separating the front from the rest.
public static java.lang.String lastFront(java.lang.String text,
java.lang.String sep)
text - The text to get the front off.sep - separating the front from the rest.
public static java.lang.String rest(java.lang.String text,
java.lang.String sep)
text - The text to get the rest off.sep - separating the rest from the front.
public static java.lang.String lastRest(java.lang.String text,
java.lang.String sep)
text - The text to get the rest off.sep - separating the rest from the front.
public static java.util.List makeList()
public static java.util.List makeList(java.lang.Object arg1)
public static java.util.List makeList(java.lang.Object arg1,
java.lang.Object arg2)
public static java.util.List makeList(java.lang.Object arg1,
java.lang.Object arg2,
java.lang.Object arg3)
public static java.util.List makeList(java.lang.Object arg1,
java.lang.Object arg2,
java.lang.Object arg3,
java.lang.Object arg4)
public static java.util.List makeList(java.lang.Object[] args)
public static java.util.Map makeMap(java.lang.Object key1,
java.lang.Object value1)
public static java.util.Map makeMap(java.lang.Object key1,
java.lang.Object value1,
java.lang.Object key2,
java.lang.Object value2)
public static java.util.Map makeMap(java.lang.Object key1,
java.lang.Object value1,
java.lang.Object key2,
java.lang.Object value2,
java.lang.Object key3,
java.lang.Object value3)
public static java.util.Map makeMap(java.lang.Object key1,
java.lang.Object value1,
java.lang.Object key2,
java.lang.Object value2,
java.lang.Object key3,
java.lang.Object value3,
java.lang.Object key4,
java.lang.Object value4)
public static java.util.List wrap(java.lang.String prefix,
java.util.List list,
java.lang.String suffix)
|
Structured Text Toolkit | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||