E - The Element type.public class Cons<E> extends Object implements de.scravy.pair.Pair<E,Cons<E>>, Iterable<E>
| Constructor and Description |
|---|
Cons() |
| Modifier and Type | Method and Description |
|---|---|
Cons<E> |
cons(E head)
Prepend an element to this list.
|
static <E> Cons<E> |
cons(E head,
Cons<E> tail)
Create a list from an existing list and an element (push to the front of
the list, returns the new list).
|
static <E> Cons<E> |
empty()
The empty list.
|
static <E> Cons<E> |
fromArray(E... array)
Create a list from an existing array.
|
E |
get(int ix)
Retrieve the element at the given index.
|
E |
getFirst() |
int |
getLength()
Get the length of the list.
|
Cons<E> |
getSecond() |
boolean |
isEmpty()
Check whether this list is empty.
|
Iterator<E> |
iterator() |
static <E> Cons<E> |
singleton(E value)
Creates a list with one element.
|
<C extends Collection<E>> |
toCollection(C collection)
Add the contents of this list to the given collection.
|
List<E> |
toList()
Transform this list into a Collections list.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitforEach, spliteratorpublic static <E> Cons<E> singleton(E value)
E - The Element type.value - The one element.public static <E> Cons<E> empty()
E - The Element type.public static <E> Cons<E> cons(E head, Cons<E> tail)
O(1).E - The Element type.head - The head for the new list.tail - The tail for the new list (the list to prepend to).public Cons<E> cons(E head)
O(1).head - @SafeVarargs public static <E> Cons<E> fromArray(E... array)
E - The Element type.array - The array.public boolean isEmpty()
O(1).public int getLength()
O(n).public List<E> toList()
public <C extends Collection<E>> C toCollection(C collection)
C - The collection type.collection - The collection to add things to.public E get(int ix)
ix - The index.NoSuchElementException - Thrown if the list does not contain this many elements (iff
getLength() ≥ index).Copyright © 2015. All rights reserved.