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 TypeMethodDescriptionvoidbooleanaddAll(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.booleanDoes 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 booleanequals(ImmutableList<?> xs, ImmutableList<?> ys) Are the two lists the same?booleanIs 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) inthashCode()Compute a hash code, overrides ObjectintbooleanisEmpty()Does list have no elements?iterator()last()The last element in the list, if any, or null.intintlength()Return the number of elements in this list.listIterator(int index) booleannonEmpty()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) intsize()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 AbstractCollection
add, addAll, clear, containsAll, remove, removeAll, retainAllMethods inherited from interface Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface 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; ifnullreturn 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:
isEmptyin interfaceCollection<A>- Specified by:
isEmptyin interfaceList<A>- Overrides:
isEmptyin 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:
sizein interfaceCollection<A>- Specified by:
sizein interfaceList<A>- Specified by:
sizein 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:
toArrayin interfaceCollection<A>- Specified by:
toArrayin interfaceList<A>- Overrides:
toArrayin classAbstractCollection<A>
-
toArray
-
toString
-
toString
Form a string listing all elements with comma as the separator character.- Overrides:
toStringin classAbstractCollection<A>
-
hashCode
-
equals
-
equals
Are the two lists the same? -
contains
Does the list contain the specified element?- Specified by:
containsin interfaceCollection<A>- Specified by:
containsin interfaceList<A>- Overrides:
containsin 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:
lastIndexOfin interfaceList<A>
-
listIterator
- Specified by:
listIteratorin interfaceList<A>
-
listIterator
- Specified by:
listIteratorin interfaceList<A>
-
subList
-