Class IterableTestOps
java.lang.Object
org.soliscode.test.util.IterableTestOps
This class consists exclusively of static methods that operate on or return iterables.
The methods of this class all throw a NullPointerException
if the iterables or class objects provided to
them are null
.
- Since:
- 1.0.0
- Author:
- evanbergstrom
-
Method Summary
Modifier and TypeMethodDescriptionstatic <E> @NotNull Collection
<E> asCollection
(@NotNull Iterable<E> i) Converts the iterable to a collection.static <E> @NotNull List
<E> Converts the iterable to a list.static <E> @NotNull Set
<E> Converts the iterable to a set.static boolean
Returnstrue
if this iterable contains the specified element.static boolean
containsByIdentity
(Iterable<?> i, Object o) Returnstrue
if this iterable contains the specified element.static <E> @NotNull Iterable
<E> Creates a copy of an iterable.static <E> Iterable
<E> Creates a copy of an the first N elements of an iterable.static <E> Iterable
<E> empty()
Returns an empty iterable.static boolean
static boolean
Returnstrue
if the iterable contains no elements.static <E> List
<E> Creates a copy of an iterable and returns it as aList
.static int
Returns the number of elements in this iterable.static <E> Iterator
<E> skipFirstIterator
(@NotNull Iterable<E> iterable) Returns an iterator that will skips the first element.static <E> Iterator
<E> skipLastIterator
(@NotNull Iterable<E> iterable) Returns an iterator that will skips the last element.
-
Method Details
-
isEmpty
Returnstrue
if the iterable contains no elements.- Parameters:
i
- The iterable.- Returns:
true
if the iterable contains no elements,false
otherwise.
-
size
Returns the number of elements in this iterable. If this iterable contains more thanInteger.MAX_VALUE
elements, returnsInteger.MAX_VALUE
.- Parameters:
i
- The iterable.- Returns:
- the number of elements in this iterable.
-
contains
Returnstrue
if this iterable contains the specified element. Returnstrue
if and only if this iterable contains at least one elemente
such thatObjects.equals(o, e)
.- Parameters:
i
- The iterable.o
- element whose presence in this iterable is to be tested- Returns:
true
if this iterable contains the specified element,false
otherwise.- Throws:
ClassCastException
- if the type of the specified element is incompatible with this collectionNullPointerException
- if the specified element is null and this iterable does not permit null elements
-
containsByIdentity
Returnstrue
if this iterable contains the specified element. Returnstrue
if and only if this iterable contains this element by identity.- Parameters:
i
- The iterable.o
- element whose presence in this iterable is to be tested- Returns:
true
if this iterable contains the specified element,false
otherwise.- Throws:
ClassCastException
- if the type of the specified element is incompatible with this collectionNullPointerException
- if the specified element is null and this iterable does not permit null elements
-
empty
Returns an empty iterable.- Type Parameters:
E
- the element type.- Returns:
- an empty iterable.
-
equals
-
asCollection
Converts the iterable to a collection.- Type Parameters:
E
- the type of the element.- Parameters:
i
- the iterable to convert.- Returns:
- a collection with the same elements as the iterable.
-
asList
Converts the iterable to a list. This method will create a new list as the return value, even if the argument is already a instance ofList
.- Type Parameters:
E
- the type of the element.- Parameters:
i
- the iterable to convert.- Returns:
- a list with the same elements as the iterable.
-
asSet
Converts the iterable to a set. This method will create a new set as the return value, even if the argument is already a instance ofSet
.- Type Parameters:
E
- the type of the element.- Parameters:
i
- the iterable to convert.- Returns:
- a set with the same elements as the iterable.
-
copy
Creates a copy of an iterable. The returned copy weill have the same elements as the original but may have a different implementation.- Type Parameters:
E
- the type of the elements.- Parameters:
iterable
- the iterable to copy.- Returns:
- a copy of the original iterable.
-
copyFirst
-
newList
-
skipFirstIterator
-
skipLastIterator
-