public final class TextUtils extends Object
| Modifier and Type | Method and Description |
|---|---|
static <T> String |
arrayToString(String separator,
Function<T,String> textProvider,
Filter<T> filter,
T... array)
Returns single text combined from array of elements using specified separator.
|
static <T> String |
arrayToString(String separator,
Function<T,String> textProvider,
T... array)
Returns single text combined from array of elements using specified separator.
|
static <T> String |
arrayToString(String separator,
T... array)
Returns single text combined from array of elements using specified separator.
|
static <T> String |
arrayToString(T... array)
Returns single text combined from array of elements using default separator.
|
static <T> String |
collectionToString(Collection<T> collection)
Returns single text combined from
Collection of elements using default separator. |
static <T> String |
collectionToString(Collection<T> collection,
String separator)
Returns single text combined from
Collection of elements using specified separator. |
static <T> String |
collectionToString(Collection<T> collection,
String separator,
Function<T,String> textProvider)
Returns single text combined from
Collection of elements using specified separator. |
static <T> String |
collectionToString(Collection<T> collection,
String separator,
Function<T,String> textProvider,
Filter<T> filter)
Returns single text combined from
Collection of elements using specified separator. |
static String |
createString(char character,
int length)
Creates new string filled with specified amount of same characters.
|
static String |
createString(String character,
int length)
Creates new string filled with specified amount of same characters.
|
static <E extends Enum<E>> |
enumArrayToString(E... enumArray)
Converts array of enumeration constants into string with list of enumeration constants and returns it.
|
static <E extends Enum<E>> |
enumArrayToString(String separator,
E... enumArray)
Converts array of enumeration constants into string with list of enumeration constants and returns it.
|
static <E extends Enum<E>> |
enumListToString(List<E> enumList)
Converts list of enumeration constants into string with list of enumeration constants and returns it.
|
static <E extends Enum<E>> |
enumListToString(List<E> enumList,
String separator)
Converts list of enumeration constants into string with list of enumeration constants and returns it.
|
static <E extends Enum<E>> |
enumStringToList(String enumString,
Class<E> enumClass)
Converts string with list of enumeration constants into real list of enumeration constants and returns it.
|
static <E extends Enum<E>> |
enumStringToList(String enumString,
Class<E> enumClass,
String separator)
Converts string with list of enumeration constants into real list of enumeration constants and returns it.
|
static boolean |
equals(String string,
String compareWith)
Returns whether the first
String equals to second one. |
static boolean |
equalsIgnoreCase(String string,
String compareWith)
Returns whether the first
String equals to second one ignoring case. |
static Integer |
findFirstNumber(String text)
Returns first number found in text.
|
static int |
findFirstRowWordEndIndex(String string)
Returns last index of the first word end.
|
static int |
findFirstWordFromIndex(String string,
int from)
Returns begin index of first word after specified index.
|
static int |
findLastRowWordStartIndex(String string)
Returns begin index of last word in the specified text.
|
static String |
format(String text,
Object... objects)
Returns message formatted with common string representations of the provided objects.
|
static String |
generateId()
Returns random ID with default prefix and suffix.
|
static String |
generateId(int length)
Returns randomly generated ID part with specified length.
|
static String |
generateId(String prefix)
Returns random ID with specified prefix and default suffix.
|
static String |
generateId(String prefix,
String suffix)
Returns random ID with specified prefix and suffix.
|
static String |
getSettingsKey(Object... settings)
Returns settings combined into a single key.
|
static String |
getSystemLineSeparator()
Returns preferred system text lines separator.
|
static String |
getWord(String text,
int location)
Returns a word from text at the specified location.
|
static int |
getWordEnd(String text,
int location)
Returns a word end index at the specified location.
|
static int |
getWordStart(String text,
int location)
Returns index of the first character in the word at the specified location.
|
static boolean |
isBlank(String text)
Returns whether or not specified text is
null or empty excluding linebreaks and whitespaces. |
static boolean |
isEmpty(String text)
Returns whether or not specified text is
null or empty. |
static int |
length(String text)
Returns specified text length.
|
static <T> String |
listToString(List<T> list)
Returns single text combined from list of elements using default separator.
|
static <T> String |
listToString(List<T> list,
String separator)
Returns single text combined from list of elements using specified separator.
|
static <T> String |
listToString(List<T> list,
String separator,
Function<T,String> textProvider)
Returns single text combined from list of elements using specified separator.
|
static <T> String |
listToString(List<T> list,
String separator,
Function<T,String> textProvider,
Filter<T> filter)
Returns single text combined from list of elements using specified separator.
|
static boolean |
notBlank(String text)
Returns whether or not specified text is
null or empty excluding linebreaks and whitespaces. |
static boolean |
notEmpty(String text)
Returns whether or not specified text is
null or empty. |
static List<String> |
numbered(String pattern,
int from,
int to)
Returns list of strings based on single pattern parsed using different number values in range.
|
static Point |
parsePoint(String text)
Returns point extracted from text.
|
static Point |
parsePoint(String text,
String separator)
Returns point extracted from text.
|
static String |
removeFirstLines(String text,
int count)
Returns text with first lines removed.
|
static String |
removeLineBreaks(String text)
Returns text with all line breaks removed.
|
static String |
removeSpacings(String text)
Returns text with all spacings removed.
|
static String |
replace(String text,
int index,
char character)
Returns text with replaced character at the specified index.
|
static String |
replaceAll(String text,
boolean ignoreCase,
String str,
Function<String,String> replacer)
Replaces all occurrences of str found in the specified text with provided text.
|
static String |
requireNonEmpty(String text)
Checks that the specified text is not
null or empty and throws a NullPointerException if it is. |
static String |
requireNonEmpty(String text,
String message)
Checks that the specified text is not
null or empty and throws a NullPointerException if it is. |
static String |
requireNonEmpty(String text,
Supplier<RuntimeException> exceptionSupplier)
Checks that the specified text is not
null or empty and throws a RuntimeException if it is. |
static String |
shortenText(String text,
int maxLength,
boolean addDots)
Returns shortened text.
|
static String |
shortenTextEnd(String text,
int maxLength,
boolean addDots)
Returns shortened text.
|
static List<Float> |
stringToFloatList(String string)
Returns a list of float parts split using specified separator.
|
static List<Float> |
stringToFloatList(String string,
String separator)
Returns a list of float parts split using specified separator.
|
static List<Integer> |
stringToIntList(String string)
Returns a list of integer parts split using specified separator.
|
static List<Integer> |
stringToIntList(String string,
String separator)
Returns a list of integer parts split using specified separator.
|
static List<String> |
stringToList(String string)
Returns a list of text parts split using specified separator.
|
static List<String> |
stringToList(String string,
String separator)
Returns a list of text parts split using specified separator.
|
static String |
unite(String separator,
String... parts)
Converts and returns specified parts which are not null into single string.
|
@NotNull public static String getSystemLineSeparator()
@NotNull public static String format(@NotNull String text, @Nullable Object... objects)
text - message to formatobjects - objects to use for message formatting@NotNull public static String replace(@NotNull String text, int index, char character)
text - text to replace character inindex - index of the character to replacecharacter - replacement characterpublic static boolean equalsIgnoreCase(@Nullable String string, @Nullable String compareWith)
@NotNull public static List<String> numbered(@NotNull String pattern, int from, int to)
pattern - values patternfrom - range startto - range end@NotNull public static String removeLineBreaks(@NotNull String text)
text - text to remove line breaks from@NotNull public static String removeSpacings(@NotNull String text)
text - text to remove spacings from@NotNull public static Integer findFirstNumber(@NotNull String text)
text - text to search through@Nullable public static String getWord(@NotNull String text, int location)
text - text to retrieve the word fromlocation - word locationpublic static int getWordStart(@NotNull String text, int location)
text - text to retrieve the word start index fromlocation - word locationpublic static int getWordEnd(@NotNull String text, int location)
text - text to retrieve the word end index fromlocation - word locationpublic static int findLastRowWordStartIndex(@NotNull String string)
string - text to processpublic static int findFirstWordFromIndex(@NotNull String string, int from)
string - text to processfrom - index to start search frompublic static int findFirstRowWordEndIndex(@NotNull String string)
string - text to process@NotNull public static String removeFirstLines(@NotNull String text, int count)
text - text to cropcount - lines count to crop@Nullable public static Point parsePoint(@NotNull String text)
text - text to extract point from@Nullable public static Point parsePoint(@NotNull String text, @NotNull String separator)
text - text to extract point fromseparator - point values separator@NotNull public static String shortenText(@NotNull String text, int maxLength, boolean addDots)
text - text to shortenmaxLength - maximum shortened text lengthaddDots - add dots at the end of the text when shortened@NotNull public static String shortenTextEnd(@NotNull String text, int maxLength, boolean addDots)
text - text to shortenmaxLength - maximum shortened text lengthaddDots - add dots at the end of the text when shortened@NotNull public static List<String> stringToList(@Nullable String string)
string - text to split@NotNull public static List<String> stringToList(@Nullable String string, @NotNull String separator)
string - text to splitseparator - text parts separator@NotNull public static List<Integer> stringToIntList(@Nullable String string)
string - text to split@NotNull public static List<Integer> stringToIntList(@Nullable String string, @NotNull String separator)
string - text to splitseparator - text parts separator@NotNull public static List<Float> stringToFloatList(@Nullable String string)
string - text to split@NotNull public static List<Float> stringToFloatList(@Nullable String string, @NotNull String separator)
string - text to splitseparator - text parts separator@Nullable public static <T> String listToString(@Nullable List<T> list)
T - elements typelist - list to combine into single text@Nullable public static <T> String listToString(@Nullable List<T> list, @NotNull String separator)
T - elements typelist - list to combine into single textseparator - elements separator@Nullable public static <T> String listToString(@Nullable List<T> list, @NotNull String separator, @NotNull Function<T,String> textProvider)
T - elements typelist - list to combine into single textseparator - elements separatortextProvider - Function providing text@Nullable public static <T> String listToString(@Nullable List<T> list, @NotNull String separator, @NotNull Function<T,String> textProvider, @Nullable Filter<T> filter)
@Nullable public static <T> String collectionToString(@Nullable Collection<T> collection)
Collection of elements using default separator.T - elements typecollection - Collection to combine into single textCollection of elements using default separator@Nullable public static <T> String collectionToString(@Nullable Collection<T> collection, @NotNull String separator)
Collection of elements using specified separator.T - elements typecollection - Collection to combine into single textseparator - elements separatorCollection of elements using specified separator@Nullable public static <T> String collectionToString(@Nullable Collection<T> collection, @NotNull String separator, @NotNull Function<T,String> textProvider)
Collection of elements using specified separator.T - elements typecollection - Collection to combine into single textseparator - elements separatortextProvider - Function providing textCollection of elements using specified separator@Nullable public static <T> String collectionToString(@Nullable Collection<T> collection, @NotNull String separator, @NotNull Function<T,String> textProvider, @Nullable Filter<T> filter)
Collection of elements using specified separator.T - elements typecollection - Collection to combine into single textseparator - elements separatortextProvider - Function providing textfilter - Filter for elementsCollection of elements using specified separator@Nullable public static <T> String arrayToString(@Nullable T... array)
T - elements typearray - array to combine into single text@Nullable public static <T> String arrayToString(@NotNull String separator, @Nullable T... array)
T - elements typeseparator - elements separatorarray - array to combine into single text@Nullable public static <T> String arrayToString(@NotNull String separator, @NotNull Function<T,String> textProvider, @Nullable T... array)
T - elements typeseparator - elements separatortextProvider - Function providing textarray - array to combine into single text@Nullable public static <T> String arrayToString(@NotNull String separator, @NotNull Function<T,String> textProvider, @Nullable Filter<T> filter, @Nullable T... array)
@Nullable public static <E extends Enum<E>> String enumArrayToString(@Nullable E... enumArray)
E - enumeration typeenumArray - enumeration constants array@Nullable public static <E extends Enum<E>> String enumArrayToString(@NotNull String separator, @Nullable E... enumArray)
E - enumeration typeseparator - text parts separatorenumArray - enumeration constants array@Nullable public static <E extends Enum<E>> String enumListToString(@Nullable List<E> enumList)
E - enumeration typeenumList - enumeration constants list@Nullable public static <E extends Enum<E>> String enumListToString(@Nullable List<E> enumList, @NotNull String separator)
E - enumeration typeenumList - enumeration constants listseparator - text parts separator@NotNull public static <E extends Enum<E>> List<E> enumStringToList(@Nullable String enumString, @NotNull Class<E> enumClass)
E - enumeration typeenumString - enumeration constants string listenumClass - enumeration class@NotNull public static <E extends Enum<E>> List<E> enumStringToList(@Nullable String enumString, @NotNull Class<E> enumClass, @NotNull String separator)
E - enumeration typeenumString - enumeration constants string listenumClass - enumeration classseparator - text parts separator@NotNull public static String unite(@NotNull String separator, @Nullable String... parts)
separator - separator to place between partsparts - parts to unitepublic static int length(@Nullable String text)
text - text to checkpublic static boolean isEmpty(@Nullable String text)
null or empty.text - text to checktrue if specified text is null or empty, false otherwisepublic static boolean notEmpty(@Nullable String text)
null or empty.text - text to checktrue if specified text is not null or empty, false otherwisepublic static boolean isBlank(@Nullable String text)
null or empty excluding linebreaks and whitespaces.text - text to checktrue if specified text is null or empty excluding linebreaks and whitespaces, false otherwisepublic static boolean notBlank(@Nullable String text)
null or empty excluding linebreaks and whitespaces.text - text to checktrue if specified text is not null or empty excluding linebreaks and whitespaces, false otherwise@NotNull public static String requireNonEmpty(@Nullable String text)
null or empty and throws a NullPointerException if it is.text - text to check for being null or emptynull or emptyNullPointerException - if text is null or empty@NotNull public static String requireNonEmpty(@Nullable String text, @NotNull String message)
null or empty and throws a NullPointerException if it is.text - text to check for being null or emptymessage - detailed message used in NullPointerExceptionnull or emptyNullPointerException - if text is null or empty@NotNull public static String requireNonEmpty(@Nullable String text, @NotNull Supplier<RuntimeException> exceptionSupplier)
null or empty and throws a RuntimeException if it is.text - text to check for being null or emptyexceptionSupplier - Supplier for a customized RuntimeExceptionnull or emptyRuntimeException - if text is null or empty@NotNull public static String createString(@NotNull String character, int length)
character - character to fill string withlength - string length@NotNull public static String createString(char character, int length)
character - character to fill string withlength - string length@NotNull public static String replaceAll(@NotNull String text, boolean ignoreCase, @NotNull String str, @NotNull Function<String,String> replacer)
text - text to replace string occurrences inignoreCase - whether should ignore case while searching for occurrences or notstr - text to replacereplacer - text replacement Function@NotNull public static String generateId()
@NotNull public static String generateId(@Nullable String prefix)
prefix - id prefix@NotNull public static String generateId(@Nullable String prefix, @Nullable String suffix)
prefix - id prefixsuffix - id suffix@NotNull public static String generateId(int length)
length - part length in symbolsCopyright © 2020. All rights reserved.