public final class TextUtil
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
TextUtil.Alignment
Left or right alignment
|
Modifier and Type | Field and Description |
---|---|
static PropertyValue<java.lang.String> |
DEFAULT_COLLATOR_LANGUAGE
Specifies the default collator locale language.
Value type: String Default value: Locale.getDefault().getLanguage() . |
Modifier and Type | Method and Description |
---|---|
static void |
collate(java.util.List values)
Sorts the string representations of this lists contents, using
the space aware collator
|
static void |
collateSansSpaces(java.text.Collator collator,
java.util.List list)
Collates the contents of the list, replacing spaces with underscores before sorting
|
static int |
collateSansSpaces(java.text.Collator collator,
java.lang.String stringOne,
java.lang.String stringTwo)
Collates the given strings after replacing spaces with underscores
|
static java.lang.String |
createRandomString(int minLength,
int maxLength)
Creates a random string from alphanumeric uppercase characters
|
static java.lang.String |
getArrayContentsAsString(java.lang.Object[] items,
boolean onePerLine) |
static java.lang.String |
getCollectionContentsAsString(java.util.Collection collection,
boolean onePerLine) |
static java.lang.String |
getDelimitedString(java.lang.String[][] headers,
java.lang.String[][] data,
java.lang.String delimiter) |
static java.lang.Double |
getDouble(java.lang.String text)
Parses a Double from the given String.
|
static java.lang.Integer |
getInt(java.lang.String text)
Parses an Integer from the given String.
|
static java.lang.Long |
getLong(java.lang.String text)
Parses a Long from the given String.
|
static <T> java.util.Comparator<T> |
getSpaceAwareCollator() |
static <T> java.util.Comparator<T> |
getSpaceAwareCollator(java.util.Locale locale) |
static java.lang.String |
getTextFileContents(java.lang.Class resourceClass,
java.lang.String resourceName)
Fetch the entire contents of a resource text file, and return it in a String, using the default Charset.
|
static java.lang.String |
getTextFileContents(java.lang.Class resourceClass,
java.lang.String resourceName,
java.nio.charset.Charset charset)
Fetch the entire contents of a resource textfile, and return it in a String.
|
static java.lang.String |
getTextFileContents(java.io.File file,
java.nio.charset.Charset charset)
Fetch the entire contents of a textfile, and return it in a String
|
static java.lang.String |
getTextFileContents(java.io.InputStream inputStream,
java.nio.charset.Charset charset)
Fetch the entire contents of an InputStream, and return it in a String.
|
static java.lang.String |
getTextFileContents(java.lang.String filename,
java.nio.charset.Charset charset)
Fetch the entire contents of a textfile, and return it in a String
|
static java.lang.String |
padString(java.lang.String string,
int length,
char padChar,
TextUtil.Alignment alignment)
Pads the given string with the given pad character until a length of
length has been reached |
static java.util.List<java.lang.String> |
parseCommaSeparatedValues(java.lang.String commaSeparatedValues) |
public static final PropertyValue<java.lang.String> DEFAULT_COLLATOR_LANGUAGE
Locale.getDefault().getLanguage()
.getSpaceAwareCollator()
,
collate(List)
,
Locale.toLanguageTag()
public static java.lang.Integer getInt(java.lang.String text)
text
- the text to parsepublic static java.lang.Double getDouble(java.lang.String text)
text
- the text to parsepublic static java.lang.Long getLong(java.lang.String text)
text
- the text to parsepublic static java.lang.String createRandomString(int minLength, int maxLength)
minLength
- the minimum lengthmaxLength
- the maximum lengthpublic static void collate(java.util.List values)
values
- the list to sort (collate)getSpaceAwareCollator()
public static <T> java.util.Comparator<T> getSpaceAwareCollator()
T
- the comparison typeDEFAULT_COLLATOR_LANGUAGE
public static <T> java.util.Comparator<T> getSpaceAwareCollator(java.util.Locale locale)
T
- the comparison typelocale
- the collator localepublic static void collateSansSpaces(java.text.Collator collator, java.util.List list)
collator
- the collatorlist
- the listpublic static int collateSansSpaces(java.text.Collator collator, java.lang.String stringOne, java.lang.String stringTwo)
collator
- the collator to usestringOne
- the first stringstringTwo
- the second stringpublic static java.lang.String padString(java.lang.String string, int length, char padChar, TextUtil.Alignment alignment)
length
has been reachedstring
- the string to padlength
- the desired lengthpadChar
- the character to use for paddingalignment
- the padding alignment, left or right sidepublic static java.lang.String getDelimitedString(java.lang.String[][] headers, java.lang.String[][] data, java.lang.String delimiter)
headers
- the headersdata
- the datadelimiter
- the delimiterpublic static java.lang.String getTextFileContents(java.lang.Class resourceClass, java.lang.String resourceName) throws java.io.IOException
resourceClass
- the resource classresourceName
- the name of the resource to retrievejava.io.IOException
- in case an IOException occurspublic static java.lang.String getTextFileContents(java.lang.Class resourceClass, java.lang.String resourceName, java.nio.charset.Charset charset) throws java.io.IOException
resourceClass
- the resource classresourceName
- the name of the resource to retrievecharset
- the Charset to use when reading the file contentsjava.io.IOException
- in case an IOException occurspublic static java.lang.String getTextFileContents(java.lang.String filename, java.nio.charset.Charset charset) throws java.io.IOException
filename
- the name of the filecharset
- the charset to usejava.io.IOException
- in case of an exceptionpublic static java.lang.String getTextFileContents(java.io.File file, java.nio.charset.Charset charset) throws java.io.IOException
file
- the filecharset
- the charset to usejava.io.IOException
- in case of an exceptionpublic static java.lang.String getTextFileContents(java.io.InputStream inputStream, java.nio.charset.Charset charset) throws java.io.IOException
inputStream
- the input stream to readcharset
- the charset to usejava.io.IOException
- in case of an exceptionpublic static java.lang.String getCollectionContentsAsString(java.util.Collection collection, boolean onePerLine)
collection
- the collectiononePerLine
- if true then each item is put on a separate line, otherwise a comma separator is usedpublic static java.lang.String getArrayContentsAsString(java.lang.Object[] items, boolean onePerLine)
items
- the itemsonePerLine
- if true then each item is put on a separate line, otherwise a comma separator is usedpublic static java.util.List<java.lang.String> parseCommaSeparatedValues(java.lang.String commaSeparatedValues)
commaSeparatedValues
- a String with comma separated values