Class BreakableIterable<E>

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

public class BreakableIterable<E> extends AbstractBreakable implements Iterable<E>

An iterable 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 BreakableIterator and BreakableSpliterator classes. Any iterator or spliterator breaks that are added to this iterable 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 BreakableIterable, but will not have any impact on how it functions.

Builder

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

    BreakableIterator<Integer> broken = Breakable.iterableOf(1, 2)
        .addBreak(FOR_EACH_DOES_NOT_CALL_ACTION)
        .setCharacteristics(ORDERED | SIZED | SUBSIZED)
        .build();
Since:
1.0
Author:
evanbergstrom
  • Field Details

    • DEFAULT_CAPACITY

      protected static final int DEFAULT_CAPACITY
      See Also:
    • FOR_EACH_DOES_NOT_CALL_ACTION

      public static final Break FOR_EACH_DOES_NOT_CALL_ACTION
      The method forEach does not call the action on any of the elements.
      See Also:
    • FOR_EACH_SKIPS_FIRST_ELEMENT

      public static final Break FOR_EACH_SKIPS_FIRST_ELEMENT
      The forEach method does not call the action on the first element.
      See Also:
    • FOR_EACH_SKIPS_LAST_ELEMENT

      public static final Break FOR_EACH_SKIPS_LAST_ELEMENT
      The method forEach does not call the action on the last element.
      See Also:
    • FOR_EACH_THROWS_WRONG_EXCEPTION_FOR_NULL_ARGUMENT

      public static final Break FOR_EACH_THROWS_WRONG_EXCEPTION_FOR_NULL_ARGUMENT
      The method forEach throws the wrong exception when passes a null action argument.
      See Also:
  • Constructor Details

    • BreakableIterable

      public BreakableIterable()
      Creates and empty breakable iterable with no breaks. The spliterator for this iterable will have no characteristics set.
    • BreakableIterable

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

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

      public BreakableIterable(@NotNull @NotNull Set<Break> breaks)
      Creates a breakable iterable with a set of breaks
      Parameters:
      breaks - the set of breaks to include.
    • BreakableIterable

      public BreakableIterable(@NotNull @NotNull Iterable<E> i, @NotNull @NotNull Collection<Break> breaks, int characteristics)
      Creates a breakable iterable from another iterable with a set of breaks and characteristics specified by the other arguments.
      Parameters:
      i - the iterable to use for the elements.
      breaks - the set of breaks to include.
      characteristics - the characteristics of the iterable.
  • Method Details

    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • iterator

      @NotNull public @NotNull Iterator<E> iterator()

      Implements the iterator method from the Iterable interface.

      #Breaks This method can be broken using any of the breaks found in the BreakableIterator class.

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

          Iterable<Integer> iterable = Breakable.iterableOf(1,2,3,4,5)
              .withBreak(BreakableIterator.ITERATOR_IS_ALWAYS_EMPTY)
              .build();
      
      Specified by:
      iterator in interface Iterable<E>
      Returns:
      An Iterator over the elements in this collection.
    • forEach

      public void forEach(Consumer<? super E> action)

      Implements the forEach method from the Iterable interface. This method can be broken using the following collection breaks:

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

          Collection<Integer> collection = Breakable.iterableOf(1,2,3,4,5)
              .withBreak(FOR_EACH_DOES_NOT_CALL_ACTION)
              .build();
      
      Specified by:
      forEach in interface Iterable<E>
      Parameters:
      action - The action to be performed for each element
      Throws:
      NullPointerException - if the specified action is null
    • spliterator

      public Spliterator<E> spliterator()

      Implements the iterator method from the Iterable interface. This method can be broken using the following collection breaks:

      #Breaks This method can be broken using any of the breaks found in the BreakableSpliterator class.

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

          Iterable<Integer> iterable = Breakable.iterableOf()
              .addElements(1,2,3,4,5)
              .withBreak(SPLITERATOR_IS_ALWAYS_EMPTY)
              .build();
      
      Specified by:
      spliterator in interface Iterable<E>
      Returns:
      a Spliterator over the elements in this collection.Ø
    • unbroken

      @NotNull public @NotNull Iterable<E> unbroken()
      returns the elements as an unbroken instance of `Iterable'
      Returns:
      an unbroken iterable.
    • iterableProvider

      @NotNull public static <E> @NotNull CollectionProvider<E,BreakableIterable<E>> iterableProvider(@NotNull @NotNull ObjectProvider<E> elementProvider)
    • iterableProvider

      @NotNull public static <E> @NotNull CollectionProvider<E,BreakableIterable<E>> iterableProvider(@NotNull @NotNull ObjectProvider<E> elementProvider, @NotNull @NotNull Set<Break> breaks)