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 |
---|
Cons(S element)
new list with only one element
|
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(java.lang.Object o) |
boolean |
exists(java.util.function.Predicate<S> predicate)
return true if predicate is fullfilled for at least one element
|
int |
hashCode()
hashcode for collections, implemented similar (just reverse) algorithm as
java.util.Collections use
|
S |
head() |
boolean |
isEmpty() |
java.util.Iterator<S> |
iterator() |
ImmutableList<S> |
prepend(ImmutableList<S> list)
prepends list (O(n)+O(m))
|
ImmutableList<S> |
prepend(S e)
creates a new list with element as head and the
momentan list as tail (O(1))
|
ImmutableList<S> |
prependReverse(ImmutableList<S> list)
prepends list (O(n)+O(m)) in reversed order
|
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() |
java.lang.String |
toString() |
append, nil, prepend, prepend, prependReverse, reverse, take, toArray, toArray
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
stream
private static final long serialVersionUID
private final S element
private final ImmutableSLList<S> cons
private final int size
Cons(S element)
element
- the only element in listCons(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> prependReverse(ImmutableList<S> list)
list
- the IListpublic boolean exists(java.util.function.Predicate<S> predicate)
predicate
- the predicatepublic 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()
hashCode
in class java.lang.Object
public java.util.Iterator<S> iterator()
public int size()
public boolean contains(S obj)
public boolean isEmpty()
public ImmutableList<S> removeFirst(S obj)
public ImmutableList<S> removeAll(S obj)
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object