Class CollectionOnly<E>

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

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

    • CollectionOnly

      public CollectionOnly()
      Creates an empty collection.
    • CollectionOnly

      public CollectionOnly(CollectionOnly<E> other)
      Creates a copy of a collection.
      Parameters:
      other - the instance of Collection to copy.
    • CollectionOnly

      public CollectionOnly(Collection<E> c)
      Creates an instance of CollectionOnly from the collection provided.
      Parameters:
      c - The collection of elements.
  • Method Details

    • size

      public int size()
      Specified by:
      size in interface Collection<E>
    • isEmpty

      public boolean isEmpty()
      Specified by:
      isEmpty in interface Collection<E>
    • contains

      public boolean contains(Object o)
      Specified by:
      contains in interface Collection<E>
    • toArray

      @NotNull public @NotNull Object @NotNull [] toArray()
      Specified by:
      toArray in interface Collection<E>
    • toArray

      @NotNull public <T> T @NotNull [] toArray(@NotNull T @NotNull [] a)
      Specified by:
      toArray in interface Collection<E>
    • add

      public boolean add(E e)
      Specified by:
      add in interface Collection<E>
    • remove

      public boolean remove(Object o)
      Specified by:
      remove in interface Collection<E>
    • containsAll

      public boolean containsAll(@NotNull @NotNull Collection<?> c)
      Specified by:
      containsAll in interface Collection<E>
    • addAll

      public boolean addAll(@NotNull @NotNull Collection<? extends E> c)
      Specified by:
      addAll in interface Collection<E>
    • removeAll

      public boolean removeAll(@NotNull @NotNull Collection<?> c)
      Specified by:
      removeAll in interface Collection<E>
    • retainAll

      public boolean retainAll(@NotNull @NotNull Collection<?> c)
      Specified by:
      retainAll in interface Collection<E>
    • clear

      public void clear()
      Specified by:
      clear in interface Collection<E>
    • equals

      public boolean equals(Object obj)
      Specified by:
      equals in interface Collection<E>
      Overrides:
      equals in class IterableOnly<E>
    • hashCode

      public int hashCode()
      Specified by:
      hashCode in interface Collection<E>
      Overrides:
      hashCode in class IterableOnly<E>
    • toString

      public String toString()
      Overrides:
      toString in class IterableOnly<E>
    • of

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

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

      Creates a collection from a list of one element.

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

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

      Creates a collection from a list of one element.

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

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

      Creates a collection from an list of two elements.

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

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

      Creates a collection from an list of three elements.

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

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

      Creates a collection from a list of four elements.

         Collection<Integer> iterable = CollectionOnly.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:
      a collection containing the specified elements.
      Throws:
      NullPointerException - if the array is null