public final class PreConditions extends Object
IllegalArgumentException.| Modifier and Type | Method and Description |
|---|---|
static boolean |
checkIfEmpty(String string)
Check if a string is empty, which includes null check.
|
static boolean |
checkIfNotEmpty(String string) |
static void |
ensureArgument(boolean expression,
String msg) |
static String |
ensureNotEmpty(String reference,
String msg) |
static <T> T |
ensureNotNull(T reference) |
static <T> T |
ensureNotNull(T reference,
String msg) |
static <T> T |
ifNull(T reference,
T defaultValue)
If our reference is null then return a default value instead.
|
public static <T> T ensureNotNull(T reference,
String msg)
throws IllegalArgumentException
IllegalArgumentExceptionpublic static <T> T ensureNotNull(T reference)
throws IllegalArgumentException
IllegalArgumentExceptionpublic static boolean checkIfEmpty(String string)
string - public static boolean checkIfNotEmpty(String string)
public static String ensureNotEmpty(String reference, String msg) throws IllegalArgumentException
IllegalArgumentExceptionpublic static void ensureArgument(boolean expression,
String msg)
throws IllegalArgumentException
IllegalArgumentExceptionpublic static <T> T ifNull(T reference,
T defaultValue)
reference - the thing to check.defaultValue - the default value to return if the above reference is null.ensureNotNull(Object, String) if you want to make sure you have a non-null
value for the default value.Copyright © 2019. All rights reserved.