Package org.atlanmod.commons.collect
Class MoreIterators
- java.lang.Object
-
- org.atlanmod.commons.collect.MoreIterators
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <E> Optional<E>firstElement(Iterator<E> iterator)Returns the first element contained initerator.static booleanisEmpty(Iterator<?> iterator)Determines if the giveniteratorcontains no element.static booleannotEmpty(Iterator<?> iterator)Determines if the giveniteratorcontains at least one element.static <E> Optional<E>onlyElement(Iterator<E> iterator)Returns the single element contained initerator.
-
-
-
Method Detail
-
isEmpty
public static boolean isEmpty(Iterator<?> iterator)
Determines if the giveniteratorcontains no element.- Parameters:
iterator- the iterator- Returns:
trueif the iterator contains no element
-
notEmpty
public static boolean notEmpty(Iterator<?> iterator)
Determines if the giveniteratorcontains at least one element.- Parameters:
iterator- the iterator- Returns:
trueif the iterator contains at least one element
-
onlyElement
@Nonnull public static <E> Optional<E> onlyElement(Iterator<E> iterator)
Returns the single element contained initerator.- Parameters:
iterator- the iterator- Returns:
- an
Optionalcontaining the single element of theiterator, orOptional.empty()if theiteratoris empty. - Throws:
IllegalArgumentException- if theiteratorcontains more than one element
-
firstElement
@Nonnull public static <E> Optional<E> firstElement(Iterator<E> iterator)
Returns the first element contained initerator.- Parameters:
iterator- the iterator- Returns:
- an
Optionalcontaining the first element of theiterator, orOptional.empty()if theiteratoris empty.
-
-