Class BreakableSequencedCollection<E>

Type Parameters:
E - The elements type for the SequencedCollection.
All Implemented Interfaces:
Iterable<E>, Collection<E>, SequencedCollection<E>, Breakable, SupportedMethods
Direct Known Subclasses:
BreakableList

public class BreakableSequencedCollection<E> extends BreakableCollection<E> implements SequencedCollection<E>

A sequenced collection that can be broken in well-defined ways in order to test collection utilities or testing classes.

Breaks

The breaks that are supported for this class are listed in the description of the method that they impact. In addition it supports the breaks in the BreakableIterable, BreakableIterator, BreakableSpliterator, and BreakableCollection classes. Any iterator or spliterator breaks that are added to this collection will be passes along to iterator or spliterator instances that are created.

Any breaks that are not listed in the supported classes can be added to an instance of BreakableSequencedCollection, but will not have any impact on how it functions.

Builder methods are provided to make declaring a broken sequenced collection easier, for example:

    BreakableSequencedCollection<Integer> broken = Breakables.buildSequencedCollection(1, 2)
        .withBreak(ADD_FIRST_ADDS_TO_END)
        .build();
Since:
1.0.0
Author:
evanbergstrom
See Also:
  • Field Details

    • ADD_FIRST_DOES_NOT_ADD_ELEMENT

      public static final Break ADD_FIRST_DOES_NOT_ADD_ELEMENT
      The addFirst method does not add an element.
      See Also:
    • ADD_FIRST_ADDS_TO_END

      public static final Break ADD_FIRST_ADDS_TO_END
      The addFirst method adds the element to the end of the collection.
      See Also:
    • ADD_LAST_DOES_NOT_ADD_ELEMENT

      public static final Break ADD_LAST_DOES_NOT_ADD_ELEMENT
      The addLast method does not add an element.
      See Also:
    • ADD_LAST_ADDS_TO_FRONT

      public static final Break ADD_LAST_ADDS_TO_FRONT
      The addLast method adds the element to the front of the collection.
      See Also:
    • GET_FIRST_RETURNS_NULL

      public static final Break GET_FIRST_RETURNS_NULL
      The getFirst method returns a null value.
      See Also:
    • GET_FIRST_ALWAYS_THROWS

      public static final Break GET_FIRST_ALWAYS_THROWS
      The getFirst method always throws a NoSuchElementException
      See Also:
    • GET_FIRST_SKIPS_FIRST_ELEMENT

      public static final Break GET_FIRST_SKIPS_FIRST_ELEMENT
      The getFirst method returns the second element.
      See Also:
    • GET_LAST_RETURNS_NULL

      public static final Break GET_LAST_RETURNS_NULL
      The getLast method returns a null value.
      See Also:
    • GET_LAST_ALWAYS_THROWS

      public static final Break GET_LAST_ALWAYS_THROWS
      The getLast method always throws a NoSuchElementException
      See Also:
    • GET_LAST_SKIPS_LAST_ELEMENT

      public static final Break GET_LAST_SKIPS_LAST_ELEMENT
      The getLast method returns the second element.
      See Also:
    • REMOVE_FIRST_DOES_NOT_REMOVE_ELEMENT

      public static final Break REMOVE_FIRST_DOES_NOT_REMOVE_ELEMENT
      The removeFirst method does not remove the first element.
      See Also:
    • REMOVE_FIRST_RETURNS_NULL

      public static final Break REMOVE_FIRST_RETURNS_NULL
      The removeFirst method returns null
      See Also:
    • REMOVE_FIRST_ALWAYS_THROWS

      public static final Break REMOVE_FIRST_ALWAYS_THROWS
      The removeFirst method always throws a NoSuchElement exception.
      See Also:
    • REMOVE_LAST_DOES_NOT_REMOVE_ELEMENT

      public static final Break REMOVE_LAST_DOES_NOT_REMOVE_ELEMENT
      The removeLast method does not remove the last element.
      See Also:
    • REMOVE_LAST_RETURNS_NULL

      public static final Break REMOVE_LAST_RETURNS_NULL
      The removeLast method returns null
      See Also:
    • REMOVE_LAST_ALWAYS_THROWS

      public static final Break REMOVE_LAST_ALWAYS_THROWS
      The removeLast method always throws a NoSuchElement exception.
      See Also:
    • REVERSED_DOES_NOT_REVERSE_COLLECTION

      public static final Break REVERSED_DOES_NOT_REVERSE_COLLECTION
      The reversed method does not reverse the collection.
      See Also:
    • REVERSED_MODIFIES_THE_COLLECTION

      public static final Break REVERSED_MODIFIES_THE_COLLECTION
      The reversed method modifies the collection.
      See Also:
  • Constructor Details

    • BreakableSequencedCollection

      public BreakableSequencedCollection()
      Creates an empty sequenced collection that has no breaks.
    • BreakableSequencedCollection

      public BreakableSequencedCollection(@NotNull @NotNull BreakableSequencedCollection<E> other)
      Creates a breakable sequenced collection from an existing instance.
      Parameters:
      other - the breakable collection to copy.
    • BreakableSequencedCollection

      public BreakableSequencedCollection(@NotNull @NotNull List<E> collection)
      Creates a breakable iterable from an iterable.
      Parameters:
      collection - the iterator to use for the elements.
    • BreakableSequencedCollection

      public BreakableSequencedCollection(@NotNull @NotNull List<E> c, @NotNull @NotNull Collection<Break> breaks, int characteristics)
      Creates a BreakableSequencedCollection from en existing collection and specifying the breaks and collection characteristics. Rather than calling this constructor directly, consider using the builder BreakableCollection.Builder.
      Parameters:
      c - the initial elements for the breakable collection.
      breaks - the breaks for the collection.
      characteristics - the characteristics for the collection.
      Throws:
      NullPointerException - if either the c or the breaks parameters are null.
  • Method Details

    • reversed

      public SequencedCollection<E> reversed()

      Implements the reversed method from the SequencedCollection interface. This method can be broken using the following collection breaks:

      • REVERSED_DOES_NOT_REVERSE_COLLECTION
      • REVERSED_MODIFIES_THE_COLLECTION

      A collection that has any of these breaks can be constructed using the builder:

          Collection<Integer> collection = Breakables.buildSequencedCollection(1,2,3,4,5)
              .withBreak(CollectionBreaks.REVERSED_DOES_NOT_REVERSE_COLLECTION)
              .build();
      
      Specified by:
      reversed in interface SequencedCollection<E>
      Returns:
      a collection with the elements in the reverse order.
      See Also:
    • addFirst

      public void addFirst(E e)

      Implements the addFirst method from the SequencedCollection interface. This method can be broken using the following collection breaks:

      • ADD_FIRST_DOES_NOT_ADD_ELEMENT
      • ADD_FIRST_ADDS_TO_END

      A collection that has any of these breaks can be constructed using the builder:

          Collection<Integer> collection = Breakables.buildSequencedCollection(1,2,3,4,5)
              .withBreak(CollectionBreaks.ADD_FIRST_DOES_NOT_ADD_ELEMENT)
              .build();
      
      Specified by:
      addFirst in interface SequencedCollection<E>
      Throws:
      UnsupportedOperationException - if this method is not supported
      NullPointerException - if the element is null and this collection does not permit null elements.
      See Also:
    • addLast

      public void addLast(E e)

      Implements the addLast method from the SequencedCollection interface. This method can be broken using the following collection breaks:

      • ADD_LAST_DOES_NOT_ADD_ELEMENT
      • ADD_LAST_ADDS_TO_FRONT

      A collection that has any of these breaks can be constructed using the builder:

          Collection<Integer> collection = Breakables.buildSequencedCollection(1,2,3,4,5)
              .withBreak(CollectionBreaks.ADD_LAST_DOES_NOT_ADD_ELEMENT)
              .build();
      
      Specified by:
      addLast in interface SequencedCollection<E>
      Throws:
      UnsupportedOperationException - if this method is not supported
      NullPointerException - if the element is null and this collection does not permit null elements.
      See Also:
    • getFirst

      public E getFirst()

      Implements the getFirst method from the SequencedCollection interface. This method can be broken using the following collection breaks:

      • GET_FIRST_RETURNS_NULL
      • GET_FIRST_ALWAYS_THROWS
      • GET_FIRST_SKIPS_FIRST_ELEMENT

      A collection that has any of these breaks can be constructed using the builder:

          Collection<Integer> collection = Breakables.buildSequencedCollection(1,2,3,4,5)
              .withBreak(CollectionBreaks.GET_FIRST_RETURNS_NULL)
              .build();
      
      Specified by:
      getFirst in interface SequencedCollection<E>
      Throws:
      UnsupportedOperationException - if this method is not supported
      NoSuchElementException - if this collection is empty
      See Also:
    • getLast

      public E getLast()

      Implements the getLast method from the SequencedCollection interface. This method can be broken using the following collection breaks:

      • GET_LAST_RETURNS_NULL
      • GET_LAST_ALWAYS_THROWS
      • GET_LAST_SKIPS_FIRST_ELEMENT

      A collection that has any of these breaks can be constructed using the builder:

          Collection<Integer> collection = Breakables.buildSequencedCollection(1,2,3,4,5)
              .withBreak(CollectionBreaks.GET_LAST_RETURNS_NULL)
              .build();
      
      Specified by:
      getLast in interface SequencedCollection<E>
      Throws:
      UnsupportedOperationException - if this method is not supported
      See Also:
    • removeFirst

      public E removeFirst()

      Implements the removeFirst method from the SequencedCollection interface. This method can be broken using the following collection breaks:

      • REMOVE_FIRST_DOES_NOT_REMOVE_ELEMENT
      • REMOVE_FIRST_RETURNS_NULL
      • REMOVE_FIRST_ALWAYS_THROWS

      A collection that has any of these breaks can be constructed using the builder:

          Collection<Integer> collection = Breakables.buildSequencedCollection(1,2,3,4,5)
              .withBreak(CollectionBreaks.REMOVE_FIRST_RETURNS_NULL)
              .build();
      
      Specified by:
      removeFirst in interface SequencedCollection<E>
      Throws:
      UnsupportedOperationException - if this method is not supported
      See Also:
    • removeLast

      public E removeLast()

      Implements the removeLast method from the SequencedCollection interface. This method can be broken using the following collection breaks:

      • REMOVE_LAST_DOES_NOT_REMOVE_ELEMENT
      • REMOVE_LAST_RETURNS_NULL
      • REMOVE_LAST_ALWAYS_THROWS

      A collection that has any of these breaks can be constructed using the builder:

          Collection<Integer> collection = Breakables.buildSequencedCollection(1,2,3,4,5)
              .withBreak(CollectionBreaks.REMOVE_LAST_RETURNS_NULL)
              .build();
      
      Specified by:
      removeLast in interface SequencedCollection<E>
      Throws:
      UnsupportedOperationException - if this method is not supported
      See Also: