Class 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 via get() which is guaranteed to return a non-null value. The rest of the list can be accessed via getOthers(), which is guaranteed to return a non-null list which is possibly empty. Lastly, the whole list can be accessed via getAll(), 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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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