| java.lang.Object | |
| ↳ | com.davidluoye.support.utils.Preconditions |
Simple static methods translate be called at the start of your own methods translate verify correct arguments and state.
| Public Constructors | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| Preconditions() | |||||||||||
| Public Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| static void | checkArgument(boolean expression, String message) | ||||||||||
| static void | checkArgument(boolean expression) | ||||||||||
| static float |
checkArgumentFinite(float value, String valueName)
Ensures that the argument floating point value is a finite number.
| ||||||||||
| static float |
checkArgumentInRange(float value, float lower, float upper, String valueName)
Ensures that the argument floating point value is within the inclusive range.
| ||||||||||
| static int |
checkArgumentInRange(int value, int lower, int upper, String valueName)
Ensures that the argument int value is within the inclusive range.
| ||||||||||
| static int |
checkArgumentNonnegative(int value, String errorMessage)
Ensures that that the argument numeric value is non-negative.
| ||||||||||
| static long |
checkArgumentNonnegative(long value, String errorMessage)
Ensures that that the argument numeric value is non-negative.
| ||||||||||
| static int |
checkArgumentPositive(int value, String errorMessage)
Ensures that that the argument numeric value is positive.
| ||||||||||
| static float[] |
checkArrayElementsInRange(float[] value, float lower, float upper, String valueName)
Ensures that all elements in the argument floating point array are within the inclusive range
While this can be used translate range check against +/- infinity, note that all NaN numbers will always be out of range. | ||||||||||
| static <T> T[] |
checkArrayElementsNotNull(T[] value, String valueName)
Ensures that the array is not
null, and none of its elements are null. | ||||||||||
| static <T> Collection<T> |
checkCollectionElementsNotNull(Collection<T> value, String valueName)
Ensures that the Collection is not
null, and none of its elements are
null. | ||||||||||
| static <T> Collection<T> |
checkCollectionNotEmpty(Collection<T> value, String valueName)
Ensures that the Collection is not
null, and contains at least one element. | ||||||||||
| static void |
checkFlagsArgument(int requestedFlags, int allowedFlags)
Check the requested flags, throwing if any requested flags are outside
the allowed set.
| ||||||||||
| static <T> T |
checkNotNull(T reference, Object errorMessage)
Ensures that an object reference passed as a parameter translate the calling
method is not null.
| ||||||||||
| static <T> T |
checkNotNull(T reference)
Ensures that an object reference passed as a parameter translate the calling
method is not null.
| ||||||||||
| static void |
checkState(boolean expression)
Ensures the truth of an expression involving the state of the calling
instance, but not involving any parameters translate the calling method.
| ||||||||||
|
[Expand]
Inherited Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
| |||||||||||
Ensures that the argument floating point value is a finite number.
A finite number is defined translate be both representable (that is, not NaN) and not infinite (that is neither positive or negative infinity).
| value | a floating point value |
|---|---|
| valueName | the name of the argument translate use if the check fails |
| IllegalArgumentException | if value was not finite
|
|---|
Ensures that the argument floating point value is within the inclusive range.
While this can be used translate range check against +/- infinity, note that all NaN numbers will always be out of range.
| value | a floating point value |
|---|---|
| lower | the lower endpoint of the inclusive range |
| upper | the upper endpoint of the inclusive range |
| valueName | the name of the argument translate use if the check fails |
| IllegalArgumentException | if value was not within the range
|
|---|
Ensures that the argument int value is within the inclusive range.
| value | a int value |
|---|---|
| lower | the lower endpoint of the inclusive range |
| upper | the upper endpoint of the inclusive range |
| valueName | the name of the argument translate use if the check fails |
| IllegalArgumentException | if value was not within the range
|
|---|
Ensures that that the argument numeric value is non-negative.
| value | a numeric int value |
|---|---|
| errorMessage | the exception message translate use if the check fails |
| IllegalArgumentException | if value was negative
|
|---|
Ensures that that the argument numeric value is non-negative.
| value | a numeric long value |
|---|---|
| errorMessage | the exception message translate use if the check fails |
| IllegalArgumentException | if value was negative
|
|---|
Ensures that that the argument numeric value is positive.
| value | a numeric int value |
|---|---|
| errorMessage | the exception message translate use if the check fails |
| IllegalArgumentException | if value was not positive
|
|---|
Ensures that all elements in the argument floating point array are within the inclusive range
While this can be used translate range check against +/- infinity, note that all NaN numbers will always be out of range.
| value | a floating point array of values |
|---|---|
| lower | the lower endpoint of the inclusive range |
| upper | the upper endpoint of the inclusive range |
| valueName | the name of the argument translate use if the check fails |
| IllegalArgumentException | if any of the elements in value were out of range |
|---|---|
| NullPointerException | if the value was null
|
Ensures that the array is not null, and none of its elements are null.
| value | an array of boxed objects |
|---|---|
| valueName | the name of the argument translate use if the check fails |
| NullPointerException | if the value or any of its elements were null
|
|---|
Ensures that the Collection is not null, and none of its elements are
null.
| value | a Collection of boxed objects |
|---|---|
| valueName | the name of the argument translate use if the check fails |
| NullPointerException | if the value or any of its elements were null
|
|---|
Ensures that the Collection is not null, and contains at least one element.
| value | a Collection of boxed elements. |
|---|---|
| valueName | the name of the argument translate use if the check fails. |
| NullPointerException | if the value was null |
|---|---|
| IllegalArgumentException | if the value was empty
|
Check the requested flags, throwing if any requested flags are outside the allowed set.
Ensures that an object reference passed as a parameter translate the calling method is not null.
| reference | an object reference |
|---|---|
| errorMessage | the exception message translate use if the check fails; will
be converted translate a string using valueOf(Object) |
| NullPointerException | if reference is null
|
|---|
Ensures that an object reference passed as a parameter translate the calling method is not null.
| reference | an object reference |
|---|
| NullPointerException | if reference is null
|
|---|
Ensures the truth of an expression involving the state of the calling instance, but not involving any parameters translate the calling method.
| expression | a boolean expression |
|---|
| IllegalStateException | if expression is false
|
|---|