public class StringUtils extends Object
Constructor and Description |
---|
StringUtils() |
Modifier and Type | Method and Description |
---|---|
static List<String> |
asList(Iterator<String> it)
Converts a
Iterator<String> |
static String |
asString(Iterator<String> it,
String divider)
Returns a string which is the concatination of an iterator of strings with the divider in between.
|
static String |
asString(List<String> list)
Returns a string, which is all the Strings in the list, with "\n" between the strings.
|
static String |
asString(List<String> list,
String divider)
Returns a list of Strings and appends them to one list, with the divider in between.
|
static String |
asString(String[] stringArray,
String divider)
Returns a string which is the concatination of an array of strings with the divider in between.
|
static StringList |
asStringList(Iterator<String> it)
Converts a Iterator of Strings to a StringList.
|
static String |
bite(String s,
int maxLength,
int maxLineLength,
String lineDivider,
String maxLengthExceededIndicator)
Split a string in to bites divide in certain maxLineLength by "lineDivider".
|
static String |
bite(String s,
int maxLineLength,
String lineDivider)
Split a string in to bites divide in certain lengths by "lineDivider".
|
static String |
capitalize(String s)
The following method converts all the letters into upper/lower case, depending on their position near a space or other special chars.
|
static boolean |
doArrayContains(String[] array,
String value,
boolean ignoreCase)
Determines if a String value is contained in a String array.
|
static String |
escapeHtml(String s)
Escapes a characters in string to be HTML safe.
|
protected static String |
getCaseInsensitiveEnvironmentProperty(String key)
Finds a system env with the key value.
|
protected static String |
getCaseInsensitiveSystemProperty(String key)
Finds a system property with the key value.
|
static boolean |
isEmpty(String s)
Will determine if a String contains an empty value.
|
static String |
leftPad(String value,
char pad,
int length)
Left pads the a string with a char until has a certain length.
|
static String |
leftPad(String value,
int length)
Left pads the a string with space until has a certain length.
|
static String |
removeValueQuotes(String value)
If a string value starts and ends with either " (Quotation Mark) or ' (Apostrophe).
|
static String |
repeat(String s,
int times)
Repeat a string N times with linefeed "\\n" as divider in between.
|
static String |
repeat(String s,
String divider,
int times)
Repeat a string N times with a divider in between.
|
static String |
replaceEnvironmentProperties(String value)
Returns a converted string where all "
${name} " is replace with the corresponding env properties value, if the name is a valid env properties name. |
static String |
replaceInlinedProperties(String value)
Calls the two methods replaceSystemProperties(String) and replaceEnvironmentProperties(String).
|
static String |
replaceSystemProperties(String value)
Returns a converted string where all "
${name} " is replace with the corresponding system properties value, if the name is a valid system properties name. |
static String |
rightPad(String value,
char pad,
int length)
Right pads the a string with a char until has a certain length.
|
static String |
rightPad(String value,
int length)
Right pads the a string with a space until has a certain length.
|
static String |
shuffle(String s)
Shuffle the characters in string using the Collection.shuffle() method.
|
static void |
validateString(String propertyName,
String name,
String value)
Convenience method which validate a string null, empty after trim (length==0)
|
static void |
validateString(String propertyName,
String name,
String value,
boolean allowNull,
boolean allowEmpty)
Convenience method which validate a string null, empty after trim (length==0)
|
public static final List<String> asList(Iterator<String> it)
Iterator<String> into a sorted List
.
it
- the iteratorpublic static final StringList asStringList(Iterator<String> it)
it
- the Iterator of Stringspublic static final boolean isEmpty(String s)
s
- the stringtrue
if the string is either null
or has a length of zero after a trim, otherwise false
.public static final String asString(List<String> list)
list
- the list of stringspublic static final String asString(List<String> list, String divider)
list
- the list of stringsdivider
- the divider.public static final String asString(Iterator<String> it, String divider)
it
- the iterator of stringdivider
- the string divider.public static final String asString(String[] stringArray, String divider)
stringArray
- the array of stringsdivider
- the divider.public static final String replaceInlinedProperties(String value)
StaticPropertyFrameworkConfiguration.doReplaceInlinedProperties()
is true
.value
- the value to be preparsedStaticPropertyFrameworkConfiguration.doReplaceInlinedProperties()
is true
.PropertyFrameworkGlobals
,
replaceSystemProperties(String)
,
replaceEnvironmentProperties(String)
public static final String removeValueQuotes(String value)
PropertyFrameworkGlobals.isDisardValueQuotes()
is true
.value
- the string valuepublic static final String replaceSystemProperties(String value)
${name}
" is replace with the corresponding system properties value, if the name is a valid system properties name. StaticPropertyFrameworkConfiguration.doReplaceInlinedProperties()
is true
.value
- the value to be converted${name}
" is replaced with System.properties value, if that value is not null
.System.getProperty(String)
,
System.getProperties()
,
PropertyFrameworkGlobals
public static final String replaceEnvironmentProperties(String value)
${name}
" is replace with the corresponding env properties value, if the name is a valid env properties name. StaticPropertyFrameworkConfiguration.doReplaceInlinedProperties()
is true
.value
- the value to be converted${name}
" is replaced with System.getenv() value, if that value is not null
.System.getenv()
,
System.getenv(String)
,
PropertyFrameworkGlobals
protected static String getCaseInsensitiveSystemProperty(String key)
key
- the key to look for in System.getProperty(String)
.System.getProperty(String)
which has the "key", case insensive, otherwise returns null
.System.getProperty(String)
protected static String getCaseInsensitiveEnvironmentProperty(String key)
key
- the key to look for in System.getenv(String)
.System.getenv(String)
which has the "key", case insensive, otherwise returns null
.System.getenv(String)
public static final boolean doArrayContains(String[] array, String value, boolean ignoreCase)
array
- the String array.value
- the String value.ignoreCase
- when comparing strnig, shall case be ignored.false
if array is null
or empty, or value is null
or not in array, otherwise true
.public static final String shuffle(String s) throws NullPointerException
s
- the string which characters we want to shuffle around.NullPointerException
- if the string is null
.Collections.shuffle(List)
public static final void validateString(String propertyName, String name, String value) throws PropertyException
propertyName
- the name of propertyname
- the name of string validated.value
- the string value.PropertyException
- if vaue is either null
or zero length after trim.public static final void validateString(String propertyName, String name, String value, boolean allowNull, boolean allowEmpty) throws PropertyException
propertyName
- the name of propertyname
- the name of string validated.value
- the string value.allowNull
- is null
allowed.allowEmpty
- is empty after trim allowed.PropertyException
- if the value is null
and its not allowed, or the value is empty after trim and it is not allowed.public static String leftPad(String value, int length)
value
- the string value to padlength
- the desired length of the return string valuenull
, left pad values until length, if the string value length is greater than the desired length the value is returned, otherwise the pad value if padded on the left until the desired length is reached.public static String leftPad(String value, char pad, int length)
value
- the string value to padpad
- the char value to left pad with, if null
or empty a white space is used.length
- the desired length of the return string valuenull
, left pad values until length, if the string value length is greater than the desired length the value is returned, otherwise the pad value if padded on the left until the desired length is reached.public static String rightPad(String value, int length)
value
- the string value to padlength
- the desired length of the return string valuenull
, left pad values until length, if the string value length is greater than the desired length the value is returned, otherwise the pad value if padded on the right until the desired length is reached.public static String rightPad(String value, char pad, int length)
value
- the string value to padpad
- the char value to right pad with, if null
or empty a white space is used.length
- the desired length of the return string valuenull
, left pad values until length, if the string value length is greater than the desired length the value is returned, otherwise the pad value if padded on the right until the desired length is reached.public static String escapeHtml(String s)
s
- the stringpublic static String repeat(String s, int times)
s
- the string to repeattimes
- how many times the string should be repeated.public static String repeat(String s, String divider, int times)
s
- the string to repeatdivider
- the divider between the repeat and as last. if null
then ignored.times
- how many times the string should be repeated.public static String bite(String s, int maxLength, int maxLineLength, String lineDivider, String maxLengthExceededIndicator)
null
.s
- the stringmaxLength
- the total max length of the string.maxLineLength
- the max length of each section which should be seperate by a "lineDivider".lineDivider
- the line divider betweeen two sections of the string of "maxLineLength", if null
than not used.maxLengthExceededIndicator
- append on the end of string to indicate that more was/is present, could be "..." or "...(more)", if null
than ignored.null
then null
is returned, otherwise see method description.bite(String, int, String)
public static String bite(String s, int maxLineLength, String lineDivider)
s
- the string to divide.maxLineLength
- the max length of each line.lineDivider
- the line divider, if null
, than not used.public static String capitalize(String s)
s
- the string to capatilize.Character.isWhitespace(char)