@GwtCompatible public final class CollectionCheck extends ObjectBaseCheck<Collection<?>,CollectionCheck>
Collection
types. It provides a functionality
similar to the ObjectArrayCheck
class.
Most check methods are related to the size of the collection, like
hasSize(int)
or hasSizeBetween(int, int)
, but there is also
the containsNoNull()
method.
arg, nullAllowed
Constructor and Description |
---|
CollectionCheck(Collection<?> arg)
For internal use only.
|
Modifier and Type | Method and Description |
---|---|
CollectionCheck |
containsNoNull()
Checks that the collection argument does not contain any
null element, throwing an exception otherwise. |
CollectionCheck |
hasSize(int size)
Checks that the collection argument has the given size, throwing an
exception otherwise.
|
CollectionCheck |
hasSizeBetween(int min,
int max)
Checks that the collection argument's size is between the two given
numbers, throwing an exception otherwise.
|
IntCheck |
hasSizeWhich()
Creates an
IntCheck property check for the size of the collection
argument. |
CollectionCheck |
isNotEmpty()
Checks that the collection argument is not empty (meaning it has a size
greater than zero), throwing an exception otherwise.
|
check, checkNull, checkWithCause, hasClass, intPropertyCheck, isEqualTo, isInstanceOf, isNotNull, isNullOr, isSameAs, objectPropertyCheck
checkConversion, me, named, not
public CollectionCheck(Collection<?> arg)
public CollectionCheck isNotEmpty()
The message type used for exceptions thrown by this method is
MessageType.ARG_EMPTY
.
IllegalArgumentException
- if the collection argument is emptycontainsNoNull()
public CollectionCheck hasSize(int size)
The message type used for exceptions thrown by this method is
MessageType.ARG_SIZE
.
To create more sophisticated checks using the collection size, use the
hasSizeWhich()
property check.
size
- The size the collection should haveIllegalArgumentException
- if the collection argument has a size different from the
given onehasSizeBetween(int, int)
public CollectionCheck hasSizeBetween(int min, int max)
The message type used for exceptions thrown by this method is
MessageType.ARG_SIZE_BETWEEN
.
To create more sophisticated checks using the collection size, use the
hasSizeWhich()
property check.
min
- The minimum size of the collectionmax
- The maximum sizeIllegalArgumentException
- If the size of the collection is strictly less than
min
or strictly greater than
max
public IntCheck hasSizeWhich()
IntCheck
property check for the size of the collection
argument. It can be used to create advanced checks using the collection
size. For example:
Check.that(list).isNullOr().hasSizeWhich().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 size of this check's collection set as the
argument and an argument name that indicates this fact. If the collection
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 CollectionCheck containsNoNull()
null
element, throwing an exception otherwise. An empty
collection is considered valid by this check.
The message type used for exceptions thrown by this method is
MessageType.ARG_CONTAINS_NULL
.
IllegalArgumentException
- If the collection contains one or more null
elementsCopyright © 2012–2017 Michael Faes. All rights reserved.