private static class ImmutableSLList.Cons<S> extends ImmutableSLList<S>
Modifier and Type | Field and Description |
---|---|
private ImmutableSLList<S> |
cons
reference to the next element (equiv.to the tail of list)
|
private S |
element
the first element
|
private static long |
serialVersionUID |
private int |
size
size of the list
|
Constructor and Description |
---|
ImmutableSLList.Cons(S element)
new list with only one element
|
ImmutableSLList.Cons(S element,
ImmutableSLList<S> cons)
constructs a new list with element as head and cons as tail
|
Modifier and Type | Method and Description |
---|---|
ImmutableList<S> |
append(ImmutableList<S> list)
appends element at end (non-destructive) (O(n))
|
ImmutableList<S> |
append(S... array)
appends element at end (non-destructive) (O(n))
|
ImmutableList<S> |
append(S e)
appends element at end (non-destructive) (O(n))
|
boolean |
contains(S obj) |
boolean |
equals(Object o) |
int |
hashCode()
hashcode for collections, implemented similar (just reverse) algorithm as
java.util.Collections use
|
S |
head() |
boolean |
isEmpty() |
Iterator<S> |
iterator() |
ImmutableList<S> |
prepend(ImmutableList<S> list)
prepends list (O(n))
|
ImmutableList<S> |
prepend(S e)
creates a new list with element as head and the
momentan list as tail (O(1))
|
ImmutableList<S> |
removeAll(S obj)
removes all occurrences of obj (O(n))
|
ImmutableList<S> |
removeFirst(S obj)
removes first occurrences of obj (O(n))
|
int |
size() |
ImmutableList<S> |
tail() |
String |
toString() |
private static final long serialVersionUID
private final S element
private final ImmutableSLList<S> cons
private final int size
ImmutableSLList.Cons(S element)
element
- the only element in listImmutableSLList.Cons(S element, ImmutableSLList<S> cons)
element
- a cons
- tail of the listpublic ImmutableList<S> prepend(S e)
e
- the public ImmutableList<S> prepend(ImmutableList<S> list)
list
- the IListpublic ImmutableList<S> append(S e)
e
- the public ImmutableList<S> append(ImmutableList<S> list)
list
- the IListpublic ImmutableList<S> append(S... array)
array
- the array to be appendedpublic S head()
public ImmutableList<S> tail()
public int hashCode()
public int size()
public boolean contains(S obj)
public boolean isEmpty()
public ImmutableList<S> removeFirst(S obj)
public ImmutableList<S> removeAll(S obj)