public final class Precondition extends Object
Preconditions
class with a sensible default error message for common situations
Guava:
checkArgument(StringUtils.isNotBlank(foo), "'foo' cannot be blank"); this.foo = foo;Kuali:
this.foo = checkNotBlank(foo, "foo");
Modifier and Type | Method and Description |
---|---|
static int |
checkEquals(int arg,
int expected,
String argName) |
static long |
checkEquals(long arg,
long expected,
String argName) |
static <T> T |
checkEquals(T arg,
T expected,
String argName) |
static File |
checkExists(File arg,
String argName)
Ensures that a File passed as an argument exists
|
static File |
checkIsDir(File arg,
String argName)
Ensures that a File passed as an argument is an existing directory
|
static File |
checkIsFile(File arg,
String argName)
Ensures that a File passed as an argument is a normal file
|
static int |
checkMax(int arg,
int max,
String argName)
Check that arg is less than or equal to max
|
static long |
checkMax(long arg,
long max,
String argName)
Check that arg is less than or equal to max
|
static int |
checkMin(int arg,
int min,
String argName)
Check that arg is greater than or equal to min.
|
static long |
checkMin(long arg,
long min,
String argName)
Check that arg is greater than or equal to min.
|
static com.google.common.base.Optional<Integer> |
checkMin(com.google.common.base.Optional<Integer> arg,
int min,
String argName)
If arg.isPresent(), check that the Integer it contains is greater than or equal to min
|
static com.google.common.base.Optional<Long> |
checkMin(com.google.common.base.Optional<Long> arg,
long min,
String argName)
If arg.isPresent(), check that the Long it contains is greater than or equal to min
|
static com.google.common.base.Optional<String> |
checkNotBlank(com.google.common.base.Optional<String> arg,
String argName)
Ensures that an
Optional<String> passed as an argument does not contain a string that is whitespace or empty (""). |
static String |
checkNotBlank(String arg,
String argName)
Ensures that a String passed as an argument is not whitespace, empty ("") or null
|
static com.google.common.base.Optional<String> |
checkNotEmpty(com.google.common.base.Optional<String> arg,
String argName)
Ensures that an
Optional<String> passed as an argument is not the empty string (""). |
static String |
checkNotEmpty(String arg,
String argName)
Ensures that a String passed as an argument is not the empty string ("") or null
|
static <T> T |
checkNotEquals(T arg,
T illegal,
String argName) |
static <T> T |
checkNotNull(T arg,
String argName)
Ensures that an object reference passed as an argument is not null
|
static <C extends Comparable> |
checkRange(C arg,
com.google.common.collect.Range<C> range,
String argName) |
static int |
checkRange(int arg,
int min,
int max,
String argName) |
static <I extends Iterable<T>,T> |
checkSize(I iterable,
int expected) |
static void |
checkTruths(int expected,
boolean... expressions) |
public static File checkExists(File arg, String argName)
arg
- a File passed as an argumentargName
- the name of the argumentNullPointerException
- If arg is null. The exception message contains the name of the argument that was nullIllegalArgumentException
- If arg does not exist or argName is blankpublic static File checkIsDir(File arg, String argName)
arg
- a File passed as an argumentargName
- the name of the argumentNullPointerException
- If arg is null. The exception message contains the name of the argument that was nullIllegalArgumentException
- If arg does not exist, is not a directory, or argName is blankpublic static File checkIsFile(File arg, String argName)
arg
- a File passed as an argumentargName
- the name of the argumentNullPointerException
- If arg is null. The exception message contains the name of the argument that was nullIllegalArgumentException
- If arg does not exist, is not a normal file, or argName is blankpublic static <T> T checkNotNull(T arg, String argName)
arg
- an object reference passed as an argumentargName
- the name of the argumentNullPointerException
- If arg is null. The exception message contains the name of the argument that was nullIllegalArgumentException
- If argName is blankpublic static String checkNotBlank(String arg, String argName)
arg
- a String passed as an argumentargName
- the name of the argumentIllegalArgumentException
- If arg is blank. The exception message contains the name of the argument that was blankIllegalArgumentException
- If argName is blankpublic static String checkNotEmpty(String arg, String argName)
arg
- a String passed as an argumentargName
- the name of the argumentIllegalArgumentException
- If arg is blank. The exception message contains the name of the argument that was blankIllegalArgumentException
- If argName is blankpublic static com.google.common.base.Optional<String> checkNotBlank(com.google.common.base.Optional<String> arg, String argName)
Optional<String>
passed as an argument does not contain a string that is whitespace or empty ("").arg
- an Optional<String>
passed as an argumentargName
- the name of the argumentOptional<String>
that was validatedIllegalArgumentException
- If arg is blank. The exception message contains the name of the argument that was blankIllegalArgumentException
- If argName is blankpublic static com.google.common.base.Optional<String> checkNotEmpty(com.google.common.base.Optional<String> arg, String argName)
Optional<String>
passed as an argument is not the empty string ("").arg
- an Optional<String>
passed as an argumentargName
- the name of the argumentOptional<String>
that was validatedIllegalArgumentException
- If arg is blank. The exception message contains the name of the argument that was blankIllegalArgumentException
- If argName is blankpublic static com.google.common.base.Optional<Integer> checkMin(com.google.common.base.Optional<Integer> arg, int min, String argName)
public static com.google.common.base.Optional<Long> checkMin(com.google.common.base.Optional<Long> arg, long min, String argName)
public static int checkMax(int arg, int max, String argName)
public static long checkMax(long arg, long max, String argName)
public static <C extends Comparable> C checkRange(C arg, com.google.common.collect.Range<C> range, String argName)
public static int checkRange(int arg, int min, int max, String argName)
public static int checkMin(int arg, int min, String argName)
public static long checkMin(long arg, long min, String argName)
public static <T> T checkNotEquals(T arg, T illegal, String argName)
public static <T> T checkEquals(T arg, T expected, String argName)
public static long checkEquals(long arg, long expected, String argName)
public static int checkEquals(int arg, int expected, String argName)
public static void checkTruths(int expected, boolean... expressions)
Copyright © 2015 The Kuali Foundation. All rights reserved.