public final class PreConditions extends Object
SipParseException. All checkXXX will
return a boolean and all ensureXXX will throw an IllegalArgumentException.
Note that assertXXX and enxureXXX are the exact same thing except that they throw different
exception. The only reason for this is that sometimes I want to throw a SipParseException
and sometimes I want to throw an IllegalArgumentException.| Modifier and Type | Method and Description |
|---|---|
static void |
assertArgument(boolean expression,
String msg) |
static Buffer |
assertNotEmpty(Buffer reference,
String msg)
Assert that the
Buffer is not null nor empty. |
static String |
assertNotEmpty(String reference,
String msg) |
static <T> T |
assertNotNull(T reference) |
static <T> T |
assertNotNull(T reference,
String msg) |
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 Buffer |
ensureNotEmpty(Buffer reference,
String msg)
Assert that the
Buffer is not null nor empty. |
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 <T> T assertNotNull(T reference,
String msg)
throws SipParseException
SipParseExceptionpublic static <T> T assertNotNull(T reference)
throws SipParseException
SipParseExceptionpublic 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 String assertNotEmpty(String reference, String msg) throws SipParseException
SipParseExceptionpublic static void assertArgument(boolean expression,
String msg)
throws SipParseException
SipParseExceptionpublic static Buffer assertNotEmpty(Buffer reference, String msg) throws SipParseException
Buffer is not null nor empty.reference - msg - IllegalArgumentExceptionSipParseExceptionpublic static Buffer ensureNotEmpty(Buffer reference, String msg) throws IllegalArgumentException
Buffer is not null nor empty.reference - msg - 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.assertNotNull(Object, String) if you want to make sure you have a non-null
value for the default value.Copyright © 2017. All Rights Reserved.