Package dev.prozilla.pine.common.util
Class Strings
java.lang.Object
dev.prozilla.pine.common.util.Strings
Static utility methods for checking certain conditions before operation on strings.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic String
requireNonBlank
(String string) Checks that the given string is not blank and throws anInvalidStringException
if it is not.static String
requireNonBlank
(String string, String message) Checks that the given string is not blank and throws a customizedInvalidStringException
if it is.static String
requireNonEmpty
(String string) Checks that the given string is not empty and throws anInvalidStringException
if it is not.static String
requireNonEmpty
(String string, String message) Checks that the given string is not empty and throws a customizedInvalidStringException
if it is.static String
requirePrefix
(String string, String prefix) Checks that the given string starts with a prefix and throws anInvalidStringException
if it doesn't.static String
requirePrefix
(String string, String prefix, String message) Checks that the given string starts with a prefix and throws a customizedInvalidStringException
if it doesn't.static String
requireSuffix
(String string, String suffix) Checks that the given string ends with a suffix and throws anInvalidStringException
if it doesn't.static String
requireSuffix
(String string, String suffix, String message) Checks that the given string ends with a suffix and throws a customizedInvalidStringException
if it doesn't.
-
Constructor Details
-
Strings
public Strings()
-
-
Method Details
-
requireNonBlank
Checks that the given string is not blank and throws anInvalidStringException
if it is not.- Parameters:
string
- The string to check- Returns:
string
if it is not blank.- Throws:
InvalidStringException
- Ifstring
is blank.
-
requireNonBlank
public static String requireNonBlank(@Nonnull String string, String message) throws InvalidStringException Checks that the given string is not blank and throws a customizedInvalidStringException
if it is.- Parameters:
string
- The string to checkmessage
- The message to be used in the event that anInvalidStringException
is thrown- Returns:
string
if it is not blank.- Throws:
InvalidStringException
- Ifstring
is blank.
-
requireNonEmpty
Checks that the given string is not empty and throws anInvalidStringException
if it is not.- Parameters:
string
- The string to check- Returns:
string
if it is not empty.- Throws:
InvalidStringException
- Ifstring
is empty.
-
requireNonEmpty
public static String requireNonEmpty(@Nonnull String string, String message) throws InvalidStringException Checks that the given string is not empty and throws a customizedInvalidStringException
if it is.- Parameters:
string
- The string to checkmessage
- The message to be used in the event that anInvalidStringException
is thrown- Returns:
string
if it is not empty.- Throws:
InvalidStringException
- Ifstring
is empty.
-
requirePrefix
public static String requirePrefix(@Nonnull String string, @Nonnull String prefix) throws InvalidStringException Checks that the given string starts with a prefix and throws anInvalidStringException
if it doesn't.- Parameters:
string
- The string to checkprefix
- The required prefix of the string- Returns:
string
if it starts with a given prefix.- Throws:
InvalidStringException
- Ifstring
does not start with a given prefix.
-
requirePrefix
public static String requirePrefix(@Nonnull String string, @Nonnull String prefix, String message) throws InvalidStringException Checks that the given string starts with a prefix and throws a customizedInvalidStringException
if it doesn't.- Parameters:
string
- The string to checkprefix
- The required prefix of the stringmessage
- The message to be used in the event that anInvalidStringException
is thrown- Returns:
string
if it starts with a given prefix.- Throws:
InvalidStringException
- Ifstring
does not start with a given prefix.
-
requireSuffix
public static String requireSuffix(@Nonnull String string, @Nonnull String suffix) throws InvalidStringException Checks that the given string ends with a suffix and throws anInvalidStringException
if it doesn't.- Parameters:
string
- The string to checksuffix
- The required suffix of the string- Returns:
string
if it ends with a given suffix.- Throws:
InvalidStringException
- Ifstring
does not end with a given suffix.
-
requireSuffix
public static String requireSuffix(@Nonnull String string, @Nonnull String suffix, String message) throws InvalidStringException Checks that the given string ends with a suffix and throws a customizedInvalidStringException
if it doesn't.- Parameters:
string
- The string to checksuffix
- The required suffix of the stringmessage
- The message to be used in the event that anInvalidStringException
is thrown- Returns:
string
if it ends with a given suffix.- Throws:
InvalidStringException
- Ifstring
does not end with a given suffix.
-