Package com.strobel.collections
Class ImmutableList<A>
java.lang.Object
java.util.AbstractCollection<A>
com.strobel.collections.ImmutableList<A>
- All Implemented Interfaces:
Iterable<A>
,Collection<A>
,List<A>
,SequencedCollection<A>
A class for generic linked lists. Links are supposed to be
immutable, the only exception being the incremental construction of
lists via ListBuffers. List is the main container class in
GJC. Most data structures and algorithms in GJC use lists rather
than arrays.
Lists are always trailed by a sentinel element, whose head and tail are both null.
This is NOT part of any supported API. If you write code that depends on this, you do so at your own risk. This code and its internal interfaces are subject to change or deletion without notice.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Iterator
<?> private static final ImmutableList
<?> The first element of the list, supposed to be immutable.The remainder of the list except for its first element, supposed to be immutable. -
Constructor Summary
ConstructorsConstructorDescriptionImmutableList
(A head, ImmutableList<A> tail) Construct a list given its head and tail. -
Method Summary
Modifier and TypeMethodDescriptionvoid
boolean
addAll
(int index, Collection<? extends A> c) Append given element at length, forming and returning a new list.appendList
(ImmutableList<A> x) Append given list at length, forming and returning a new list.appendList
(ListBuffer<A> x) Append given list buffer at length, forming and returning a new list.boolean
Does the list contain the specified element?static <T> ImmutableList
<T> convert
(Class<T> type, ImmutableList<?> list) static <A> ImmutableList
<A> empty()
Construct an empty list.private static <A> Iterator
<A> static boolean
equals
(ImmutableList<?> xs, ImmutableList<?> ys) Are the two lists the same?boolean
Is this list the same as other list?static <A> ImmutableList
<A> fill
(int len, A init) Deprecated.static <A> ImmutableList
<A> from
(A[] array) Construct a list consisting all elements of given array.get
(int index) int
hashCode()
Compute a hash code, overrides Objectint
boolean
isEmpty()
Does list have no elements?iterator()
last()
The last element in the list, if any, or null.int
int
length()
Return the number of elements in this list.listIterator
(int index) boolean
nonEmpty()
Does list have elements?static <A> ImmutableList
<A> of
(A x1) Construct a list consisting of given element.static <A> ImmutableList
<A> of
(A x1, A x2) Construct a list consisting of given elements.static <A> ImmutableList
<A> of
(A x1, A... rest) Construct a list consisting of given elements.static <A> ImmutableList
<A> of
(A x1, A x2, A x3) Construct a list consisting of given elements.static <A> ImmutableList
<A> of
(A x1, A x2, A x3, A... rest) Construct a list consisting of given elements.Prepend given element to front of list, forming and returning a new list.prependList
(ImmutableList<A> xs) Prepend given list of elements to front of list, forming and returning a new list.remove
(int index) reverse()
Reverse list.setTail
(ImmutableList<A> tail) int
size()
subList
(int fromIndex, int toIndex) Object[]
toArray()
<T> T[]
toArray
(T[] vec) Copy successive elements of this list into given vector until list is exhausted or end of vector is reached.toString()
Form a string listing all elements with comma as the separator character.Form a string listing all elements with given separator character.Methods inherited from class java.util.AbstractCollection
add, addAll, clear, containsAll, remove, removeAll, retainAll
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
Methods inherited from interface java.util.List
add, addAll, addFirst, addLast, clear, containsAll, getFirst, getLast, remove, removeAll, removeFirst, removeLast, replaceAll, retainAll, reversed, sort, spliterator
-
Field Details
-
head
The first element of the list, supposed to be immutable. -
tail
The remainder of the list except for its first element, supposed to be immutable. -
EMPTY_LIST
-
EMPTY_ITERATOR
-
-
Constructor Details
-
ImmutableList
ImmutableList(A head, ImmutableList<A> tail) Construct a list given its head and tail.
-
-
Method Details
-
empty
Construct an empty list. -
of
Construct a list consisting of given element. -
of
Construct a list consisting of given elements. -
of
Construct a list consisting of given elements. -
of
Construct a list consisting of given elements. -
of
Construct a list consisting of given elements. -
from
Construct a list consisting all elements of given array.- Parameters:
array
- an array; ifnull
return an empty list
-
fill
Deprecated.Construct a list consisting of a given number of identical elements.- Parameters:
len
- The number of elements in the list.init
- The value of each element.
-
isEmpty
public boolean isEmpty()Does list have no elements?- Specified by:
isEmpty
in interfaceCollection<A>
- Specified by:
isEmpty
in interfaceList<A>
- Overrides:
isEmpty
in classAbstractCollection<A>
-
nonEmpty
public boolean nonEmpty()Does list have elements? -
length
public int length()Return the number of elements in this list. -
size
public int size()- Specified by:
size
in interfaceCollection<A>
- Specified by:
size
in interfaceList<A>
- Specified by:
size
in classAbstractCollection<A>
-
setTail
-
prepend
Prepend given element to front of list, forming and returning a new list. -
prependList
Prepend given list of elements to front of list, forming and returning a new list. -
reverse
Reverse list. If the list is empty or a singleton, then the same list is returned. Otherwise a new list is formed. -
append
Append given element at length, forming and returning a new list. -
appendList
Append given list at length, forming and returning a new list. -
appendList
Append given list buffer at length, forming and returning a new list. -
toArray
Copy successive elements of this list into given vector until list is exhausted or end of vector is reached.- Specified by:
toArray
in interfaceCollection<A>
- Specified by:
toArray
in interfaceList<A>
- Overrides:
toArray
in classAbstractCollection<A>
-
toArray
- Specified by:
toArray
in interfaceCollection<A>
- Specified by:
toArray
in interfaceList<A>
- Overrides:
toArray
in classAbstractCollection<A>
-
toString
Form a string listing all elements with given separator character. -
toString
Form a string listing all elements with comma as the separator character.- Overrides:
toString
in classAbstractCollection<A>
-
hashCode
public int hashCode()Compute a hash code, overrides Object -
equals
Is this list the same as other list? -
equals
Are the two lists the same? -
contains
Does the list contain the specified element?- Specified by:
contains
in interfaceCollection<A>
- Specified by:
contains
in interfaceList<A>
- Overrides:
contains
in classAbstractCollection<A>
-
last
The last element in the list, if any, or null. -
convert
-
emptyIterator
-
iterator
-
get
-
addAll
-
set
-
add
-
remove
-
indexOf
-
lastIndexOf
- Specified by:
lastIndexOf
in interfaceList<A>
-
listIterator
- Specified by:
listIterator
in interfaceList<A>
-
listIterator
- Specified by:
listIterator
in interfaceList<A>
-
subList
-