|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sf.mmm.util.lang.base.StringUtilImpl
@Singleton @Named public class StringUtilImpl
This is the implementation of the StringUtil
interface.
getInstance()
Field Summary | |
---|---|
private static StringUtil |
instance
|
private static char[] |
SEPARATORS
|
Fields inherited from interface net.sf.mmm.util.lang.api.StringUtil |
---|
EMPTY_CHAR_ARRAY, EMPTY_STRING_ARRAY, FALSE, LINE_SEPARATOR, LINE_SEPARATOR_CR, LINE_SEPARATOR_CRLF, LINE_SEPARATOR_LF, LINE_SEPARATOR_LFCR, TRUE |
Constructor Summary | |
---|---|
StringUtilImpl()
The constructor. |
Method Summary | |
---|---|
String |
fromCamlCase(String string,
char separator)
This method converts the given string from caml-case syntax to
lower-case using the given separator as word-boundary. |
static StringUtil |
getInstance()
This method gets the singleton instance of this StringUtilImpl . |
boolean |
isEmpty(String string)
This method determines if the given string contains no information. |
boolean |
isEmpty(String string,
boolean trim)
This method determines if the given string is empty. |
boolean |
isSubstring(char[] string,
String substring,
int offset)
This method checks if the given string
contains the given
substring at the given offset . |
boolean |
isSubstring(String string,
String substring,
int offset)
This method checks if the given string
contains the given
substring at the given offset . |
String |
padNumber(long number,
int digits)
This method formats a positive number to a string with at least the given number of digits padding it with leading zeros. |
String |
padNumber(long number,
int digits,
int radix)
This method formats a positive number to a string using the given radix with at least the given number of digits padding it with
leading zeros. |
Boolean |
parseBoolean(String booleanValue)
This method parses a boolean value given as string. |
void |
replace(char[] string,
char oldChar,
char newChar)
This method replaces all occurrences of oldChar in the
char-array given by string with newChar . |
String |
replace(String string,
String match,
String replace)
This method replaces all occurrences of the string match with
the string replace in the given string. |
String |
replaceSuffixWithCase(String string,
int suffixLength,
String newSuffixLowerCase)
This method delegates to StringUtil.replaceSuffixWithCase(String, int, String, Locale) using
Locale.ENGLISH . |
String |
replaceSuffixWithCase(String string,
int suffixLength,
String newSuffixLowerCase,
Locale locale)
This method replaces the last suffixLength number of
characters from string with the lower-case string
newSuffixLowerCase with respect to the original case of the
given string . |
String |
toCamlCase(String string)
This method converts the given string to caml-case syntax
using the default separators ' ' , '-' ,
'_' and '.' |
String |
toCamlCase(String string,
char... separators)
This method converts the given string to caml-case syntax. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static StringUtil instance
getInstance()
private static final char[] SEPARATORS
toCamlCase(String)
Constructor Detail |
---|
public StringUtilImpl()
Method Detail |
---|
public static StringUtil getInstance()
StringUtilImpl
.getInstance()
methods and
construct new instances via the container-framework of your choice (like
plexus, pico, springframework, etc.). To wire up the dependent components
everything is properly annotated using common-annotations (JSR-250). If
your container does NOT support this, you should consider using a better
one.
public Boolean parseBoolean(String booleanValue)
parseBoolean
in interface StringUtil
booleanValue
- is the boolean value as string.
true
if the given string
equals
to
true
, false
if it
equals
to
false
and null
in any other case.Boolean.valueOf(String)
public void replace(char[] string, char oldChar, char newChar)
oldChar
in the
char-array given by string
with newChar
.
replace
in interface StringUtil
string
- is the char-array where the replacement should take place.oldChar
- is the character to be replaced.newChar
- is the replacement for oldChar
.String.replace(char, char)
public String replace(String string, String match, String replace)
match
with
the string replace
in the given string.
replace
in interface StringUtil
string
- is the string where to replace.match
- is the string that is searched and replaced.replace
- is the string match
is substituted with.
match
replaced by replace
.public boolean isSubstring(String string, String substring, int offset)
string
contains
the given
substring
at the given offset
.string.indexOf(substring, offset) == offsetor
string.substring(offset).beginsWith(substring)
isSubstring
in interface StringUtil
string
- is the string potentially containing substring
.substring
- is the substring that should be contained in
string
at the given offset
.offset
- is the offset in string
where to check for
substring
.
true
if the given string
contains
the given
substring
at the given offset
and
false
otherwise.public boolean isSubstring(char[] string, String substring, int offset)
string
contains
the given
substring
at the given offset
.string.indexOf(substring, offset) == offsetor
string.substring(offset).beginsWith(substring)
isSubstring
in interface StringUtil
string
- is the char[] representing the string potentially containing
substring
.substring
- is the substring that should be contained in
string
at the given offset
.offset
- is the offset in string
where to check for
substring
.
true
if the given string
contains
the given
substring
at the given offset
and
false
otherwise.public String replaceSuffixWithCase(String string, int suffixLength, String newSuffixLowerCase)
StringUtil.replaceSuffixWithCase(String, int, String, Locale)
using
Locale.ENGLISH
.
replaceSuffixWithCase
in interface StringUtil
string
- is the string to replace.suffixLength
- is the length of the suffix from string
to
replace.newSuffixLowerCase
- is the new suffix for the given
string
in lower-case
.
string
with the last
suffixLength
characters cut off and replaced by
newSuffixLowerCase
with respect to the original case
of string
.StringUtil.replaceSuffixWithCase(String, int, String, Locale)
public String replaceSuffixWithCase(String string, int suffixLength, String newSuffixLowerCase, Locale locale)
suffixLength
number of
characters from string
with the lower-case string
newSuffixLowerCase
with respect to the original case of the
given string
.Locale.ENGLISH
:string |
suffixLength |
newSuffixLowerCase |
|
---|---|---|---|
foobar | 3 | foo | foofoo |
FOOBAR | 3 | foo | FOOFOO |
FooBar | 3 | foo | FooFoo |
FooBar | 2 | foo | FooBfoo |
replaceSuffixWithCase
in interface StringUtil
string
- is the string to replace.suffixLength
- is the length of the suffix from string
to
replace.newSuffixLowerCase
- is the new suffix for the given
string
in lower-case
.locale
- is the locale used for case transformation.
string
with the last
suffixLength
characters cut off and replaced by
newSuffixLowerCase
with respect to the original case
of string
.public boolean isEmpty(String string)
isEmpty
in interface StringUtil
string
- is the string to check.
true
if the given string is null
or has a
trimmed length of zero, false
otherwise.StringUtil.isEmpty(String, boolean)
public boolean isEmpty(String string, boolean trim)
isEmpty
in interface StringUtil
string
- is the string to check.trim
- if whitespaces should be ignored and a string with a trimmed
length of zero is considered as empty.
true
if the given string is null
or has a
(trimmed) length of zero, false
otherwise.public String padNumber(long number, int digits)
padNumber(5, 3)
will return "005"
padNumber(25, 3)
will return "025"
padNumber(100, 3)
will return "100"
padNumber
in interface StringUtil
number
- is the positive number to format.digits
- is the (minimum) number of digits required.
digits
. If the number is less, leading zeros are
appended.public String padNumber(long number, int digits, int radix)
radix
with at least the given number of digits padding it with
leading zeros.padNumber(31, 3, 16)
will return "01f"
padNumber(5, 6, 2)
will return "000101"
digits
: Radix | byte | short | int | long |
---|---|---|---|---|
2 | 8 | 16 | 32 | 64 |
8 | 3 | 6 | 9 | 12 |
10 | 3 | 5 | 9 | 19 |
16 | 2 | 4 | 8 | 16 |
padNumber
in interface StringUtil
number
- is the positive number to format.digits
- is the (minimum) number of digits required.radix
- is the radix to use.
digits
. If the number is less, leading zeros are
appended.public String toCamlCase(String string)
string
to caml-case syntax
using the default separators ' '
, '-'
,
'_'
and '.'
.
toCamlCase
in interface StringUtil
string
- is the string to convert.
string
in caml-case syntax.StringUtil.toCamlCase(String, char[])
public String toCamlCase(String string, char... separators)
string
to caml-case syntax.string
that are in the list given by
separators
and capitalizes the first character of the
following word.string | toCamlCase(string) |
---|---|
foo bar |
fooBar |
aAa-bBB-CcC |
aAaBBBCcC |
X--m_._l.. |
XML |
toCamlCase
in interface StringUtil
string
- is the string to convert.separators
- is the list of characters that are treated as
word-separators.
string
in caml-case syntax.public String fromCamlCase(String string, char separator)
string
from caml-case syntax to
lower-case using the given separator
as word-boundary.string | separator | fromCamlCase (string, separator) |
---|---|---|
FooBar | - | foo-bar |
someWordMix | . | some.word.mix |
AbbreviationsLikeXMLshouldNotBeCapitalized | _ | abbreviations_like_xmlshould_not_be_capitalized |
FOO_BAR | * | foo_bar |
fromCamlCase
in interface StringUtil
string
- is the string to convert.separator
- is the character to insert at word-boundaries indicated by
a switch from lower- to upper-case.
string
in lower-case with the given
separator
inserted at word-boundaries.StringUtil.toCamlCase(String, char...)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |