public final class StringHelper extends Object
Modifier and Type | Method and Description |
---|---|
static String |
cleanString(String string)
Cleans a string, removes whitespaces on start and end, and removes multiple whitespaces.
|
static List<String> |
cleanStringList(List<String> list)
Cleans a List of Strings, handle null parameter
|
static String |
cleanUpString(String str,
String cleanUpChar,
String replaceChar)
Remove the cleanUpChar from the given string by stripping it from the start and end.
|
static Long |
getStringAsLong(String value,
Long fallback)
Converts a string containing a decimal number into a long.
|
static Long[] |
getStringAsLongArray(String value)
Gets the string as long array.
|
static Long[] |
getStringAsLongArray(String[] values) |
static List<Long> |
getStringAsLongList(String value)
Convert a string of longs which are separated by commas into a list of Long objects.
|
static List<Long> |
getStringAsLongList(String[] values) |
static List<Long> |
getStringAsLongList(String value,
boolean ignoreValuesEqualLessZero)
Convert a string of longs which are separated by commas into a list of Long objects.
|
static List<Long> |
getStringAsLongList(String value,
String separator)
Convert a string of longs which are separated by a given string into a list of Long objects.
|
static List<Long> |
getStringAsLongList(String value,
String separator,
boolean ignoreValuesEqualLessZero)
Convert a string of longs which are separated by a given string into a list of Long objects.
|
static Map<String,String> |
getStringAsMap(String mapping)
Converts a string of the form 'k1=v1,k2=v2,k3=v3' into a map with k's as key and the v's as
the associated values.
|
static String |
replaceCharacter(String source,
char charToReplace,
String replacement)
Replaces all occurrences of a character with the replacement.
|
static String |
toString(Collection<?> coll)
Build a string containing toString for each sub element.
|
static String |
toString(Map<String,String> mapping)
Converts the map into a string of the form 'k1=v1,k2=v2,k3=v3'.
|
static String |
toString(Object[] array,
String separator)
Build a string of the array in the form "o1, o2, o3" if separator is ", "
|
static String |
truncateMiddle(String string,
int maxLength,
String ellipses)
To cut out middle part of a String.
|
public static String cleanString(String string)
string
- the stringpublic static List<String> cleanStringList(List<String> list)
list
- the listpublic static String cleanUpString(String str, String cleanUpChar, String replaceChar)
str
- the string to cleanupcleanUpChar
- the string to replacereplaceChar
- the string to replace withpublic static Long getStringAsLong(String value, Long fallback)
value
- the value to convertfallback
- the fallback to return if conversion failedpublic static Long[] getStringAsLongArray(String value)
value
- the valuepublic static Long[] getStringAsLongArray(String[] values)
values
- The values to parse.public static List<Long> getStringAsLongList(String value)
value
- the value to processpublic static List<Long> getStringAsLongList(String value, boolean ignoreValuesEqualLessZero)
value
- the value to processignoreValuesEqualLessZero
- if true, parsed long values <= 0 will not be added to the returning listpublic static List<Long> getStringAsLongList(String value, String separator)
value
- the value to processseparator
- the separatorpublic static List<Long> getStringAsLongList(String value, String separator, boolean ignoreValuesEqualLessZero)
value
- the value to processseparator
- the separatorignoreValuesEqualLessZero
- if true, parsed long values <= 0 will not be added to the returning listpublic static List<Long> getStringAsLongList(String[] values)
values
- The values to parse.public static Map<String,String> getStringAsMap(String mapping)
mapping
- the string based mapping to convertpublic static String replaceCharacter(String source, char charToReplace, String replacement)
source
- the source to processcharToReplace
- the character to replacereplacement
- the replacement for the characterpublic static String toString(Collection<?> coll)
coll
- The collection to usepublic static String toString(Map<String,String> mapping)
getStringAsMap(String)
.mapping
- the map to convertpublic static String toString(Object[] array, String separator)
array
- an array of objects which should be "stringed"separator
- the separator to usepublic static String truncateMiddle(String string, int maxLength, String ellipses)
string
- the string to truncatemaxLength
- the max length of a stringellipses
- the replacement in case of cutting the stringCopyright © 2019 Communote team. All rights reserved.