Type Parameters:
S - the type of this validator
E - the type of elements in the collection
All Known Subinterfaces:
CollectionValidator<T,E>, ListValidator<T,E>

public interface CollectionComponent<S,E>
Methods that all Collection validators must contain.
  • Method Summary

    Modifier and Type
    Method
    Description
    contains(E expected)
    Ensures that the collection contains an element.
    contains(E expected, String name)
    Ensures that the collection contains an element.
    containsAll(E[] expected)
    Ensures that the collection contains all the elements in expected.
    containsAll(E[] expected, String name)
    Ensures that the collection contains all the elements in expected.
    Ensures that the collection contains all the elements in expected.
    containsAll(Collection<E> expected, String name)
    Ensures that the collection contains all the elements in expected.
    containsAny(E[] expected)
    Ensures that the collection contains any elements in expected.
    containsAny(E[] expected, String name)
    Ensures that the collection contains at least one element in expected.
    Ensures that the collection contains any elements in expected.
    containsAny(Collection<E> expected, String name)
    Ensures that the collection contains at least one element in expected.
    containsExactly(E[] expected)
    Ensures that the collection consists of the same elements as expected, irrespective of their order.
    containsExactly(E[] expected, String name)
    Ensures that the collection consists of the same elements as expected, irrespective of their order.
    Ensures that the collection consists of the same elements as expected, irrespective of their order.
    containsExactly(Collection<E> expected, String name)
    Ensures that the collection consists of the same elements as expected, irrespective of their order.
    doesNotContain(E unwanted)
    Ensures that the collection does not contain unwanted.
    doesNotContain(E unwanted, String name)
    Ensures that the collection does not contain unwanted.
    doesNotContainAll(E[] unwanted)
    Allows the collection to contain some, but not all, elements from a collection.
    doesNotContainAll(E[] unwanted, String name)
    Allows the collection to contain some, but not all, elements from a collection.
    Allows the collection to contain some, but not all, elements from another collection.
    Allows the collection to contain some, but not all, elements from another collection.
    doesNotContainAny(E[] unwanted)
    Ensures that the collection does not contain any of the elements in unwanted.
    doesNotContainAny(E[] unwanted, String name)
    Ensures that the collection does not contain any of the elements in unwanted.
    Ensures that the collection does not contain any of the elements in unwanted.
    Ensures that the collection does not contain any of the elements in unwanted.
    Ensures that the collection does not contain any duplicate elements.
    Ensures that the collection and unwanted consist of different elements, irrespective of their order.
    doesNotContainExactly(E[] unwanted, String name)
    Ensures that the collection and unwanted consist of different elements, irrespective of their order.
    Ensures that the collection and unwanted consist of different elements, irrespective of their order.
    Ensures that the collection and unwanted consist of different elements, irrespective of their order.
    Ensures that the collection is empty.
    Ensures that the collection is not empty.
    Returns a validator for the collection's size.
  • Method Details

    • isEmpty

      S isEmpty()
      Ensures that the collection is empty.
      Returns:
      this
      Throws:
      NullPointerException - if the value is null
      IllegalArgumentException - if the collection is not empty
    • isNotEmpty

      S isNotEmpty()
      Ensures that the collection is not empty.
      Returns:
      this
      Throws:
      NullPointerException - if the value is null
      IllegalArgumentException - if the collection is empty
    • contains

      S contains(E expected)
      Ensures that the collection contains an element.
      Parameters:
      expected - the element
      Returns:
      this
      Throws:
      NullPointerException - if the value or expected are null
      IllegalArgumentException - if the collection does not contain expected
    • doesNotContain

      S doesNotContain(E unwanted)
      Ensures that the collection does not contain unwanted.
      Parameters:
      unwanted - the unwanted element
      Returns:
      this
      Throws:
      NullPointerException - if the value or unwanted are null
      IllegalArgumentException - if the collection contains unwanted
    • contains

      S contains(E expected, String name)
      Ensures that the collection contains an element.
      Parameters:
      expected - the element
      name - the name of the element
      Returns:
      this
      Throws:
      NullPointerException - if the value or any of the arguments are null
      IllegalArgumentException - if:
      • name is empty
      • name contains whitespace
      • name is already in use by the value being validated or the validator context
      • the collection does not contain expected
    • doesNotContain

      S doesNotContain(E unwanted, String name)
      Ensures that the collection does not contain unwanted.
      Parameters:
      unwanted - the unwanted element
      name - the name of the element
      Returns:
      this
      Throws:
      NullPointerException - if the value or any of the arguments are null
      IllegalArgumentException - if:
      • name is empty
      • name contains whitespace
      • name is already in use by the value being validated or the validator context
      • the collection contains unwanted
    • containsExactly

      S containsExactly(E[] expected)
      Ensures that the collection consists of the same elements as expected, irrespective of their order.

      In contrast, isEqualTo() requires the same element ordering.

      This method is provided for convenience, without any implied performance benefits compared to containsExactly(Collection)

      Parameters:
      expected - the desired elements
      Returns:
      this
      Throws:
      NullPointerException - if the value or expected are null
      IllegalArgumentException - if:
      • the collection is missing any element in expected
      • the collection contains any element that is not in expected
    • doesNotContainExactly

      S doesNotContainExactly(E[] unwanted)
      Ensures that the collection and unwanted consist of different elements, irrespective of their order.

      This method is provided for convenience, without any implied performance benefits compared to doesNotContainExactly(Collection)

      Parameters:
      unwanted - the unwanted elements
      Returns:
      this
      Throws:
      NullPointerException - if the value or unwanted are null
      IllegalArgumentException - if the collection consists of the same elements as unwanted, irrespective of their order
    • containsExactly

      S containsExactly(Collection<E> expected)
      Ensures that the collection consists of the same elements as expected, irrespective of their order.

      In contrast, isEqualTo() requires the same element ordering.

      Parameters:
      expected - the desired elements
      Returns:
      this
      Throws:
      NullPointerException - if the value or expected are null
      IllegalArgumentException - if:
      • the collection is missing any element in expected
      • the collection contains any element that is not in expected
    • doesNotContainExactly

      S doesNotContainExactly(Collection<E> unwanted)
      Ensures that the collection and unwanted consist of different elements, irrespective of their order.
      Parameters:
      unwanted - the unwanted elements
      Returns:
      this
      Throws:
      NullPointerException - if the value or unwanted are null
      IllegalArgumentException - if the collection consists of the same elements as unwanted, irrespective of their order
    • containsExactly

      S containsExactly(E[] expected, String name)
      Ensures that the collection consists of the same elements as expected, irrespective of their order.

      In contrast, isEqualTo() requires the same element ordering.

      This method is provided for convenience, without any implied performance benefits compared to containsExactly(Collection, String)

      Parameters:
      expected - the desired elements
      name - the name of the expected collection
      Returns:
      this
      Throws:
      NullPointerException - if the value or any of the arguments are null
      IllegalArgumentException - if:
      • name is empty
      • name contains whitespace
      • name is already in use by the value being validated or the validator context
      • the collection and expected contain different elements, irrespective of their order
    • doesNotContainExactly

      S doesNotContainExactly(E[] unwanted, String name)
      Ensures that the collection and unwanted consist of different elements, irrespective of their order.

      This method is provided for convenience, without any implied performance benefits compared to doesNotContainExactly(Collection, String)

      Parameters:
      unwanted - the unwanted elements
      name - the name of the unwanted collection
      Returns:
      this
      Throws:
      NullPointerException - if the value or any of the arguments are null
      IllegalArgumentException - if:
      • name is empty
      • name contains whitespace
      • name is already in use by the value being validated or the validator context
      • the collection consists of the same elements as unwanted, irrespective of their order
    • containsExactly

      S containsExactly(Collection<E> expected, String name)
      Ensures that the collection consists of the same elements as expected, irrespective of their order.

      In contrast, isEqualTo() requires the same element ordering.

      Parameters:
      expected - the desired elements
      name - the name of the expected collection
      Returns:
      this
      Throws:
      NullPointerException - if the value or any of the arguments are null
      IllegalArgumentException - if:
      • name is empty
      • name contains whitespace
      • name is already in use by the value being validated or the validator context
      • the collection and expected contain different elements, irrespective of their order
    • doesNotContainExactly

      S doesNotContainExactly(Collection<E> unwanted, String name)
      Ensures that the collection and unwanted consist of different elements, irrespective of their order.
      Parameters:
      unwanted - the unwanted elements
      name - the name of the unwanted collection
      Returns:
      this
      Throws:
      NullPointerException - if the value or any of the arguments are null
      IllegalArgumentException - if:
      • name is empty
      • name contains whitespace
      • name is already in use by the value being validated or the validator context
      • the collection consists of the same elements as unwanted, irrespective of their order
    • containsAny

      S containsAny(E[] expected)
      Ensures that the collection contains any elements in expected.

      This method is provided for convenience, without any implied performance benefits compared to containsAny(Collection)

      Parameters:
      expected - the desired elements
      Returns:
      this
      Throws:
      NullPointerException - if the value or expected are null
      IllegalArgumentException - if the collection does not contain any element in expected
    • doesNotContainAny

      S doesNotContainAny(E[] unwanted)
      Ensures that the collection does not contain any of the elements in unwanted.

      This method is provided for convenience, without any implied performance benefits compared to doesNotContainAny(Collection)

      Parameters:
      unwanted - the unwanted elements
      Returns:
      this
      Throws:
      NullPointerException - if the value or unwanted are null
      IllegalArgumentException - if the collection contains any of the elements in unwanted
    • containsAny

      S containsAny(Collection<E> expected)
      Ensures that the collection contains any elements in expected.
      Parameters:
      expected - the desired elements
      Returns:
      this
      Throws:
      NullPointerException - if the value or expected are null
      IllegalArgumentException - if the collection does not contain any element in expected
    • doesNotContainAny

      S doesNotContainAny(Collection<E> unwanted)
      Ensures that the collection does not contain any of the elements in unwanted.
      Parameters:
      unwanted - the unwanted elements
      Returns:
      this
      Throws:
      NullPointerException - if the value or unwanted are null
      IllegalArgumentException - if the collection contains any of the elements in unwanted
    • containsAny

      S containsAny(E[] expected, String name)
      Ensures that the collection contains at least one element in expected.

      This method is provided for convenience, without any implied performance benefits compared to containsAny(Collection, String)

      Parameters:
      expected - the desired elements
      name - the name of the expected collection
      Returns:
      this
      Throws:
      NullPointerException - if the value or any of the arguments are null
      IllegalArgumentException - if:
      • name is empty
      • name contains whitespace
      • name is already in use by the value being validated or the validator context
      • the collection does not contain any element in expected
    • doesNotContainAny

      S doesNotContainAny(E[] unwanted, String name)
      Ensures that the collection does not contain any of the elements in unwanted.

      This method is provided for convenience, without any implied performance benefits compared to doesNotContainAny(Collection, String)

      Parameters:
      unwanted - the unwanted elements
      name - the name of the unwanted collection
      Returns:
      this
      Throws:
      NullPointerException - if the value or any of the arguments are null
      IllegalArgumentException - if:
      • name is empty
      • name contains whitespace
      • name is already in use by the value being validated or the validator context
      • the collection contains any of the elements in unwanted
    • containsAny

      S containsAny(Collection<E> expected, String name)
      Ensures that the collection contains at least one element in expected.
      Parameters:
      expected - the desired elements
      name - the name of the expected collection
      Returns:
      this
      Throws:
      NullPointerException - if the value or any of the arguments are null
      IllegalArgumentException - if:
      • name is empty
      • name contains whitespace
      • name is already in use by the value being validated or the validator context
      • the collection does not contain any element in expected
    • doesNotContainAny

      S doesNotContainAny(Collection<E> unwanted, String name)
      Ensures that the collection does not contain any of the elements in unwanted.
      Parameters:
      unwanted - the unwanted elements
      name - the name of the unwanted collection
      Returns:
      this
      Throws:
      NullPointerException - if the value or any of the arguments are null
      IllegalArgumentException - if:
      • name is empty
      • name contains whitespace
      • name is already in use by the value being validated or the validator context
      • the collection contains any of the elements in unwanted
    • containsAll

      S containsAll(E[] expected)
      Ensures that the collection contains all the elements in expected.

      This method is provided for convenience, without any implied performance benefits compared to containsAll(Collection)

      Parameters:
      expected - the desired elements
      Returns:
      this
      Throws:
      NullPointerException - if the value or expected are null
      IllegalArgumentException - if the collection does not contain all the elements in expected
    • doesNotContainAll

      S doesNotContainAll(E[] unwanted)
      Allows the collection to contain some, but not all, elements from a collection.

      This method is provided for convenience, without any implied performance benefits compared to doesNotContainAll(Collection)

      Parameters:
      unwanted - the unwanted elements
      Returns:
      this
      Throws:
      NullPointerException - if the value or unwanted are null
      IllegalArgumentException - if the collection contains all the elements in unwanted
    • containsAll

      S containsAll(Collection<E> expected)
      Ensures that the collection contains all the elements in expected.
      Parameters:
      expected - the desired elements
      Returns:
      this
      Throws:
      NullPointerException - if the value or expected are null
      IllegalArgumentException - if the collection does not contain all the elements in expected
    • doesNotContainAll

      S doesNotContainAll(Collection<E> unwanted)
      Allows the collection to contain some, but not all, elements from another collection.
      Parameters:
      unwanted - the unwanted elements
      Returns:
      this
      Throws:
      NullPointerException - if the value or unwanted are null
      IllegalArgumentException - if the collection contains all the elements in unwanted
    • containsAll

      S containsAll(E[] expected, String name)
      Ensures that the collection contains all the elements in expected.

      This method is provided for convenience, without any implied performance benefits compared to containsAll(Collection, String)

      Parameters:
      expected - the desired elements
      name - the name of the expected collection
      Returns:
      this
      Throws:
      NullPointerException - if the value or any of the arguments are null
      IllegalArgumentException - if:
      • name is empty
      • name contains whitespace
      • name is already in use by the value being validated or the validator context
      • the collection does not contain all elements in expected
    • doesNotContainAll

      S doesNotContainAll(E[] unwanted, String name)
      Allows the collection to contain some, but not all, elements from a collection.
      Parameters:
      unwanted - the unwanted elements
      name - the name of the unwanted collection
      Returns:
      this
      Throws:
      NullPointerException - if the value or any of the arguments are null
      IllegalArgumentException - if:
      • name is empty
      • name contains whitespace
      • name is already in use by the value being validated or the validator context
      • the collection contains all the elements in unwanted
    • containsAll

      S containsAll(Collection<E> expected, String name)
      Ensures that the collection contains all the elements in expected.
      Parameters:
      expected - the desired elements
      name - the name of the expected collection
      Returns:
      this
      Throws:
      NullPointerException - if the value or any of the arguments are null
      IllegalArgumentException - if:
      • name is empty
      • name contains whitespace
      • name is already in use by the value being validated or the validator context
      • the collection does not contain all elements in expected
    • doesNotContainAll

      S doesNotContainAll(Collection<E> unwanted, String name)
      Allows the collection to contain some, but not all, elements from another collection.
      Parameters:
      unwanted - the unwanted elements
      name - the name of the unwanted collection
      Returns:
      this
      Throws:
      NullPointerException - if the value or any of the arguments are null
      IllegalArgumentException - if:
      • name is empty
      • name contains whitespace
      • name is already in use by the value being validated or the validator context
      • the collection contains all the elements in unwanted
    • doesNotContainDuplicates

      S doesNotContainDuplicates()
      Ensures that the collection does not contain any duplicate elements.
      Returns:
      this
      Throws:
      NullPointerException - if the value is null
      IllegalArgumentException - if the collection contains any duplicate elements
    • size

      Returns a validator for the collection's size.
      Returns:
      a validator for the collection's size
      Throws:
      NullPointerException - if the value is null