public final class StringUtil extends Object
| Modifier and Type | Method and Description |
|---|---|
static boolean |
isNotNullOrEmpty(String data)
Determines if the given
String is not null or empty. |
static boolean |
isNotNullOrEmptyAfterTrim(String data)
Determines if the given
String is not null or empty even after bring trimmed. |
static boolean |
isNullOrEmpty(String data)
Determines if the given
String is null or empty. |
static boolean |
isNullOrEmptyAfterTrim(String data)
Determines if the given
String is null or empty even after bring trimmed. |
static String |
replaceLast(String source,
char toReplace,
char toUse)
Replaces the last occurrence of a character in the given source.
|
static String |
replaceLast(String source,
String toReplace,
String toUse)
Replaces the last occurrence of a character in the given source.
|
static <E extends Exception> |
splitByDelimiters(String data,
Collection<Character> delimiters,
ThrowableBiConsumer<Character,String,E> splitConsumer)
Parse the given data and split the string at every position that is a one of the provided delimiters.
|
static <E extends Exception> |
splitByDelimiters(String data,
Collection<Character> delimiters,
ThrowablePredicate<String,E> consumePredicate)
|
static String |
stripStringIndicators(String data)
Strips the " characters at the start and end of the given string if present.
|
public static String replaceLast(String source, char toReplace, char toUse)
source - source which contains the data to be usedtoReplace - the character that is to be replacedtoUse - the character that is used insteadString where last occurrence of the given character is replaced by the provided character or the original string if its null or does not contain the characterpublic static String replaceLast(String source, String toReplace, String toUse)
source - source which contains the data to be usedtoReplace - the character that is to be replacedtoUse - the character that is used insteadString where last occurrence of the given character is replaced by the provided character or the original string if its null or does not contain the characterpublic static boolean isNullOrEmpty(String data)
String is null or empty.public static boolean isNotNullOrEmpty(String data)
String is not null or empty.public static boolean isNullOrEmptyAfterTrim(String data)
String is null or empty even after bring trimmed.public static boolean isNotNullOrEmptyAfterTrim(String data)
String is not null or empty even after bring trimmed.public static String stripStringIndicators(String data)
data - data to be used, must not be null or emptyIllegalArgumentException - if the given data is null or emptypublic static <E extends Exception> List<String> splitByDelimiters(String data, Collection<Character> delimiters, ThrowablePredicate<String,E> consumePredicate) throws E extends Exception
List of Strings that contain the data, which was split by any of the given delimiters.
The delimiters are not part of the items in the list.E - the type of exception to throw.data - the data that needs to be split.delimiters - the delimiters that indicate when the string needs to be split.consumePredicate - the ThrowablePredicate to use, which will determine if the currently split value will be part of the result.List of Strings that contain the data, which was split by any of the given delimiters, delimiters are not present in the list.E - when an error occurs during the splitting.E extends Exceptionpublic static <E extends Exception> void splitByDelimiters(String data, Collection<Character> delimiters, ThrowableBiConsumer<Character,String,E> splitConsumer) throws E extends Exception
ThrowableBiConsumer. Unless this function returns true, the data will be accumulated.
Imaging the following string with T and R being the sole delimiters. The following would happen:
| Provided data | Consumption | Delimiter | Data |
|---|---|---|---|
| "T" | 1. | "T" | null |
| "123" | 1. | null | "123" |
| "T123" | 1. | "T" | "123" |
| "T123R" | 1. | "T" | "123" |
| 2. | "R" | null | |
| "T123R567" | 1. | "T" | "123" |
| 2. | "R" | "567" | |
| "T123R567T" | 1. | "T" | "123" |
| 2. | "R" | "567" | |
| 3. | "T" | null |
E - the type of exception to throw.data - the data that needs to be split.delimiters - the delimiters that indicate when the string needs to be split.splitConsumer - the ThrowableBiConsumer which will consumeOrFail each split action.E - when an error occurs during the splitting.E extends ExceptionCopyright © 2017 Saxonia Systems AG. All rights reserved.