public class Precondition extends Object
Preconditions
class with a sensible default error message for common situations
Guava:
checkArgument(!StringUtils.isBlank(foo), "'foo' cannot be blank"); this.foo = foo;Kuali:
this.foo = checkNotBlank(foo, "foo");
Constructor and Description |
---|
Precondition() |
Modifier and Type | Method and Description |
---|---|
static int |
checkMax(int arg,
int 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 <T> T |
checkNotNull(T arg,
String argName)
Ensures that an object reference passed as an argument is not null
|
public Precondition()
public 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 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<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 int checkMin(int arg, int min, String argName)
Copyright © 2010–2014 The Kuali Foundation. All rights reserved.