Class NestedList<T>

  • All Implemented Interfaces:
    java.lang.Iterable<T>

    public class NestedList<T>
    extends java.lang.Object
    implements java.lang.Iterable<T>
    An immutable linked list object with structure sharing.
    Since:
    0.7
    Version:
    0.7
    Author:
    Evren Sirin
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static <T> NestedList<T> concat​(java.lang.Iterable<T> begin, NestedList<T> end)
      Returns a list that will be the concatenation of the begin elements and end elements in iteration order.
      static <T> NestedList<T> concat​(java.util.Iterator<T> begin, NestedList<T> end)
      Returns a list that will be the concatenation of the begin elements and end elements in iteration order.
      static <T> NestedList<T> create​(T first, NestedList<T> rest)
      Returns a list with the given first element and the rest list.
      T first()  
      boolean isNil()  
      java.util.Iterator<T> iterator()  
      static <T> NestedList<T> nil()
      Returns the nil (empty) list.
      NestedList<T> rest()  
      static <T> NestedList<T> singleton​(T element)
      Returns a list with a single element.
      int size()  
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.lang.Iterable

        forEach, spliterator
    • Method Detail

      • nil

        public static <T> NestedList<T> nil()
        Returns the nil (empty) list.
      • singleton

        public static <T> NestedList<T> singleton​(T element)
        Returns a list with a single element. The returned list's rest will be nil().
      • create

        public static <T> NestedList<T> create​(T first,
                                               NestedList<T> rest)
        Returns a list with the given first element and the rest list.
      • concat

        public static <T> NestedList<T> concat​(java.lang.Iterable<T> begin,
                                               NestedList<T> end)
        Returns a list that will be the concatenation of the begin elements and end elements in iteration order.
      • concat

        public static <T> NestedList<T> concat​(java.util.Iterator<T> begin,
                                               NestedList<T> end)
        Returns a list that will be the concatenation of the begin elements and end elements in iteration order.
      • first

        public T first()
      • isNil

        public boolean isNil()
      • size

        public int size()
      • iterator

        public java.util.Iterator<T> iterator()
        Specified by:
        iterator in interface java.lang.Iterable<T>
      • toString

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