java.lang.Object
is.codion.common.Text
A utility class for working with text, such as sorting and reading from files
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final PropertyValue<String>Specifies the default collator locale language.
Value type: String
Default value:Locale.getDefault().getLanguage().static final PropertyValue<Character>Specifies the wildcard character used
Value type: Character
Default value: % -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> List<T>Sorts the string representations of the list contents, using the space aware collatorstatic <T> Comparator<T>collator()Creates a Comparator which compares the string representations of the objects using the default Collator, taking spaces into account.static <T> Comparator<T>Creates a Comparator which compares the string representations of the objects using the default Collator, taking spaces into account.static StringCreates a delimited string from the given input lists.static StringLeft pads the given string with the given pad character until a length oflengthhas been reachedparseCommaSeparatedValues(String commaSeparatedValues) Parses, splits and trims the given comma separated string.static StringrandomString(int minimumLength, int maximumLength) Creates a random string from alphanumeric uppercase charactersstatic StringRight pads the given string with the given pad character until a length oflengthhas been reachedstatic StringtextFileContents(File file, Charset charset) Fetch the entire contents of a textfile, and return it in a Stringstatic StringtextFileContents(InputStream inputStream, Charset charset) Fetch the entire contents of an InputStream, and return it in a String.static <T> StringtextFileContents(Class<T> resourceClass, String resourceName) Fetch the entire contents of a resource text file, and return it in a String, using the default Charset.static <T> StringtextFileContents(Class<T> resourceClass, String resourceName, Charset charset) Fetch the entire contents of a resource textfile, and return it in a String.static StringtextFileContents(String filename, Charset charset) Fetch the entire contents of a textfile, and return it in a Stringstatic StringunderscoreToCamelCase(String text) Converts a string with underscores into a camelCaseString.
-
Field Details
-
DEFAULT_COLLATOR_LANGUAGE
Specifies the default collator locale language.
Value type: String
Default value:Locale.getDefault().getLanguage().- See Also:
-
WILDCARD_CHARACTER
Specifies the wildcard character used
Value type: Character
Default value: %
-
-
Method Details
-
randomString
Creates a random string from alphanumeric uppercase characters- Parameters:
minimumLength- the minimum lengthmaximumLength- the maximum length- Returns:
- a random string
-
collate
Sorts the string representations of the list contents, using the space aware collator- Type Parameters:
T- the list element type- Parameters:
values- the list to sort (collate)- Returns:
- the sorted list
- See Also:
-
collator
Creates a Comparator which compares the string representations of the objects using the default Collator, taking spaces into account.- Type Parameters:
T- the type of the objects to compare- Returns:
- a space aware collator
- See Also:
-
collator
Creates a Comparator which compares the string representations of the objects using the default Collator, taking spaces into account.- Type Parameters:
T- the type of the objects to compare- Parameters:
locale- the collator locale- Returns:
- a space aware collator
- See Also:
-
rightPad
Right pads the given string with the given pad character until a length oflengthhas been reached- Parameters:
string- the string to padlength- the desired lengthpadChar- the character to use for padding- Returns:
- the padded string
-
leftPad
Left pads the given string with the given pad character until a length oflengthhas been reached- Parameters:
string- the string to padlength- the desired lengthpadChar- the character to use for padding- Returns:
- the padded string
-
delimitedString
public static String delimitedString(List<String> header, List<List<String>> lines, String columnDelimiter) Creates a delimited string from the given input lists.- Parameters:
header- the headerlines- the linescolumnDelimiter- the column delimiter- Returns:
- a String comprised of the given header and lines using the given column delimiter
-
textFileContents
public static <T> String textFileContents(Class<T> resourceClass, String resourceName) throws IOException Fetch the entire contents of a resource text file, and return it in a String, using the default Charset.- Type Parameters:
T- the resource class type- Parameters:
resourceClass- the resource classresourceName- the name of the resource to retrieve- Returns:
- the contents of the resource file
- Throws:
IOException- in case an IOException occurs
-
textFileContents
public static <T> String textFileContents(Class<T> resourceClass, String resourceName, Charset charset) throws IOException Fetch the entire contents of a resource textfile, and return it in a String.- Type Parameters:
T- the resource class type- Parameters:
resourceClass- the resource classresourceName- the name of the resource to retrievecharset- the Charset to use when reading the file contents- Returns:
- the contents of the resource file
- Throws:
IOException- in case an IOException occurs
-
textFileContents
Fetch the entire contents of a textfile, and return it in a String- Parameters:
filename- the name of the filecharset- the charset to use- Returns:
- the file contents as a String
- Throws:
IOException- in case of an exception
-
textFileContents
Fetch the entire contents of a textfile, and return it in a String- Parameters:
file- the filecharset- the charset to use- Returns:
- the file contents as a String
- Throws:
IOException- in case of an exception
-
textFileContents
Fetch the entire contents of an InputStream, and return it in a String. Does not close the stream.- Parameters:
inputStream- the input stream to readcharset- the charset to use- Returns:
- the stream contents as a String
- Throws:
IOException- in case of an exception
-
parseCommaSeparatedValues
Parses, splits and trims the given comma separated string. Returns an empty list in case of null or empty string argument.- Parameters:
commaSeparatedValues- a String with comma separated values- Returns:
- the trimmed values
-
underscoreToCamelCase
Converts a string with underscores into a camelCaseString. Just don't use this, it's far from bulletproof.- Parameters:
text- the text- Returns:
- a camelCase version of the given text
-