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>
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
-
Field Summary
Fields inherited from class org.soliscode.test.interfaces.IterableOnly
iterable
-
Constructor Summary
ConstructorsConstructorDescriptionCreates an empty collection.Creates an instance ofCollectionOnly
from the collection provided.CollectionOnly
(CollectionOnly<E> other) Creates a copy of a collection. -
Method Summary
Modifier and TypeMethodDescriptionboolean
boolean
addAll
(@NotNull Collection<? extends E> c) void
clear()
boolean
boolean
containsAll
(@NotNull Collection<?> c) boolean
int
hashCode()
boolean
isEmpty()
static <E> Collection
<E> of()
Creates a collection from an empty collection of elements.static <E> Collection
<E> of
(E e1) Creates a collection from a list of one element.static <E> Collection
<E> of
(E... values) Creates a collection from a list of one element.static <E> Collection
<E> of
(E e1, E e2) Creates a collection from an list of two elements.static <E> Collection
<E> of
(E e1, E e2, E e3) Creates a collection from an list of three elements.static <E> Collection
<E> of
(E e1, E e2, E e3, E e4) Creates a collection from a list of four elements.boolean
boolean
removeAll
(@NotNull Collection<?> c) boolean
retainAll
(@NotNull Collection<?> c) int
size()
@NotNull Object @NotNull []
toArray()
<T> T @NotNull []
toArray
(T @NotNull [] a) toString()
Methods inherited from class org.soliscode.test.interfaces.IterableOnly
iterator, spliterator
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Collection
iterator, parallelStream, removeIf, spliterator, stream, toArray
-
Constructor Details
-
CollectionOnly
public CollectionOnly()Creates an empty collection. -
CollectionOnly
Creates a copy of a collection.- Parameters:
other
- the instance ofCollection
to copy.
-
CollectionOnly
Creates an instance ofCollectionOnly
from the collection provided.- Parameters:
c
- The collection of elements.
-
-
Method Details
-
size
public int size()- Specified by:
size
in interfaceCollection<E>
-
isEmpty
public boolean isEmpty()- Specified by:
isEmpty
in interfaceCollection<E>
-
contains
- Specified by:
contains
in interfaceCollection<E>
-
toArray
- Specified by:
toArray
in interfaceCollection<E>
-
toArray
@NotNull public <T> T @NotNull [] toArray(@NotNull T @NotNull [] a) - Specified by:
toArray
in interfaceCollection<E>
-
add
- Specified by:
add
in interfaceCollection<E>
-
remove
- Specified by:
remove
in interfaceCollection<E>
-
containsAll
- Specified by:
containsAll
in interfaceCollection<E>
-
addAll
- Specified by:
addAll
in interfaceCollection<E>
-
removeAll
- Specified by:
removeAll
in interfaceCollection<E>
-
retainAll
- Specified by:
retainAll
in interfaceCollection<E>
-
clear
public void clear()- Specified by:
clear
in interfaceCollection<E>
-
equals
- Specified by:
equals
in interfaceCollection<E>
- Overrides:
equals
in classIterableOnly<E>
-
hashCode
public int hashCode()- Specified by:
hashCode
in interfaceCollection<E>
- Overrides:
hashCode
in classIterableOnly<E>
-
toString
- Overrides:
toString
in classIterableOnly<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
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 isnull
-
of
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 isnull
-
of
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 isnull
-
of
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 isnull
-
of
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 isnull
-