|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectedu.neu.ccs.Strings
Class Strings contains a set of static methods
to provide fast and human-readable encoding of an array of
String data together with corresponding tools
for decoding such data.
Class Strings also contains miscellaneous
String utilities.
An encoded string will have one of the following forms that we will refer to as a string group:
[s0;s1;...](s0,s1,...){s0|s1|...}A string group enclosed in [] uses the
character ; as its string separator.
A string group enclosed in () uses the
character , as its string separator.
A string group enclosed in {} uses the
character | as its string separator.
The encoding methods in this class are NOT 100% robust
since the decoding process will fail if any encoded string contains
the separator character used for the encoding. To guarantee robust
encoding, use the encoding methods in CodecUtilities.
Despite this consideration, these methods of encoding and decoding are quite valuable in the situations where what is to be encoded refers to data that should not contain the particular separator being used. It is for this reason that three forms of encoding are provided with three separators.
The method decodeStringGroup directly looks for the
type of encoding performed by the encoding methods in this class.
The more general method decode tries 3 algorithms in
turn including CodecUtilities.decode to see if the
given string has been encoded in any of 3 possible ways. It is
recommended that the method decode in this class be
used for general decoding of a string into a string array.
As a helpful support tool, this class contains a method
tokenize that uses a StringTokenizer to
break a string into a string array of tokens according to a given
list of delimiters. Optionally, the trim method may
be invoked to trim the tokens. There are parallel methods that
make delimited strings.
As of 2.5.0, this class also contains methods that will split
strings corresponding to a character delimiter and will not make
adjacent delimiters be treated as a single delimiter. These
methods begin with exactSplit in their name. There
are also parallel methods with exactMake in their
name that make delimited strings.
This class contains methods to build name-value string pairs of the form name=value and to decompose such pairs.
This class contains utility methods to convert between arrays of string and arrays of long or double.
This class contains utility methods to pad strings and to combine string pairs with a blank separator.
Finally, this class contains a simple utility to convert a string to the equivalent HTML string with ampersand, less than, greater than, and quote encoded.
Class Strings cannot be instantiated.
| Field Summary | |
static char |
BRACES
The start character for encodings {s0|s1|etc}. |
static char |
BRACES_END
The end character for encodings {s0|s1|etc}. |
static char |
BRACES_SEP
The separator character for encodings {s0|s1|etc}
as a string. |
static char |
BRACKETS
The start character for encodings [s0;s1;etc]. |
static char |
BRACKETS_END
The end character for encodings [s0;s1;etc]. |
static char |
BRACKETS_SEP
The separator character for encodings [s0;s1;etc]
as a string. |
private static char |
EQUALS
The equals character. |
static char |
PARENS
The start character for encodings (s0,s1,etc). |
static char |
PARENS_END
The end character for encodings (s0,s1,etc). |
static char |
PARENS_SEP
The separator character for encodings (s0,s1,etc)
as a string. |
| Constructor Summary | |
private |
Strings()
Prevent instantiation. |
| Method Summary | |
static String[] |
decode(String string)
Attempts several algorithms to decode the given string into an array of strings and returns this array if successful and returns null if unsuccessful with all attempts. |
static String[] |
decodeStringGroup(String string)
Returns a String array by decoding the given
string assuming it is encoded by the encoding conventions of
this class. |
static String[] |
doublesToStrings(double[] data)
Returns an array of strings corresponding to the given array of double. |
static String |
encode(String[] data)
Returns the encoded String array as
[s0;s1;etc]
where s0, s1, etc represent the array elements. |
static String |
encodeStringGroup(char start,
String[] data)
Returns the encoded String array as
a sequence enclosed with the given start character,
its matching end character, and its associated
separator character. |
static String |
encodeWithBraces(String[] data)
Returns the encoded String array as
{s0|s1|etc}
where s0, s1, etc represent the array elements. |
static String |
encodeWithBrackets(String[] data)
Returns the encoded String array as
[s0;s1;etc]
where s0, s1, etc represent the array elements. |
static String |
encodeWithParens(String[] data)
Returns the encoded String array as
(s0,s1,etc)
where s0, s1, etc represent the array elements. |
static String |
exactMakeCommaList(String[] data)
Uses the array of strings to build a string that separates each item with a comma; automatically trims the array before the build. |
static String |
exactMakeNewlineList(String[] data)
Uses the array of strings to build a string that separates each item with a newline; automatically trims the array before the build. |
static String |
exactMakeSeparatorList(String[] data,
char delimiter)
Uses the array of strings to build a string that separates each item with the given delimiter; automatically trims the array before the build. |
static String |
exactMakeSeparatorList(String[] data,
char delimiter,
boolean trim)
Uses the array of strings to build a string that separates each item with the given delimiter; if trim is true then trims the array before the build. |
static String[] |
exactSplitCommaList(String string)
Returns an array of strings obtained by splitting the given string at every occurence of the comma character; automatically trims the array returned. |
static String[] |
exactSplitList(String string,
char delimiter)
Returns an array of strings obtained by splitting the given string at every occurence of the given delimiter; automatically trims the array returned. |
static String[] |
exactSplitList(String string,
char delimiter,
boolean trim)
Returns an array of strings obtained by splitting the given string at every occurence of the given delimiter; if trim is true then also trims the array returned. |
static String[] |
exactSplitNewlineList(String string)
Returns an array of strings obtained by splitting the given string at every occurence of the newline character; automatically trims the array returned. |
static String |
flatten(String data)
Returns a string with all whitespace but non-blank characters replaced by blanks. |
static String[] |
flatten(String[] data)
Returns a string array with all strings in the original array flattened using Strings.flatten. |
static int |
getIndexValue(String message)
Returns the array index that was prepended to an error message thrown by stringsToLongs
or stringsToDoubles. |
static String |
getName(String string)
Given a string of the form name=value, return the name portion. |
static String[] |
getNames(String[] pairs)
Given an array of name-value pairs, returns the array of names. |
static String |
getValue(String string)
Given a string of the form name=value, return the value portion. |
static String[] |
getValues(String[] pairs)
Given an array of name-value pairs, returns the array of values. |
static boolean |
isNonTrivialWhitespace(char c)
Returns true if the given character is whitespace but is non-blank. |
static boolean |
isStartEnd(String string,
char start,
char end)
Returns true if the given string starts and ends with the given pair of distinct start and end characters. |
static String |
joinWithSpace(String s,
String t)
If s and t are both non- null then return
(s+blank+t). |
static String[] |
longsToStrings(long[] data)
Returns an array of strings corresponding to the given array of longs. |
static ParseException |
makeAdjustedParseException(ParseException ex,
String type,
String[] names)
Returns a new ParseException based on
the given ParseException but adjusted to
include information from the given type name and the
given field names. |
static String |
makeCommaList(String[] arrayList)
Creates a comma separated list by trimming the data in the given String array and concatenating with commas. |
static String |
makeNameValuePair(String name,
String value)
Given a pair of strings name and value, return the string name=value. |
static String[] |
makeNameValuePairs(String[] names,
String[] values)
Given an array of names and an array of values, constructs and returns an array of pairs of the form: name=value. |
static String |
makeSeparatorList(String[] arrayList,
char separator)
Creates a separated list by trimming the data in the given String array and concatenating with the given separator. |
static String |
pad(String s)
Returns the given string if it is non- null
and has length at least 1; otherwise returns " ". |
static String[] |
pad(String[] data)
Returns a string array with all strings in the original array padded using Strings.pad. |
static String[] |
padOnLeft(String[] data,
int width)
Returns a string array with all strings in the original array padded using Strings.padOnLeft. |
static String |
padOnLeft(String s,
int width)
Return the string s padded with blanks on the left. |
static String[] |
padOnRight(String[] data,
int width)
Returns a string array with all strings in the original array padded using Strings.padOnRight. |
static String |
padOnRight(String s,
int width)
Return the string s padded with blanks on the right. |
static String |
prefixRepeatChar(String string,
char c,
int count)
Returns a string with count instances of the given character c prefixed to the given string. |
static String |
removeIndexValue(String message)
Returns the error message with its prepended index value removed. |
static String[] |
splitCommaList(String commalist)
Extract the non-empty strings from a comma separated list. |
static String[] |
splitIn2(String string)
Splits the given string into 2 parts: a prefix and a suffix and returns these 2 parts in a string array. |
static String[] |
splitIn3(String string)
Splits the given string into 3 parts: a prefix, a string group, and a suffix and returns these 3 parts in a string array. |
static double[] |
stringsToDoubles(String[] data)
Returns an array of doubles
corresponding to the given array of strings. |
static long[] |
stringsToLongs(String[] data)
Returns an array of longs
corresponding to the given array of strings. |
static XComplex[] |
stringsToXComplexValues(String[] data)
Returns an array of XComplex values
corresponding to the given array of strings. |
static String |
suffixRepeatChar(String string,
char c,
int count)
Returns a string with count instances of the given character c suffixed to the given string. |
static String |
textToSafeHTML(String text)
Returns an HTML safe string built from the given string by replacing ampersand, less than, greater than, and quote with their HTML encodings; replaces tabs with spaces assuming a tab size of 4. |
static String |
textToSafeHTML(String text,
int tabsize)
Returns an HTML safe string built from the given string by replacing ampersand, less than, greater than, and quote with their HTML encodings; replaces tabs with spaces assuming the given tab size. |
static String[] |
tokenize(String string,
String delimiters,
boolean trim)
Returns a string array contains the tokens obtained by using a StringTokenizer to split the string
according to the given delimiters; if the given trim is
true then the tokens are trimmed before being returned. |
static String[] |
trim(String[] data)
Returns a string array with all strings in the original array trimmed using String.trim. |
static String[] |
XComplexValuesToStrings(XComplex[] data)
Returns an array of strings corresponding to the given array of XComplex. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
public static final char BRACKETS
[s0;s1;etc].
public static final char PARENS
(s0,s1,etc).
public static final char BRACES
{s0|s1|etc}.
public static final char BRACKETS_END
[s0;s1;etc].
public static final char PARENS_END
(s0,s1,etc).
public static final char BRACES_END
{s0|s1|etc}.
public static final char BRACKETS_SEP
[s0;s1;etc]
as a string.
public static final char PARENS_SEP
(s0,s1,etc)
as a string.
public static final char BRACES_SEP
{s0|s1|etc}
as a string.
private static final char EQUALS
| Constructor Detail |
private Strings()
| Method Detail |
public static String encode(String[] data)
Returns the encoded String array as
[s0;s1;etc]
where s0, s1, etc represent the array elements.
Equivalent to encodeWithBrackets.
data - the data to encodeencodeStringGroup(char, String[])public static String encodeWithBrackets(String[] data)
Returns the encoded String array as
[s0;s1;etc]
where s0, s1, etc represent the array elements.
Equivalent to encode.
data - the data to encodeencodeStringGroup(char, String[])public static String encodeWithParens(String[] data)
Returns the encoded String array as
(s0,s1,etc)
where s0, s1, etc represent the array elements.
data - the data to encodeencodeStringGroup(char, String[])public static String encodeWithBraces(String[] data)
Returns the encoded String array as
{s0|s1|etc}
where s0, s1, etc represent the array elements.
data - the data to encodeencodeStringGroup(char, String[])
public static String encodeStringGroup(char start,
String[] data)
Returns the encoded String array as
a sequence enclosed with the given start character,
its matching end character, and its associated
separator character.
If the given data array is null then
returns null to signal failure.
Assume the array elements are s0, s1, etc. Then the elements are encoded in one of the following ways.
[s0;s1;...](s0,s1,...){s0|s1|...}depending on whether the start character is
[, (, or {.
If the start character is none of the three characters
required then returns null to signal failure.
Each valid start character is paired with a corresponding separator character for the encoding.
[ is paired with the separator ;( is paired with the separator ,{ is paired with the separator |As of 2.5.0, the encoding-decoding algorithms were changed
to avoid the use of the Java class StringTokenizer.
In fact, the portion of the output string between the start and
end characters is computed by the following call:
exactMakeSeparatorList(data,separator,false)
This call ignores null strings in the data
array but makes an entry in the output string for all data
strings that are non-null even for those of
length 0. The parameter false means that no trimming is
done on the data strings.
To be robust and decodable, the encoded strings must not contain the separator character used in the encoding.
For a fully robust but more complex encoding, see the
classes in the codec package especially
CodecUtilities.
start - the start character for the encoding which must
be either [, (, or
{data - the array data to encodepublic static String[] decode(String string)
Attempts several algorithms to decode the given string into
an array of strings and returns this array if successful and
returns null if unsuccessful with all attempts.
Algorithm 1 uses CodecUtilities.decode to
attempt to parse the given string as a codec-encoded string.
Algorithm 2 calls splitIn2 and then calls
decodeStringGroup to parse the suffix as a
string group if possible.
Algorithm 3 calls splitIn3 and then calls
decodeStringGroup to parse the internal
string group if this string group is non-empty.
In particular, since this decode method calls the
decode method of CodecUtilities,
it is more general and is recommended as the preferred method for
decoding a string into an array of strings.
string - the string to decodepublic static String[] decodeStringGroup(String string)
Returns a String array by decoding the given
string assuming it is encoded by the encoding conventions of
this class.
The given string should be what we call a string group, that is, it should have one of the following forms.
[s0;s1;...](s0,s1,...){s0|s1|...}The string array returned contains s0 s1 ....
As of 2.5.0, even empty (zero length) strings will be included
in the array returned. The method exactSplitList
is used to split the string within the start and end grouping
characters.
To avoid issues with leading and trailing whitespace, the given string is trimmed prior to processing.
Returns null if.
null.[], (), or {}.
string - the string group to decode
public static boolean isStartEnd(String string,
char start,
char end)
Returns true if the given string starts and ends with the given pair of distinct start and end characters.
string - the string to teststart - the start characterend - the end characterpublic static String[] splitIn2(String string)
Splits the given string into 2 parts: a prefix and a suffix and returns these 2 parts in a string array.
The prefix consists of the longest substring of the given string
starting at the beginning that does not contain one of the following
start characters: [, (, or {.
If the given string does not contain any of the start characters, then the prefix is the given string and the suffix is the empty string.
Otherwise, the prefix is the substring up to but not including the first start character and the suffix is the rest of the string.
This algorithm does not guarantee that the suffix is a string group but if it is then it is the largest possible string group contained in the original string.
Returns null if the given string is null.
If the given string is non-null, then both strings in the
return array will be non-null.
string - the string to split
public static String[] splitIn3(String string)
Splits the given string into 3 parts: a prefix, a string group, and a suffix and returns these 3 parts in a string array.
The prefix consists of the longest substring of the given string
starting at the beginning that does not contain one of the following
start characters: [, (, or {.
If the given string does not contain any of the start characters, then the prefix is the given string and the other two parts are empty strings.
If a start character exists, then a search is made for the nearest matching end character that follows the start character. If such an end character is found then this defines the string group and the suffix is what is left. If no matching end character is found then the string group is empty and the suffix is the rest of the string including the unmatched start character.
With this specification, it is possible for the suffix to contain additional string groups that could be peeled off by repeated use of this method.
Returns null if the given string is null.
If the given string is non-null, then all three strings
in the return array will be non-null.
string - the string to split
public static String makeNameValuePair(String name,
String value)
Given a pair of strings name and value, return the string name=value.
If either string is null, return null.
name - the namevalue - the valuepublic static String getName(String string)
Given a string of the form name=value, return the name portion.
Return null if the given string is null.
Return an empty string if the given string does not contain an equals sign.
string - the name-value stringpublic static String getValue(String string)
Given a string of the form name=value, return the value portion.
Return null if the given string is null.
Return the given string if the given string does not contain an equals sign.
string - the name-value string
public static String[] makeNameValuePairs(String[] names,
String[] values)
Given an array of names and an array of values, constructs and returns an array of pairs of the form: name=value.
Returns null to signal failure if any of the
following situations takes place.
null.null entries.
names - the array of namesvalues - the array of valuespublic static String[] getNames(String[] pairs)
Given an array of name-value pairs, returns the array of names.
Returns null if the given array is
null.
Returns null if any entry in the given array is
null.
pairs - the array of name-value pairspublic static String[] getValues(String[] pairs)
Given an array of name-value pairs, returns the array of values.
Returns null if the given array is
null.
Returns null if any entry in the given array is
null.
pairs - the array of name-value pairspublic static String[] longsToStrings(long[] data)
Returns an array of strings
corresponding to the given array of longs.
Returns null if the given data is null.
data - the data to convert
public static String[] doublesToStrings(double[] data)
Returns an array of strings
corresponding to the given array of double.
Returns null if the given data is null.
data - the data to convert
public static String[] XComplexValuesToStrings(XComplex[] data)
Returns an array of strings
corresponding to the given array of XComplex.
Each XComplex is converted by the static method
XComplex.toStringData.
Returns null if the given data is null.
data - the data to convert
public static long[] stringsToLongs(String[] data)
throws ParseException
Returns an array of longs
corresponding to the given array of strings.
Returns null if the given data is null.
Trims the data strings prior to the numeric conversion.
In converting the i-th data item of the array to a long,
the following conventions and procedures are followed.
null or of length 0,
then the corresponding long is set to zero.fromStringData of XLong so that
arithmetic expressions will be evaluated. If this method
throws a ParseException then the exception is
rethrown with the following items prepended to the message
to make precise where in the array the error occured.i + ": "
data - the data to convert
ParseException
public static double[] stringsToDoubles(String[] data)
throws ParseException
Returns an array of doubles
corresponding to the given array of strings.
Returns null if the given data is null.
Trims the data strings prior to the numeric conversion.
In converting the i-th data item of the array to a double,
the following conventions and procedures are followed.
null or of length 0,
then the corresponding double is set to zero.fromStringData of XDouble so that
arithmetic expressions will be evaluated. If this method
throws a ParseException then the exception is
rethrown with the following items prepended to the message
to make precise where in the array the error occured.i + ": "
data - the data to convert
ParseException
public static XComplex[] stringsToXComplexValues(String[] data)
throws ParseException
Returns an array of XComplex values
corresponding to the given array of strings.
Returns null if the given data is null.
Trims the data strings prior to the numeric conversion.
In converting the i-th data item of the array to an XComplex,
the following conventions and procedures are followed.
null or of length 0,
then the corresponding XComplex is set to zero.fromStringData of XComplex. If
this method throws a ParseException then the
exception is rethrown with the following items prepended to
the message to make precise where in the array the error
occured.i + ": "
data - the data to convert
ParseExceptionpublic static int getIndexValue(String message)
Returns the array index that was prepended to an
error message thrown by stringsToLongs
or stringsToDoubles.
This is a hack required since there is no extra
data field in a ParseException to hold
the array index directly.
Returns 0 if the message has no prepended value.
message - the error messagepublic static String removeIndexValue(String message)
Returns the error message with its prepended index value removed.
Assumes that the original error message was created
by stringsToLongs or
stringsToDoubles.
This is a hack required since there is no extra
data field in a ParseException to hold
the array index directly.
Returns the message if the message has no prepended index value.
message - the error message
public static ParseException makeAdjustedParseException(ParseException ex,
String type,
String[] names)
Returns a new ParseException based on
the given ParseException but adjusted to
include information from the given type name and the
given field names.
Assumes that the given ParseException
was thrown by stringsToLongs or
stringsToDoubles while parsing the given
type.
The type name is used to make the user aware of the specific type whose data was being parsed.
The names array is used to replace the array index in the original message with a more understandable field name.
This is a helper method for the methods
fromStringData in
assorted Stringable classes.
ex - the original ParseExceptiontype - the type being parsednames - the field names that replace indicespublic static String[] trim(String[] data)
Returns a string array with all strings in the original
array trimmed using String.trim.
null data strings are returned as is.
Returns null if the given data array is
null.
Returns a newly constructed array but strings that were already trimmed in the original array will be returned as is.
data - the data to trimpublic static boolean isNonTrivialWhitespace(char c)
Returns true if the given character is whitespace but is non-blank.
c - the character to testpublic static String flatten(String data)
Returns a string with all whitespace but non-blank characters replaced by blanks.
This method is called flatten because it will turn a string with line feeds and carriage returns into one that may be viewed on a single line.
Returns the given string if it does not contain a character that is whitespace but non-blank.
data - the string to flattenpublic static String[] flatten(String[] data)
Returns a string array with all strings in the original
array flattened using Strings.flatten.
null data strings are returned as is.
Returns null if the given data array is
null.
Returns a newly constructed array but strings that were already flattened in the original array will be returned as is.
data - the data to flatten
public static String[] tokenize(String string,
String delimiters,
boolean trim)
Returns a string array contains the tokens obtained by
using a StringTokenizer to split the string
according to the given delimiters; if the given trim is
true then the tokens are trimmed before being returned.
If the given string is null, returns
null.
If the given delimiters string is null or
of length 0, return a string array with the given string
as its only element (possibly trimmed).
string - the string to tokenizedelimiters - the delimiter characterstrim - whether or not to trim the tokenspublic static String[] splitCommaList(String commalist)
Extract the non-empty strings from a comma separated list.
Return a zero length array if the list is null
or has length 0 after being trimmed.
This is a frequently used special case of the method
tokenize and so is explicitly given its own name.
commalist - a comma separated list of strings
public static String makeSeparatorList(String[] arrayList,
char separator)
Creates a separated list by trimming the data in the given String array and concatenating with the given separator.
The strings that are null or that trim to
length 0 strings will be omitted from the separator list.
arrayList - the array of strings to concatenateseparator - the separator characterpublic static String makeCommaList(String[] arrayList)
Creates a comma separated list by trimming the data in the given String array and concatenating with commas.
The strings that are null or that trim to
length 0 strings will be omitted from the separator list.
This is a frequently used special case of the method
makeSeparatorList and so is explicitly given its
own name.
arrayList - the array of strings to concatenate
public static String[] exactSplitList(String string,
char delimiter,
boolean trim)
Returns an array of strings obtained by splitting the given string at every occurence of the given delimiter; if trim is true then also trims the array returned.
If the delimiter occurs N times in the given string then the array returned will have size (N+1).
If the delimiter occurs in adjacent positions in the string then the corresponding split will have length 0.
This method avoids StringTokenizer since
that class groups adjacent delimiters.
If the given string is null, returns
null.
string - the string to splitdelimiter - the delimiter that defines the splittrim - whether or not to trim the array returned
public static String[] exactSplitList(String string,
char delimiter)
Returns an array of strings obtained by splitting the given string at every occurence of the given delimiter; automatically trims the array returned.
If the delimiter occurs N times in the given string then the array returned will have size (N+1).
If the delimiter occurs in adjacent positions in the string then the corresponding split will have length 0.
This method avoids StringTokenizer since
that class groups adjacent delimiters.
If the given string is null, returns
null.
string - the string to splitdelimiter - the delimiter that defines the splitpublic static String[] exactSplitCommaList(String string)
Returns an array of strings obtained by splitting the given string at every occurence of the comma character; automatically trims the array returned.
If comma occurs N times in the given string then the array returned will have size (N+1).
If comma occurs in adjacent positions in the string then the corresponding split will have length 0.
This method avoids StringTokenizer since
that class groups adjacent delimiters.
If the given string is null, returns
null.
string - the string to splitpublic static String[] exactSplitNewlineList(String string)
Returns an array of strings obtained by splitting the given string at every occurence of the newline character; automatically trims the array returned.
If newline occurs N times in the given string then the array returned will have size (N+1).
If newline occurs in adjacent positions in the string then the corresponding split will have length 0.
This method avoids StringTokenizer since
that class groups adjacent delimiters.
If the given string is null, returns
null.
string - the string to split
public static String exactMakeSeparatorList(String[] data,
char delimiter,
boolean trim)
Uses the array of strings to build a string that separates each item with the given delimiter; if trim is true then trims the array before the build.
If the given data is null, returns
null.
If the given data is non-null, then
the string returned is non-null.
If an item in the data array is null
then that item is skipped.
If M is the number of non-null items
in the data array then the delimiter will be placed
(M-1) times into the returned string to separate the
non-null items.
This method does not check whether or not the delimiter occurs within any item in the data array.
data - the string array to build into a stringdelimiter - the delimiter to use as a separatortrim - whether or not to trim before the build
public static String exactMakeSeparatorList(String[] data,
char delimiter)
Uses the array of strings to build a string that separates each item with the given delimiter; automatically trims the array before the build.
If the given data is null, returns
null.
If the given data is non-null, then
the string returned is non-null.
If an item in the data array is null
then that item is skipped.
If M is the number of non-null items
in the data array then the delimiter will be placed
(M-1) times into the returned string to separate the
non-null items.
This method does not check whether or not the delimiter occurs within any item in the data array.
data - the string array to build into a stringdelimiter - the delimiter to use as a separatorpublic static String exactMakeCommaList(String[] data)
Uses the array of strings to build a string that separates each item with a comma; automatically trims the array before the build.
If the given data is null, returns
null.
If the given data is non-null, then
the string returned is non-null.
If an item in the data array is null
then that item is skipped.
If M is the number of non-null items
in the data array then the comma will be placed
(M-1) times into the returned string to separate the
non-null items.
This method does not check whether or not a comma occurs within any item in the data array.
data - the string array to build into a stringpublic static String exactMakeNewlineList(String[] data)
Uses the array of strings to build a string that separates each item with a newline; automatically trims the array before the build.
If the given data is null, returns
null.
If the given data is non-null, then
the string returned is non-null.
If an item in the data array is null
then that item is skipped.
If M is the number of non-null items
in the data array then the newline will be placed
(M-1) times into the returned string to separate the
non-null items.
This method does not check whether or not a newline occurs within any item in the data array.
data - the string array to build into a stringpublic static String pad(String s)
Returns the given string if it is non-null
and has length at least 1; otherwise returns " ".
s - the string to pad to length at least 1public static String[] pad(String[] data)
Returns a string array with all strings in the original
array padded using Strings.pad.
Returns null if the given data array is
null.
data - the data to pad
public static String prefixRepeatChar(String string,
char c,
int count)
Returns a string with count instances of the given character c prefixed to the given string.
If string is null, it is set to
the empty string.
If count is negative it is set to 0.
string - the string to prefixc - the character to repeatcount - the number of repeats
public static String suffixRepeatChar(String string,
char c,
int count)
Returns a string with count instances of the given character c suffixed to the given string.
If string is null, it is set to
the empty string.
If count is negative it is set to 0.
string - the string to suffixc - the character to repeatcount - the number of repeats
public static String padOnLeft(String s,
int width)
Return the string s padded with blanks on the left.
First, if s is null, replace s with an
empty string.
Then, if s has length greater than or equal to width, return s.
Otherwise, return a string constructed with s on the right and (width-s.length()) blanks on the left.
s - the string to padwidth - the minimum width of the return string
public static String[] padOnLeft(String[] data,
int width)
Returns a string array with all strings in the original
array padded using Strings.padOnLeft.
Returns null if the given data array is
null.
data - the data to padwidth - the minimum width of each return string
public static String padOnRight(String s,
int width)
Return the string s padded with blanks on the right.
First, if s is null, replace s with an
empty string.
Then, if s has length greater than or equal to width, return s.
Otherwise, return a string constructed with s on the left and (width-s.length()) blanks on the right.
s - the string to padwidth - the minimum width of the return string
public static String[] padOnRight(String[] data,
int width)
Returns a string array with all strings in the original
array padded using Strings.padOnRight.
Returns null if the given data array is
null.
data - the data to padwidth - the minimum width of each return string
public static String joinWithSpace(String s,
String t)
If s and t are both non-null then return
(s+blank+t).
Otherwise, if one string is null, return
the other.
s - string 1 to joint - string 2 to joinpublic static String textToSafeHTML(String text)
Returns an HTML safe string built from the given string by replacing ampersand, less than, greater than, and quote with their HTML encodings; replaces tabs with spaces assuming a tab size of 4.
text - the string to convert to HTML
public static String textToSafeHTML(String text,
int tabsize)
Returns an HTML safe string built from the given string by replacing ampersand, less than, greater than, and quote with their HTML encodings; replaces tabs with spaces assuming the given tab size.
text - the string to convert to HTMLtabsize - the tabsize for conversion of tabs to spaces
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||