Package io.github.zero88.utils
Class Strings
- java.lang.Object
-
- io.github.zero88.utils.Strings
-
public final class Strings extends java.lang.ObjectStrings Utilities.- Since:
- 1.0.0
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static intconvertToInt(java.lang.String text, int fallback)Convertstringtoint.static java.lang.StringconvertToString(java.io.InputStream inputStream)Convert to string.static java.lang.Stringduplicate(java.lang.String value, int times)Construct from given value in multiple times.static java.lang.Stringfallback(java.lang.String value, @NotNull java.util.function.Supplier<java.lang.String> fallback)Fallback string.static java.lang.Stringfallback(java.lang.String value, java.lang.String fallback)Checks given string is blank then fallback to given valuestatic java.lang.Stringformat(java.lang.String msgPattern, java.lang.Object... params)Format string.static java.lang.ObjectgetFirstNotNull(java.lang.Object... objects)Gets first not null.static java.lang.StringgetFirstNotNull(java.lang.String... strings)Gets first not null.static java.lang.StringgetMatchValue(java.lang.String with, java.lang.String[] withMatch)Gets match value.static java.lang.StringgetMatchValueOrFirstOne(java.lang.String with, java.lang.String[] withMatch)Gets match value or first one.static booleanin(java.lang.String with, boolean equalsIgnoreCase, java.lang.String... values)In boolean.static booleanin(java.lang.String with, java.lang.String... values)In boolean.static booleanisBlank(java.lang.String text)Check given text is blank or not.static booleanisNotBlank(java.lang.String text)Check given text is not blank or not.static java.lang.StringoptimizeMultipleSpace(java.lang.String text)Checks that the specified string reference is notblankthen remove multiple space characters to one space.static java.lang.StringoptimizeNoSpace(java.lang.String text)Checks that the specified string reference is notblankthen remove all space characters.static java.lang.StringpadLeft(java.lang.String inputString, int length)Pad left string with blank' 'static java.lang.StringpadLeftZeros(java.lang.String inputString, int length)Pad left string with'0'static java.lang.StringrequiredMinLength(java.lang.String text, int minLength)Checks that the specified string reference is notblankand its length greater than given input.static java.lang.StringrequireNotBlank(java.lang.Object object, java.lang.String message)Checks that the specified object reference isnot blank.static java.lang.StringrequireNotBlank(java.lang.String text)Checks that the specified string reference is notblank.static java.lang.StringrequireNotBlank(java.lang.String text, @NotNull java.util.function.Supplier<? extends java.lang.RuntimeException> errorSupplier)Checks that the specified string reference isnot blank.static java.lang.StringrequireNotBlank(java.lang.String text, java.lang.String message)Checks that the specified string reference is notblank.static <T> TrequireNotBlank(T obj, @NotNull java.util.function.Supplier<? extends java.lang.RuntimeException> errorSupplier)Checks that the specified object reference isnot nullornot blankif given object isstring.static java.lang.StringtoSnakeLowerCase(@NotNull java.lang.String text)To snake case lc string.static java.lang.StringtoSnakeUpperCase(@NotNull java.lang.String text)To snake case uc string.static java.lang.StringtoString(java.lang.Object object)To String.
-
-
-
Method Detail
-
toString
public static java.lang.String toString(java.lang.Object object)
To String.- Parameters:
object- the object cast to string.- Returns:
blankif null, elseObject.toString()withtrim- Since:
- 1.0.0
-
duplicate
public static java.lang.String duplicate(java.lang.String value, int times)Construct from given value in multiple times.- Parameters:
value- Value to duplicatetimes- Times to duplicate- Returns:
- Append value
- Since:
- 1.0.0
-
isBlank
public static boolean isBlank(java.lang.String text)
Check given text is blank or not.- Parameters:
text- the text to check for blank- Returns:
Trueif blank, else otherwise- Since:
- 1.0.0
-
isNotBlank
public static boolean isNotBlank(java.lang.String text)
Check given text is not blank or not. The reversion ofisBlank(String)- Parameters:
text- the text to check for blank- Returns:
Trueif not blank, else otherwise- Since:
- 1.0.0
-
requireNotBlank
public static java.lang.String requireNotBlank(java.lang.String text)
Checks that the specified string reference is notblank. This method is designed primarily for doing parameter validation in methods and constructors, as demonstrated below:public Foo(Bar bar) { this.bar = Strings.requireNotBlank(bar); }- Parameters:
text- the text to check for blank- Returns:
- Trimmed
textif notblank - Throws:
java.lang.IllegalArgumentException- ifobjisblank- Since:
- 1.0.0
-
requireNotBlank
public static java.lang.String requireNotBlank(java.lang.String text, java.lang.String message)Checks that the specified string reference is notblank. This method is designed primarily for doing parameter validation in methods and constructors, as demonstrated below:public Foo(Bar bar) { this.bar = Strings.requireNotBlank(bar, "String cannot blank"); }- Parameters:
text- the text to check for blankmessage- the error message will be included in exception- Returns:
- Trimmed
textif notblank - Throws:
java.lang.IllegalArgumentException- ifobjisblank- Since:
- 1.0.0
-
requireNotBlank
public static java.lang.String requireNotBlank(java.lang.String text, @NotNull @NotNull java.util.function.Supplier<? extends java.lang.RuntimeException> errorSupplier)Checks that the specified string reference isnot blank. Ifblank, raise exception in given supplier.- Parameters:
text- the texterrorSupplier- the exception supplier- Returns:
- Trimmed
textif notblank - Since:
- 1.0.0
-
requireNotBlank
public static java.lang.String requireNotBlank(java.lang.Object object, java.lang.String message)Checks that the specified object reference isnot blank. ifnot blank, it will convert to string bytoString()method- Parameters:
object- the object to checkmessage- the error message will be included in exception- Returns:
- Trimmed
objectifnot blank - Throws:
java.lang.IllegalArgumentException- ifobjisblank- Since:
- 1.0.0
-
requireNotBlank
public static <T> T requireNotBlank(T obj, @NotNull @NotNull java.util.function.Supplier<? extends java.lang.RuntimeException> errorSupplier)Checks that the specified object reference isnot nullornot blankif given object isstring. Ifblank, raise exception in given supplier.- Type Parameters:
T- Type ofobject- Parameters:
obj- the objecterrorSupplier- the error supplier- Returns:
- the t
- Since:
- 1.0.0
-
optimizeMultipleSpace
public static java.lang.String optimizeMultipleSpace(java.lang.String text)
Checks that the specified string reference is notblankthen remove multiple space characters to one space.- Parameters:
text- Given input- Returns:
- Optimization text
- Throws:
java.lang.IllegalArgumentException- iftextisblank- Since:
- 1.0.0
-
optimizeNoSpace
public static java.lang.String optimizeNoSpace(java.lang.String text)
Checks that the specified string reference is notblankthen remove all space characters.- Parameters:
text- Given input- Returns:
- Optimization text
- Throws:
java.lang.IllegalArgumentException- iftextisblank- Since:
- 1.0.0
-
requiredMinLength
public static java.lang.String requiredMinLength(java.lang.String text, int minLength)Checks that the specified string reference is notblankand its length greater than given input.- Parameters:
text- Given inputminLength- Min length- Returns:
- this text if conforms condition
- Throws:
java.lang.IllegalArgumentException- iftextoroptimized textisblank- Since:
- 1.0.0
-
toSnakeLowerCase
public static java.lang.String toSnakeLowerCase(@NotNull @NotNull java.lang.String text)To snake case lc string.- Parameters:
text- the text- Returns:
- the string
- Since:
- 1.0.0
-
toSnakeUpperCase
public static java.lang.String toSnakeUpperCase(@NotNull @NotNull java.lang.String text)To snake case uc string.- Parameters:
text- the text- Returns:
- the string
- Since:
- 1.0.0
-
convertToInt
public static int convertToInt(java.lang.String text, int fallback)Convertstringtoint.- Parameters:
text- Text to convertfallback- Default value to fallback- Returns:
- Int value that corresponding to given text
- Since:
- 1.0.0
-
convertToString
public static java.lang.String convertToString(java.io.InputStream inputStream)
Convert to string.- Parameters:
inputStream- the input stream- Returns:
- the string
- Since:
- 1.0.0
-
format
public static java.lang.String format(java.lang.String msgPattern, java.lang.Object... params)Format string.- Parameters:
msgPattern- the msg patternparams- the params- Returns:
- the string
- Since:
- 1.0.0
-
fallback
public static java.lang.String fallback(java.lang.String value, java.lang.String fallback)Checks given string is blank then fallback to given value- Parameters:
value- Stringfallback- Fallback value, must not blank- Returns:
- given value if not blank, otherwise
fallback - Since:
- 1.0.0
-
fallback
public static java.lang.String fallback(java.lang.String value, @NotNull @NotNull java.util.function.Supplier<java.lang.String> fallback)Fallback string.- Parameters:
value- the valuefallback- the fallback- Returns:
- the string
- Since:
- 1.0.0
-
in
public static boolean in(java.lang.String with, boolean equalsIgnoreCase, java.lang.String... values)In boolean.- Parameters:
with- the withequalsIgnoreCase- the equals ignore casevalues- the values- Returns:
- the boolean
- Since:
- 1.0.0
-
in
public static boolean in(java.lang.String with, java.lang.String... values)In boolean.- Parameters:
with- the withvalues- the values- Returns:
- the boolean
- Since:
- 1.0.0
-
getFirstNotNull
public static java.lang.String getFirstNotNull(java.lang.String... strings)
Gets first not null.- Parameters:
strings- the strings- Returns:
- the first not null
- Since:
- 1.0.0
-
getFirstNotNull
public static java.lang.Object getFirstNotNull(java.lang.Object... objects)
Gets first not null.- Parameters:
objects- the objects- Returns:
- the first not null
- Since:
- 1.0.0
-
getMatchValueOrFirstOne
public static java.lang.String getMatchValueOrFirstOne(java.lang.String with, java.lang.String[] withMatch)Gets match value or first one.- Parameters:
with- the withwithMatch- the with match- Returns:
- the match value or first one
- Since:
- 1.0.0
-
getMatchValue
public static java.lang.String getMatchValue(java.lang.String with, java.lang.String[] withMatch)Gets match value.- Parameters:
with- the withwithMatch- the with match- Returns:
- the match value
- Since:
- 1.0.0
-
padLeft
public static java.lang.String padLeft(java.lang.String inputString, int length)Pad left string with blank' '- Parameters:
inputString- input stringlength- total length- Returns:
- padded string
-
padLeftZeros
public static java.lang.String padLeftZeros(java.lang.String inputString, int length)Pad left string with'0'- Parameters:
inputString- input stringlength- total length- Returns:
- padded string
-
-