Package com.complexible.common.collect
Class NestedList<T>
- java.lang.Object
-
- com.complexible.common.collect.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 thebegin
elements andend
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 thebegin
elements andend
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()
-
-
-
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 benil()
.
-
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 thebegin
elements andend
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 thebegin
elements andend
elements in iteration order.
-
first
public T first()
-
rest
public NestedList<T> rest()
-
isNil
public boolean isNil()
-
size
public int size()
-
iterator
public java.util.Iterator<T> iterator()
- Specified by:
iterator
in interfacejava.lang.Iterable<T>
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-