Class Cons<E>

All Implemented Interfaces:
Iterable<E>, LinkedList<E>, List<E>, Traversable<E>, Iterable<E>

class Cons<E> extends ConsList<E>
Cons constructs a new list by prepending a new element to an existing list
  • Field Details

    • tail

      private ConsList<E> tail
  • Constructor Details

  • Method Details

    • isEmpty

      public boolean isEmpty()
      Description copied from interface: Traversable
      Returns true if this collection is empty.
      Specified by:
      isEmpty in interface Traversable<E>
      Overrides:
      isEmpty in class AbstractTraversable<E>
    • first

      @Nullable public E first()
      Description copied from interface: List
      Returns first element in the list or null if the list is empty.
    • tail

      @NotNull public @NotNull ConsList<E> tail()
      Description copied from interface: List
      Returns a list containing all elements in the list, excluding the first element. An empty list is returned if the list is empty.
      Specified by:
      tail in interface LinkedList<E>
      Specified by:
      tail in interface List<E>
      Specified by:
      tail in class ConsList<E>
    • set

      @NotNull public @NotNull ConsList<E> set(int i, E elem)
      Description copied from interface: List
      Returns a list with the element set to the value specified at the index (zero-based).
      Specified by:
      set in interface LinkedList<E>
      Specified by:
      set in interface List<E>
      Specified by:
      set in class ConsList<E>
    • append

      @NotNull public @NotNull ConsList<E> append(E elem)
      Description copied from interface: List
      Returns a list with the specified element appended to the bottom of the list.
      Specified by:
      append in interface LinkedList<E>
      Specified by:
      append in interface List<E>
      Specified by:
      append in class ConsList<E>
    • drop

      @NotNull public @NotNull ConsList<E> drop(int number)
      Description copied from interface: List
      Returns a list containing all elements in this list, excluding the first number of elements.
      Specified by:
      drop in interface LinkedList<E>
      Specified by:
      drop in interface List<E>
      Specified by:
      drop in class ConsList<E>
    • take

      @NotNull public @NotNull ConsList<E> take(int number)
      Description copied from interface: List
      Returns a list containing the first number of elements from this list.
      Specified by:
      take in interface LinkedList<E>
      Specified by:
      take in interface List<E>
      Specified by:
      take in class ConsList<E>
    • range

      @NotNull public @NotNull ConsList<E> range(int from, boolean fromInclusive, int to, boolean toInclusive)
      Description copied from interface: List
      Returns a list containing a contiguous range of elements from this list.
      Specified by:
      range in interface LinkedList<E>
      Specified by:
      range in interface List<E>
      Specified by:
      range in class ConsList<E>
      Parameters:
      from - starting index for the range (zero-based)
      fromInclusive - if true, the element at the from index will be included
      to - end index for the range (zero-based)
      toInclusive - if true, the element at the to index will be included
    • get

      public E get(int i)
      Description copied from interface: List
      Returns the element at the specified index in this list (zero-based).
    • last

      @Nullable public E last()
      Description copied from interface: List
      Returns last element in the list or null if the list is empty.