Package org.pgpainless.util
Class NonEmptyList<E>
- java.lang.Object
-
- org.pgpainless.util.NonEmptyList<E>
-
- Type Parameters:
E
- element type
public class NonEmptyList<E> extends java.lang.Object
Utility class of an immutable list which cannot be empty. The first element can be accessed viaget()
which is guaranteed to return a non-null value. The rest of the list can be accessed viagetOthers()
, which is guaranteed to return a non-null list which is possibly empty. Lastly, the whole list can be accessed viagetAll()
, which is guaranteed to return a non-empty list.
-
-
Constructor Summary
Constructors Constructor Description NonEmptyList(E element)
Create a singleton list from the given element.NonEmptyList(java.util.List<E> elements)
Create a non-empty list from the given list of elements.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description E
get()
Return the first element of the list.java.util.List<E>
getAll()
Return a non-empty list of all elements of this list.java.util.List<E>
getOthers()
Return a list of all elements of the list except the first.
-
-
-
Constructor Detail
-
NonEmptyList
public NonEmptyList(E element)
Create a singleton list from the given element.- Parameters:
element
- element
-
NonEmptyList
public NonEmptyList(java.util.List<E> elements)
Create a non-empty list from the given list of elements.- Parameters:
elements
- elements- Throws:
java.lang.IllegalArgumentException
- if the provided list of elements is empty.
-
-
Method Detail
-
get
@Nonnull public E get()
Return the first element of the list.- Returns:
- first
-
getOthers
@Nonnull public java.util.List<E> getOthers()
Return a list of all elements of the list except the first.- Returns:
- list of all but the first element
-
getAll
public java.util.List<E> getAll()
Return a non-empty list of all elements of this list.- Returns:
- all elements
-
-