@GwtCompatible public final class ObjectArrayCheck extends ObjectBaseCheck<Object[],ObjectArrayCheck>
Object[]
.
Most check methods are related to the length of the array, like
hasLength(int)
or hasLengthBetween(int, int)
, but there is
also the containsNoNull()
method.
arg, nullAllowed
Constructor and Description |
---|
ObjectArrayCheck(Object[] arg)
For internal use only.
|
Modifier and Type | Method and Description |
---|---|
ObjectArrayCheck |
containsNoNull()
Checks that the array argument does not contain any
null
element, throwing an exception otherwise. |
ObjectArrayCheck |
hasLength(int length)
Checks that the array argument has the given length, throwing an
exception otherwise.
|
ObjectArrayCheck |
hasLengthBetween(int min,
int max)
Checks that the array argument's length is between the two given numbers,
throwing an exception otherwise.
|
IntCheck |
hasLengthWhich()
Creates an
IntCheck property check for the length of the array
argument. |
ObjectArrayCheck |
isNotEmpty()
Checks that the array argument is not empty (meaning it has a length
greater than zero), throwing an exception otherwise.
|
check, checkNull, checkWithCause, hasClass, intPropertyCheck, isEqualTo, isInstanceOf, isNotNull, isNullOr, isSameAs, objectPropertyCheck
checkConversion, me, named, not
public ObjectArrayCheck(Object[] arg)
public ObjectArrayCheck isNotEmpty()
The message type used for exceptions thrown by this method is
MessageType.ARG_EMPTY
.
IllegalArgumentException
- if the array argument is emptycontainsNoNull()
public ObjectArrayCheck hasLength(int length)
The message type used for exceptions thrown by this method is
MessageType.ARG_LENGTH
.
To create more sophisticated checks using the array length, use the
hasLengthWhich()
property check.
length
- The length the array should haveIllegalArgumentException
- if the array argument has a length different from the given
onehasLengthBetween(int, int)
public ObjectArrayCheck hasLengthBetween(int min, int max)
The message type used for exceptions thrown by this method is
MessageType.ARG_LENGTH_BETWEEN
.
To create more sophisticated checks using the array length, use the
hasLengthWhich()
property check.
min
- The minimum length of the arraymax
- The maximum lengthIllegalArgumentException
- If the length of the array is strictly less than
min
or strictly greater than
max
public IntCheck hasLengthWhich()
IntCheck
property check for the length of the array
argument. It can be used to create advanced checks using the array
length. For example:
Check.that(array).isNullOr().hasLengthWhich().isGreaterThan(3);
Just like a check method, this method first asserts the non-nullness of the argument, throwing an exception in case of a failure.
The returned check has the length of this check's array set as the
argument and an argument name that indicates this fact. If the array
reference is null
and allowed to be so (like in the above
example), the returned property check is completely disabled, meaning
none of its check methods will throw an exception. An inversion called
before this method is ignored and does not have any
effect on the check methods called on the returned property check.
public ObjectArrayCheck containsNoNull()
null
element, throwing an exception otherwise. An empty array is considered
valid by this check.
The message type used for exceptions thrown by this method is
MessageType.ARG_CONTAINS_NULL
.
IllegalArgumentException
- If the array contains one or more null
elementsCopyright © 2012–2017 Michael Faes. All rights reserved.