Package ai.libs.jaicore.basic
Class StringUtil
- java.lang.Object
-
- ai.libs.jaicore.basic.StringUtil
-
public class StringUtil extends java.lang.Object
This class provides handy utility functions when dealing with Strings.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.String[]
explode(java.lang.String string, java.lang.String delimiter)
Splits a string using delimiter as a separator of elements into an array.static java.lang.String
firstElementWithPrefix(java.util.Collection<java.lang.String> collection, java.lang.String prefix)
Finds the first String starting with the given prefix in a collection of Strings.static java.lang.String
fromBinary(java.lang.String binarySequence)
Translates a binary representation of a string to the respective string.static java.lang.String[]
getArrayWithValues(int size, java.lang.String value)
static char[]
getCommonChars(boolean includeDigits)
Getter for all available common characters of the system.static java.lang.String
getRandomString(int length, char[] chars, long seed)
Returns a random string of a desired length and from a given set of characters.static java.lang.String
implode(java.lang.Object[] array)
Concatenates the string representations of an array of objects using ", " as a separator.static java.lang.String
implode(java.lang.Object[] array, java.lang.String delimiter)
Concatenates the string representations of an array of objects using the specified delimiter as a separator.static java.lang.String
implode(java.util.Collection<?> set, java.lang.String delimiter)
Concatenates the string representations of a set of objects using the specified delimiter as a separator.static java.lang.String
implode(java.util.Collection<java.lang.Object> collection)
Concatenates the string representations of a collection of objects using ", " as a separator.static java.lang.String
implode(java.util.Set<java.lang.Object> set)
Concatenates the string representations of a set of objects using ", " as a separator.static java.lang.String[]
merge(java.lang.String[] array1, java.lang.String[] array2)
Merges two string arrays into one single array.static java.lang.String[]
shiftFirst(java.lang.String[] input)
Removes the first entry of the value and returns an array containing all values but the first one.static java.lang.String
stripChar(java.lang.String str, char c)
Strips a specific character from a string.static java.lang.String
toStringLimited(java.lang.Object o, int limit)
Limits the toString output of an object to a specified length.
-
-
-
Method Detail
-
getCommonChars
public static char[] getCommonChars(boolean includeDigits)
Getter for all available common characters of the system. Digits can be included if desired.- Parameters:
includeDigits
- Flag whether to include digits in the array of the system's common characters.- Returns:
- An array of the system's common characters.
-
getRandomString
public static java.lang.String getRandomString(int length, char[] chars, long seed)
Returns a random string of a desired length and from a given set of characters.- Parameters:
length
- The length of the resulting random string.chars
- The set of characters to be used to generate a random string.- Returns:
- The generated random string.
-
implode
public static java.lang.String implode(java.lang.Object[] array)
Concatenates the string representations of an array of objects using ", " as a separator.- Parameters:
array
- The array of objects of which the string representation is to be concatenated.- Returns:
- The concatenated string of the given objects' string representation.
-
implode
public static java.lang.String implode(java.util.Set<java.lang.Object> set)
Concatenates the string representations of a set of objects using ", " as a separator.- Parameters:
set
- The set of objects of which the string representation is to be concatenated.- Returns:
- The concatenated string of the given objects' string representation.
-
implode
public static java.lang.String implode(java.util.Collection<?> set, java.lang.String delimiter)
Concatenates the string representations of a set of objects using the specified delimiter as a separator.- Parameters:
set
- The set of objects of which the string representation is to be concatenated.delimter
- A string separating the respective string representations.- Returns:
- The concatenated string of the given objects' string representation.
-
implode
public static java.lang.String implode(java.util.Collection<java.lang.Object> collection)
Concatenates the string representations of a collection of objects using ", " as a separator.- Parameters:
collection
- The set of objects of which the string representation is to be concatenated.- Returns:
- The concatenated string of the given objects' string representation.
-
implode
public static java.lang.String implode(java.lang.Object[] array, java.lang.String delimiter)
Concatenates the string representations of an array of objects using the specified delimiter as a separator.- Parameters:
array
- The array of objects of which the string representation is to be concatenated.delimter
- A string separating the respective string representations.- Returns:
- The concatenated string of the given objects' string representation.
-
explode
public static java.lang.String[] explode(java.lang.String string, java.lang.String delimiter)
Splits a string using delimiter as a separator of elements into an array.- Parameters:
string
- The string to be split.delimiter
- A string separating the sub-strings.- Returns:
- An array of sub-string which were formerly separeted by the specified delimiter.
-
merge
public static java.lang.String[] merge(java.lang.String[] array1, java.lang.String[] array2)
Merges two string arrays into one single array. Note: This is a duplicate for apache-commons-lang: ArrayUtils.addAll(array1, array2);- Parameters:
array1
- The first array.array2
- The second array.- Returns:
- Concatenated array of Strings.
-
getArrayWithValues
public static java.lang.String[] getArrayWithValues(int size, java.lang.String value)
-
stripChar
public static java.lang.String stripChar(java.lang.String str, char c)
Strips a specific character from a string.- Parameters:
str
- The string from which the character shall be stripped.c
- The character to strip.- Returns:
- The stripped string where the specified character does not occur any longer.
-
shiftFirst
public static java.lang.String[] shiftFirst(java.lang.String[] input)
Removes the first entry of the value and returns an array containing all values but the first one.- Parameters:
input
- The array of values to be shifted.- Returns:
- The resulting shifted array.
-
fromBinary
public static java.lang.String fromBinary(java.lang.String binarySequence)
Translates a binary representation of a string to the respective string.- Parameters:
binarySequence
- The binary encoding of the string.- Returns:
- The translated string.
-
toStringLimited
public static java.lang.String toStringLimited(java.lang.Object o, int limit)
Limits the toString output of an object to a specified length.- Parameters:
o
- The object for which a string limited string representation is to be obtained.limit
- The maximum length of the toString output.- Returns:
- The resulting (potentially cut) string.
-
firstElementWithPrefix
public static java.lang.String firstElementWithPrefix(java.util.Collection<java.lang.String> collection, java.lang.String prefix)
Finds the first String starting with the given prefix in a collection of Strings.- Parameters:
collection
- The collection of Strings to search in.prefix
- The prefix of the searched-for element.- Returns:
- The first element of the collection starting with the desired prefix.
-
-