Class IterableOnly<E>

java.lang.Object
org.soliscode.test.interfaces.IterableOnly<E>
Type Parameters:
E - the element type.
All Implemented Interfaces:
Iterable<E>
Direct Known Subclasses:
CollectionOnly

public class IterableOnly<E> extends Object implements Iterable<E>
An iterable that is provided for tests that only implement the Iterable interface. If the code that is being tested tries to detect the kind of iterable to optimize the algorithm, it will be forced to use only the methods on iterable.
Since:
1.0
Author:
evanbergstrom
  • Field Details

  • Constructor Details

    • IterableOnly

      public IterableOnly()
      Creates an empty iterable.
    • IterableOnly

      public IterableOnly(Iterable<E> other)
      Creates a copy of an iterable.
      Parameters:
      other - the instance of IterableOnly to copy.
    • IterableOnly

      public IterableOnly(Collection<E> c)
      Creates an instance of IterableOnly from the collection provided.
      Parameters:
      c - The collection of elements.
  • 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()
      Specified by:
      iterator in interface Iterable<E>
    • spliterator

      public Spliterator<E> spliterator()
      Specified by:
      spliterator in interface Iterable<E>
    • of

      public static <E> Iterable<E> of()
      Creates an iterable from an empty collection of elements.
      Type Parameters:
      E - the element type.
      Returns:
      an iterable on an empty collection of elements.
    • of

      @SafeVarargs public static <E> Iterable<E> of(E... values)

      Creates an iterable from a list of one element.

         Iterable<Integer> iterable = IterableOnly.of(1, 2, 3, 4);
      
      Type Parameters:
      E - the element type.
      Parameters:
      values - the array of elements.
      Returns:
      an iterable containing the element.
      Throws:
      NullPointerException - if the array is null
    • of

      public static <E> Iterable<E> of(E e1)

      Creates an iterable from a list of one element.

         Iterable<Integer> iterable = IterableOnly.of(1);
      
      Type Parameters:
      E - the element type.
      Parameters:
      e1 - the first element.
      Returns:
      an iterable containing the specified elements.
      Throws:
      NullPointerException - if the array is null
    • of

      public static <E> Iterable<E> of(E e1, E e2)

      Creates an iterable from an list of two elements.

         Iterable<Integer> iterable = IterableOnly.of(1, 2);
      
      Type Parameters:
      E - the element type.
      Parameters:
      e1 - the first element.
      e2 - the second element.
      Returns:
      an iterable containing the specified elements.
      Throws:
      NullPointerException - if the array is null
    • of

      public static <E> Iterable<E> of(E e1, E e2, E e3)

      Creates an iterable from an list of three elements.

         Iterable<Integer> iterable = IterableOnly.of(1, 2, 3);
      
      Type Parameters:
      E - the element type.
      Parameters:
      e1 - the first element.
      e2 - the second element.
      e3 - the third element.
      Returns:
      an iterable containing the specified elements.
      Throws:
      NullPointerException - if the array is null
    • of

      public static <E> Iterable<E> of(E e1, E e2, E e3, E e4)

      Creates an iterable from a list of four elements.

         Iterable<Integer> iterable = IterableOnly.of(1, 2, 3, 4);
      
      Type Parameters:
      E - the element type.
      Parameters:
      e1 - the first element.
      e2 - the second element.
      e3 - the third element.
      e4 - the third element.
      Returns:
      an iterable containing the specified elements.
      Throws:
      NullPointerException - if the array is null