Package com.ongres.scram.common.util
Class Preconditions
- java.lang.Object
-
- com.ongres.scram.common.util.Preconditions
-
public final class Preconditions extends java.lang.Object
Generic utility methods used to validate data.
-
-
Constructor Summary
Constructors Modifier Constructor Description private
Preconditions()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> T
castNonNull(T ref)
static void
checkArgument(boolean check, @NotNull java.lang.String valueName)
Checks that the argument is valid, based in a check boolean condition.static void
checkArgument(boolean check, @NotNull java.lang.String valueName, @NotNull java.lang.String errMsg)
Checks that the argument is valid, based in a check boolean condition.static char @NotNull []
checkNotEmpty(char @NotNull [] value, @NotNull java.lang.String valueName)
Checks that the char[] is not null and not empty.static @NotNull java.lang.String
checkNotEmpty(@NotNull java.lang.String value, @NotNull java.lang.String valueName)
Checks that the String is not null and not empty.static <T> T
checkNotNull(T value, @NotNull java.lang.String valueName)
Checks that the argument is not null.static int
gt0(int value, @NotNull java.lang.String valueName)
Checks that the integer argument is positive.static boolean
isNullOrEmpty(@Nullable java.lang.String string)
Returnstrue
if the given string is null or is the empty string.
-
-
-
Method Detail
-
checkNotNull
@NotNull public static <T> T checkNotNull(@Nullable T value, @NotNull @NotNull java.lang.String valueName)
Checks that the argument is not null.- Type Parameters:
T
- The type of the value- Parameters:
value
- The value to be checkedvalueName
- The name of the value that is checked in the method- Returns:
- The same value passed as argument
- Throws:
java.lang.IllegalArgumentException
- If value is null.
-
castNonNull
@NotNull public static <T> T castNonNull(@Nullable T ref)
-
checkNotEmpty
@NotNull public static @NotNull java.lang.String checkNotEmpty(@NotNull @NotNull java.lang.String value, @NotNull @NotNull java.lang.String valueName)
Checks that the String is not null and not empty.- Parameters:
value
- The String to checkvalueName
- The name of the value that is checked in the method- Returns:
- The same String passed as argument
- Throws:
java.lang.IllegalArgumentException
- If value is null or empty
-
checkNotEmpty
public static char @NotNull [] checkNotEmpty(char @NotNull [] value, @NotNull @NotNull java.lang.String valueName)
Checks that the char[] is not null and not empty.- Parameters:
value
- The String to checkvalueName
- The name of the value that is checked in the method- Returns:
- The same String passed as argument
- Throws:
java.lang.IllegalArgumentException
- If value is null or empty
-
checkArgument
public static void checkArgument(boolean check, @NotNull @NotNull java.lang.String valueName)
Checks that the argument is valid, based in a check boolean condition.- Parameters:
check
- The boolean checkvalueName
- The name of the value that is checked in the method- Throws:
java.lang.IllegalArgumentException
- if check is not valid
-
checkArgument
public static void checkArgument(boolean check, @NotNull @NotNull java.lang.String valueName, @NotNull @NotNull java.lang.String errMsg)
Checks that the argument is valid, based in a check boolean condition.- Parameters:
check
- The boolean checkvalueName
- The name of the value that is checked in the methoderrMsg
- Detail of the error message- Throws:
java.lang.IllegalArgumentException
- if check is not valid
-
gt0
public static int gt0(int value, @NotNull @NotNull java.lang.String valueName)
Checks that the integer argument is positive.- Parameters:
value
- The value to be checkedvalueName
- The name of the value that is checked in the method- Returns:
- The same value passed as argument
- Throws:
java.lang.IllegalArgumentException
- If value is equal or less than 0
-
isNullOrEmpty
public static boolean isNullOrEmpty(@Nullable @Nullable java.lang.String string)
Returnstrue
if the given string is null or is the empty string.- Parameters:
string
- a String reference to check- Returns:
true
if the string is null or the string is empty
-
-