java.lang.Object
is.codion.common.utilities.Text
A utility class for working with text, such as collating and padding.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final PropertyValue<String> Specifies the default collator locale, as an IETF BCP 47 language tag -is,zh-TW,pt-BR. -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> List<T> Sorts the given list in place, comparing the string representations of the list contents using the space aware collator.static <T> Comparator<T> collator()Returns a Comparator which compares the string representations of the objects using the Collator for theCOLLATOR_LOCALElocale, taking spaces into account.static <T> Comparator<T> Creates a Comparator which compares the string representations of the objects using the Collator for the given locale, taking spaces into account.static StringLeft pads the given string with the given pad character until a length oflengthhas been reachedstatic booleannullOrEmpty(@Nullable String string) Returns true if the given string is null or empty.static booleannullOrEmpty(@Nullable String... strings) Returns true if any of the given strings is null or empty.Splits and trims the given comma separated string.static StringRight pads the given string with the given pad character until a length oflengthhas been reached
-
Field Details
-
COLLATOR_LOCALE
Specifies the default collator locale, as an IETF BCP 47 language tag -is,zh-TW,pt-BR. A bare language is a valid tag, so the values this accepted when it took only a language still do.Note that the default is resolved when this class is loaded, so an application setting
Locale.setDefault(Locale)must do so before anything touchesText.- Value type: String
- Default value:
Locale.getDefault().toLanguageTag().
- See Also:
-
-
Method Details
-
collate
Sorts the given list in place, comparing 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 given list, sorted in place
- See Also:
-
collator
Returns a Comparator which compares the string representations of the objects using the Collator for theCOLLATOR_LOCALElocale, taking spaces into account.Note that the locale is captured on first use; changing
COLLATOR_LOCALEafterwards has no effect. Usecollator(Locale)for a collator in a locale of your choosing.- 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 Collator for the given locale, taking spaces into account.- Type Parameters:
T- the type of the objects to compare- Parameters:
locale- the collator locale- Returns:
- a space aware collator
-
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
-
parseCSV
Splits and trims the given comma separated string. Returns an empty list in case of null or empty string argument. Empty segments are dropped, so"a,,b"yields[a, b].- Parameters:
csv- a String with comma separated values- Returns:
- the trimmed values
-
nullOrEmpty
Returns true if the given string is null or empty.- Parameters:
string- the string to check- Returns:
- true if the given string is null or empty, false otherwise
-
nullOrEmpty
Returns true if any of the given strings is null or empty.- Parameters:
strings- the strings to check- Returns:
- true if one of the given strings is null or empty or if no arguments are provided, false otherwise
-