|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object edu.nrao.sss.util.StringUtil
public class StringUtil
A utility class for manipulating text strings.
Version Info:
$Revision: 1351 $ |
$Date: 2008-06-13 14:11:55 -0600 (Fri, 13 Jun 2008) $ |
$Author: dharland $ |
Field Summary | |
---|---|
static String |
EOL
Returns the end-of-line string. |
Method Summary | |
---|---|
String |
capitalizeFirstLetterOfEachWord(String str)
Returns a string based on str where
the first letters of each word are converted to upper case. |
String |
format(double number,
double stdBeg,
double stdEnd)
Returns a text representation of number . |
String |
formatNoScientificNotation(BigDecimal number)
Returns a text representation of number . |
String |
formatNoScientificNotation(BigDecimal number,
int minFracDigits,
int maxFracDigits)
Returns a text representation of number . |
String |
formatNoScientificNotation(double number)
Returns a text representation of number . |
String |
formatNoScientificNotation(double number,
int minFracDigits,
int maxFracDigits)
Returns a text representation of number . |
String |
fromCollection(Collection<?> source,
String separator)
Returns a string that is the result of calling toString() on every
member of source and inserting separator between each
member. |
String |
fromCollection(Collection<?> source,
String separator,
boolean appendSeparatorToEnd)
Returns a string that is the result of calling toString() on every
member of source and inserting separator between each
member. |
static StringUtil |
getInstance()
Returns an instance of this string utility. |
String |
getSpacer(int multiplier)
|
Pattern |
globToPattern(String glob)
Calls globToRegex(java.lang.String) to create a regex string, then compiles that regex and
returns the resultant pattern. |
String |
globToRegex(String glob)
Converts a glob expression to a regex. |
String |
globToSqlLike(String glob,
char escape)
Converts a glob expression to an SQL LIKE expression. |
String |
lowerAndCapitalizeFirstLetterOfEachWord(String str)
Returns a string based on str that is in lower case, except for
the first letters of each word, which are in upper case. |
String |
normalizeString(String str)
Returns a normalized version of str . |
Collection<String> |
toCollection(String source,
String separator,
Collection<String> destination)
Returns a collection of strings that was built by parsing source ,
using separator as a delimiter. |
Collection<String> |
toCollection(String source,
String separator,
Collection<String> destination,
boolean addMissingFinalSeparator)
Returns a collection of strings that was built by parsing source ,
using separator as a delimiter. |
String |
toXmlName(String name,
char replacementForIllegalChars)
Returns a valid XML Name by replacing illegal characters in name
with replacementForIllegalChars . |
String |
toXmlNCName(String name,
char replacementForIllegalChars)
Returns a valid XML non-colonized name by replacing illegal characters in name with replacementForIllegalChars . |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String EOL
Method Detail |
---|
public static StringUtil getInstance()
public String normalizeString(String str)
str
.
Normalization means the following:
str
is null,
the empty string (""
) is returned.
str
- the string to be normalized.
str
.String.trim()
public String lowerAndCapitalizeFirstLetterOfEachWord(String str)
str
that is in lower case, except for
the first letters of each word, which are in upper case.
Example:
str
- the input string.
capitalizeFirstLetterOfEachWord(String)
public String capitalizeFirstLetterOfEachWord(String str)
str
where
the first letters of each word are converted to upper case.
Example:
str
- the input string.
lowerAndCapitalizeFirstLetterOfEachWord(String)
public String getSpacer(int multiplier)
public String format(double number, double stdBeg, double stdEnd)
number
.
The returned text is similar to that provided by
Double.toString(double)
, except that the
range of numbers where scientific notation is not
used is given by the other parameters.
If number
is such that
stdBeg <= number <= stdEndscientific notation will not be used.
number
- the number for which a text representation is needed.stdBeg
- the minimum absolute value where regular notation
should be preferred to scientific notation.
This should be a non-negative number.stdEnd
- the maximum absolute value where regular notation
should be preferred to scientific notation.
This should be a non-negative number.
number
.public String formatNoScientificNotation(double number)
number
.
The returned text is similar to that provided by
Double.toString(double)
, except that
scientific notation is never used.
number
- the number for which a text representation is needed.
number
.public String formatNoScientificNotation(double number, int minFracDigits, int maxFracDigits)
number
.
The returned text is similar to that provided by
Double.toString(double)
, except that
scientific notation is never used.
number
- the number for which a text representation is needed.minFracDigits
- the minimum number of digits after the decimal point.maxFracDigits
- the maximum number of digits after the decimal point.
number
.public String formatNoScientificNotation(BigDecimal number)
number
.
There will always be at least one digit after the decimal
point.
If number
is determined by
MathUtil.doubleValueIsInfinite(BigDecimal)
to
be infinite, the returned text will be either
"+infinity" or "-infinity".
number
- the number for which a text representation is needed.
number
.public String formatNoScientificNotation(BigDecimal number, int minFracDigits, int maxFracDigits)
number
.
number
- the number for which a text representation is needed.minFracDigits
- the minimum number of digits after the decimal point.maxFracDigits
- the maximum number of digits after the decimal point.
number
.public String fromCollection(Collection<?> source, String separator)
toString()
on every
member of source
and inserting separator
between each
member. A null member will be represented by the empty string.
The returned string does not contain a trailing separator
(unless the final member of source
was the empty string or ended
with the separator). This is a convenience method that is equivalent
to calling fromCollection(source, separator, false)
.
It is the client's duty to select a separator that will not be present in the string representation of any of the members of the source collection.
source
- a collection of objects that will be turned into a single
string.separator
- the text used to separate one member of the collection
from another.
source
. If the collection is
empty, the empty string ("") is returned.public String fromCollection(Collection<?> source, String separator, boolean appendSeparatorToEnd)
toString()
on every
member of source
and inserting separator
between each
member. A null member will be represented by the empty string.
It is the client's duty to select a separator that will not be present in the string representation of any of the members of the source collection.
source
- a collection of objects that will be turned into a single
string.separator
- the text used to separate one member of the collection
from another.appendSeparatorToEnd
- if true, this method adds a final
separator at the end of the returned string.
source
. If the collection is
empty, the empty string ("") is returned.public Collection<String> toCollection(String source, String separator, Collection<String> destination)
source
,
using separator
as a delimiter.
Note: the separator
is not interpreted as a
regular expression, but just as a simple string. This allows a client
to call toString
and fromString
with the same delimiter
and obtain sensible results. Also, a final delimiter is assumed, if
not already present. That is, using ";" as a delimiter, the following
text would result in the set of integers from one through five:
1;2;3;4;5. Consecutive delimiters will result in empty-string
("") elements.
This is a convenience method that is equivalent to calling
toCollection(source, separator, desination, true)
.
source
- a string representation of a collection.separator
- text that separates one member of a collection from
another in the source
text.destination
- the collection into which the members created from
source
are added. If this parameter is
null, a new collection will be created and
used.
source
,
using separator
as a delimiter.public Collection<String> toCollection(String source, String separator, Collection<String> destination, boolean addMissingFinalSeparator)
source
,
using separator
as a delimiter.
Note: the separator
is not interpreted as a
regular expression, but just as a simple string. This allows a client
to call toString
and fromString
with the same delimiter
and obtain sensible results.
Consecutive delimiters will result in empty-string ("")
elements.
source
- a string representation of a collection.separator
- text that separates one member of a collection from
another in the source
text.destination
- the collection into which the members created from
source
are added. If this parameter is
null, a new collection will be created and
used.addMissingFinalSeparator
- if true, any characters in
source
between the final separator and the end of the
string will be treated as the final string added to
destination
. If false, any characters after
the final separator are discarded.
source
,
using separator
as a delimiter.public String toXmlName(String name, char replacementForIllegalChars)
name
with replacementForIllegalChars
.
If there are no illegal characters, name
is returned unaltered.
If the first character of name
is normally a legal value, but is
not legal as the first character in an XML Name, the replacement
character is inserted prior to the first character in
name
.
replacementForIllegalChars
- a character to use as a replacement for
illegal characters in name
.
name
.public String toXmlNCName(String name, char replacementForIllegalChars)
name
with replacementForIllegalChars
.
If there are no illegal characters, name
is returned unaltered.
If the first character of name
is normally a legal value, but is
not legal as the first character in an XML NCName, the replacement
character is inserted prior to the first character in
name
.
XML Schema's ID and IDREF types are subtypes of NCName. That is, any string used as an ID must be a legal NCName.
replacementForIllegalChars
- a character to use as a replacement for
illegal characters in name
.
name
.public String globToSqlLike(String glob, char escape)
*
-- matches 0 or more of any character?
-- matches 1 of any character
public String globToRegex(String glob)
*
-- matches 0 or more of any character?
-- matches 1 of any character
glob
.public Pattern globToPattern(String glob)
globToRegex(java.lang.String)
to create a regex string, then compiles that regex and
returns the resultant pattern. The Pattern has the CASE_INSENSITIVE and
UNICODE_CASE flags set.
RuntimeException
- if the value returned by globToRegex is not a
valid regex. Note: this should never happen but may if there's a
programmer error in globToRegex.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |