Class ConsList<E>

  • Type Parameters:
    E - Element type
    All Implemented Interfaces:
    java.lang.Iterable<E>, java.util.Collection<E>, java.util.List<E>

    public class ConsList<E>
    extends AbstractImmutableList<E>
    List that consists of a head element and an immutable non-empty list.
    • Field Detail

      • first

        private final E first
      • rest

        private final java.util.List<E> rest
    • Constructor Detail

      • ConsList

        private ConsList​(E first,
                         java.util.List<E> rest)
    • Method Detail

      • of

        public static <E> java.util.List<E> of​(E first,
                                               java.util.List<? extends E> rest)
        Creates a ConsList. It consists of an element pre-pended to another list. If the other list is mutable, creates an immutable copy.
      • get

        public E get​(int index)
      • size

        public int size()
      • hashCode

        public int hashCode()
        Specified by:
        hashCode in interface java.util.Collection<E>
        Specified by:
        hashCode in interface java.util.List<E>
        Overrides:
        hashCode in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object o)
        Specified by:
        equals in interface java.util.Collection<E>
        Specified by:
        equals in interface java.util.List<E>
        Overrides:
        equals in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • listIterator

        @Nonnull
        public java.util.ListIterator<E> listIterator()
        Specified by:
        listIterator in interface java.util.List<E>
        Overrides:
        listIterator in class AbstractImmutableList<E>
      • iterator

        @Nonnull
        public java.util.Iterator<E> iterator()
        Specified by:
        iterator in interface java.util.Collection<E>
        Specified by:
        iterator in interface java.lang.Iterable<E>
        Specified by:
        iterator in interface java.util.List<E>
        Overrides:
        iterator in class AbstractImmutableList<E>
      • listIterator

        @Nonnull
        public java.util.ListIterator<E> listIterator​(int index)
        Specified by:
        listIterator in interface java.util.List<E>
        Overrides:
        listIterator in class AbstractImmutableList<E>
      • toArray

        @Nonnull
        public java.lang.Object[] toArray()
      • toArray

        @Nonnull
        public <T> T[] toArray​(@Nonnull
                               T[] a)
      • indexOf

        public int indexOf​(java.lang.Object o)
      • lastIndexOf

        public int lastIndexOf​(java.lang.Object o)