|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.qedeq.base.utility.StringUtility
public final class StringUtility
A collection of useful static methods for strings. LATER mime 20070101: use StringBuilder instead of StringBuffer if working under JDK 1.5
Method Summary | |
---|---|
static java.lang.String |
alignRight(long number,
int length)
Trim an integer with leading spaces to a given maximum length. |
static java.lang.String |
alignRight(java.lang.String string,
int length)
Trim a String with leading spaces to a given maximum length. |
static java.lang.String |
asLines(java.util.Set set)
Evaluates toString at the elements of a Set and returns them as line separated Strings. |
static java.lang.String |
byte2Hex(byte[] data)
Get a hex string representation for an byte array. |
static void |
deleteLineLeadingWhitespace(java.lang.StringBuffer buffer)
Search for first line followed by whitespace and delete this string within the whole text. |
static java.lang.String |
escapeProperty(java.lang.String value)
Return a String like it appears in an property file. |
static java.lang.String |
escapeXml(java.lang.String value)
Escapes the characters in a String using XML entities. |
static java.lang.String |
format(long number,
int length)
Trim an integer with leading zeros to a given maximum length. |
static java.lang.String |
getClassName(java.lang.Class clazz)
Get non qualified class name. |
static java.lang.String |
getLastDotString(java.lang.String full)
Get last dot separated string part. |
static java.lang.String |
getLastTwoDotStrings(java.lang.String full)
Get last two dot separated string part. |
static java.lang.StringBuffer |
getSpaces(int length)
Get amount of spaces. |
static java.lang.String |
getSystemLineSeparator()
Get platform dependent line separator. |
static byte[] |
hex2byte(java.lang.String hex)
Get a byte array of a hex string representation. |
static java.lang.String |
hex2String(java.lang.String hex)
Get a String out of a hex string representation. |
static java.lang.String |
hex2String(java.lang.String hex,
java.lang.String encoding)
Get a String out of a hex string representation. |
static boolean |
isIn(java.lang.String lookFor,
java.lang.String[] array)
Does a given string is an element of a given string array? |
static boolean |
isLetterDigitString(java.lang.String text)
Tests if given String begins with a letter and contains
only letters and digits. |
static boolean |
isNotIn(java.lang.String lookFor,
java.lang.String[] array)
Does a given string is not an element of a given string array? |
static java.lang.String |
quote(java.lang.String unquoted)
Quotes a String . |
static void |
replace(java.lang.StringBuffer text,
java.lang.String search,
java.lang.String replace)
Replaces all occurrences of search in text
by replace . |
static java.lang.String |
replace(java.lang.String text,
java.lang.String search,
java.lang.String replace)
Replaces all occurrences of search in text
by replace and returns the result. |
static java.lang.String[] |
split(java.lang.String text,
java.lang.String delimiter)
Split String by given delimiter. |
static java.lang.String |
string2Hex(java.lang.String data)
Get a hex string representation for a String. |
static java.lang.String |
string2Hex(java.lang.String data,
java.lang.String encoding)
Get a hex string representation for a String. |
static java.lang.String |
substring(java.lang.String text,
int position,
int length)
Return substring of text. |
static java.lang.String |
toString(java.util.Map map)
Returns a readable presentation of a Map. |
static java.lang.String |
toString(java.lang.Object[] list)
Returns a readable presentation of an Object array. |
static java.lang.String |
toString(java.util.Set set)
Returns a readable presentation of a Set. |
static java.lang.String |
unescapeXml(java.lang.String value)
Unescapes a string containing XML entity escapes to a string containing the actual Unicode characters corresponding to the escapes. |
static java.lang.String |
useSystemLineSeparator(java.lang.String text)
Creates String with platform dependent line ends. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static java.lang.String replace(java.lang.String text, java.lang.String search, java.lang.String replace)
search
in text
by replace
and returns the result.
text
- text to work on, can be null
search
- replace this text by replace
, can be null
replace
- replacement for search
, can be null
null
)public static void replace(java.lang.StringBuffer text, java.lang.String search, java.lang.String replace)
search
in text
by replace
.
text
- Text to work on. Must not be null
.search
- replace this text by replace
. Can be null
.replace
- replacement for search
. Can be null
.
java.lang.NullPointerException
- text
is null
.public static java.lang.String substring(java.lang.String text, int position, int length)
text
- Text to work on. Must not be null
.position
- Starting position. Might be negative.length
- Maximum length to get.
length
and starting with position.
java.lang.NullPointerException
- text
is null
.public static java.lang.String toString(java.lang.Object[] list)
CharSequence
are quoted.
list
- List of Objects.
public static java.lang.String toString(java.util.Set set)
CharSequence
are quoted.
set
- Set of objects.
public static java.lang.String toString(java.util.Map map)
map
- Map of objects mappings.
public static java.lang.String asLines(java.util.Set set)
set
- Set of objects.
public static java.lang.String quote(java.lang.String unquoted)
String
. A a quote character " is appended at the
beginning and the end of the String
. If a quote character occurs
within the string it is replaced by two quotes.
unquoted
- the unquoted String
, must not be null
String
java.lang.NullPointerException
- if unquoted == null
public static boolean isLetterDigitString(java.lang.String text)
String
begins with a letter and contains
only letters and digits.
text
- test this
text
only made of letters and digits and has
a leading letter?
java.lang.NullPointerException
- if text == null
public static java.lang.StringBuffer getSpaces(int length)
length
- number of spaces
number
spacespublic static java.lang.String getLastDotString(java.lang.String full)
full
- String with dots in it. Also null
is accepted.
full
. Is never null
.public static java.lang.String getLastTwoDotStrings(java.lang.String full)
full
- String with dots in it. Also null
is accepted.
full
. Is never null
.public static java.lang.String getClassName(java.lang.Class clazz)
clazz
- Class.
public static void deleteLineLeadingWhitespace(java.lang.StringBuffer buffer)
For example the following text
Do you know the muffin man, The muffin man, the muffin man, Do you know the muffin man, Who lives on Drury Lane?will be converted into:
Do you know the muffin man, The muffin man, the muffin man, Do you know the muffin man, Who lives on Drury Lane?
buffer
- Work on this text.public static java.lang.String escapeProperty(java.lang.String value)
value
- Escape this value.
public static final java.lang.String alignRight(long number, int length)
length
is
shorter than the String representation of number
no digit is cut. So the
resulting String might be longer than length
.
number
- Format this long.length
- Maximum length. Must not be bigger than 20 and less than 1.
length
, trimmed with leading spaces.public static final java.lang.String alignRight(java.lang.String string, int length)
string
- Format this string.length
- Minimum length. Must not be bigger than 20 and less than 1.
length
, trimmed with leading spaces.public static final java.lang.String format(long number, int length)
number
- Format this long.length
- Maximum length. Must not be bigger than 20 and less than 1.
length
, trimmed with leading spaces.public static java.lang.String byte2Hex(byte[] data)
data
- byte
array to work on
public static java.lang.String string2Hex(java.lang.String data)
data
- String to work on
public static java.lang.String string2Hex(java.lang.String data, java.lang.String encoding) throws java.io.UnsupportedEncodingException
data
- String to work onencoding
- Use this String encoding.
java.io.UnsupportedEncodingException
- Encoding not supported.public static byte[] hex2byte(java.lang.String hex)
hex
- Hex string representation of data.
java.lang.IllegalArgumentException
- Padding wrong or illegal hexadecimal character.public static java.lang.String hex2String(java.lang.String hex)
hex
- Hex string representation of data.
java.lang.IllegalArgumentException
- Padding wrong or illegal hexadecimal character.public static java.lang.String hex2String(java.lang.String hex, java.lang.String encoding) throws java.io.UnsupportedEncodingException
hex
- Hex string representation of data.encoding
- Use this String encoding.
java.io.UnsupportedEncodingException
- Encoding not supported.
java.lang.IllegalArgumentException
- Padding wrong or illegal hexadecimal character.public static java.lang.String getSystemLineSeparator()
"\n"
on UNIX).
public static java.lang.String useSystemLineSeparator(java.lang.String text)
text
is null
or empty nothing is changed. At the end of the String the platform dependent line end is
added whether or not the original text ends with such a sequence.
text
- Text with CR or CR LF as line end markers. Might be null
.
public static java.lang.String[] split(java.lang.String text, java.lang.String delimiter)
text
- Text to split.delimiter
- Split at these points.
public static java.lang.String escapeXml(java.lang.String value)
Escapes the characters in a String
using XML entities.
For example: "bread" & "butter" => "bread" & "butter".
Supports only the five basic XML entities (gt, lt, quot, amp, apos). Does not support DTDs or external entities.
Note that unicode characters greater than 0x7f are currently escaped to their numerical \\u equivalent. This may change in future releases.
value
- The String
to escape, may be null.
String
, null
if null string inputunescapeXml(java.lang.String)
public static java.lang.String unescapeXml(java.lang.String value)
Unescapes a string containing XML entity escapes to a string containing the actual Unicode characters corresponding to the escapes.
Supports only the five basic XML entities (gt, lt, quot, amp, apos). Does not support DTDs or external entities.
Note that numerical \\u unicode codes are unescaped to their respective unicode characters. This may change in future releases.
value
- The String
to unescape, may be null.
String
, null
if null string inputescapeXml(String)
public static boolean isNotIn(java.lang.String lookFor, java.lang.String[] array)
lookFor
- Look for this string.array
- The array we look through.
public static boolean isIn(java.lang.String lookFor, java.lang.String[] array)
lookFor
- Look for this string.array
- The array we look through.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |