APIdia Launch Partner
Top Description Fields Constructors Methods
com.sun.tools.javac.util

public Class List<A>

extends AbstractCollection<A>
implements List<A>
Class Inheritance
All Implemented Interfaces
java.util.List, java.util.SequencedCollection, java.util.Collection, java.lang.Iterable
Imports
java.lang.reflect.Array, java.util.ArrayList, .Collection, .Collections, .Iterator, .AbstractCollection, .ListIterator, .NoSuchElementException, java.util.function.Function, java.util.stream.Collector

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

Modifier and TypeField and Description
private static final List<?>
public A
head

The first element of the list, supposed to be immutable.

public List<A>
tail

The remainder of the list except for its first element, supposed to be immutable.

Constructor Summary

AccessConstructor and Description
pack-priv
List(A head, List<A> tail)

Construct a list given its head and tail.

Method Summary

Modifier and TypeMethod and Description
public void
add(int index, A element)

Implements java.util.List.add.

Inserts the specified element at the specified position in this list (optional operation).

public boolean
addAll(int index, Collection<? extends A> c)

Implements java.util.List.addAll.

Inserts all of the elements in the specified collection into this list at the specified position (optional operation).

public List<A>
append(A x)

Append given element at length, forming and returning a new list.

public List<A>
appendList(List<A> x)

Append given list at length, forming and returning a new list.

public List<A>
appendList(ListBuffer<A> x)

Append given list buffer at length, forming and returning a new list.

public static <Z> Collector<Z, ListBuffer<Z>, List<Z>>
collector()

Collect elements into a new list (using a ListBuffer)

public boolean
contains(Object x)

Overrides java.util.AbstractCollection.contains.

Implements java.util.List.contains, java.util.Collection.contains.

Does the list contain the specified element?

public static <T> List<T>
convert(Class<T> klass, List<?> list)

public List<A>
diff(List<A> that)

public boolean
equals(Object other)

Overrides java.lang.Object.equals.

Implements java.util.List.equals, java.util.Collection.equals.

Is this list the same as other list?

public static boolean
equals(List<?> xs, List<?> ys)

Are the two lists the same?

public static <A> List<A>
fill(int
The number of elements in the list.
len
,
A
The value of each element.
init
)
Deprecated

Construct a list consisting of a given number of identical elements.

public static <A> List<A>
filter(List<A> l, A elem)

Returns the list obtained from 'l' after removing all elements 'elem'

public static <A> List<A>
from(A[]
an array; if null return an empty list
array
)

Construct a list consisting all elements of given array.

public static <A> List<A>
from(Iterable<? extends A> coll)

public A
get(int index)

Implements java.util.List.get.

Returns the element at the specified position in this list.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Implements java.util.List.hashCode, java.util.Collection.hashCode.

Compute a hash code, overrides Object

public int
indexOf(Object o)

Implements java.util.List.indexOf.

Returns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element.

public List<A>
intersect(List<A> that)

public boolean
public Iterator<A>
iterator()

Implements abstract java.util.AbstractCollection.iterator.

Implements java.util.List.iterator, java.util.Collection.iterator.

Returns an iterator over the elements in this list in proper sequence.

public A
last()

The last element in the list, if any, or null.

public int
lastIndexOf(Object o)

Implements java.util.List.lastIndexOf.

Returns the index of the last occurrence of the specified element in this list, or -1 if this list does not contain the element.

public int
length()

Return the number of elements in this list.

public ListIterator<A>
listIterator()

Implements java.util.List.listIterator.

Returns a list iterator over the elements in this list (in proper sequence).

public ListIterator<A>
listIterator(int index)

Implements java.util.List.listIterator.

Returns a list iterator over the elements in this list (in proper sequence), starting at the specified position in the list.

public <Z> List<Z>
map(Function<A, Z> mapper)

public static <A> List<A>
nil()

Construct an empty list.

public boolean
nonEmpty()

Does list have elements?

public static <A> List<A>
of(A x1)

Hides java.util.List.of.

Construct a list consisting of given element.

public static <A> List<A>
of(A x1, A x2)

Hides java.util.List.of.

Construct a list consisting of given elements.

public static <A> List<A>
of(A x1, A x2, A x3)

Hides java.util.List.of.

Construct a list consisting of given elements.

public static <A> List<A>
of(A x1, A x2, A x3, A... rest)

Hides java.util.List.of.

Construct a list consisting of given elements.

public List<A>
prepend(A x)

Prepend given element to front of list, forming and returning a new list.

public List<A>
prependList(List<A> xs)

Prepend given list of elements to front of list, forming and returning a new list.

public A
remove(int index)

Implements java.util.List.remove.

Removes the element at the specified position in this list (optional operation).

public List<A>
reverse()

Reverse list.

public A
set(int index, A element)

Implements java.util.List.set.

Replaces the element at the specified position in this list with the specified element (optional operation).

public List<A>
setTail(List<A> tail)

public int
size()

Implements abstract java.util.AbstractCollection.size.

Implements java.util.List.size, java.util.Collection.size.

Returns the number of elements in this list.

public List<A>
subList(int fromIndex, int toIndex)

Implements java.util.List.subList.

Returns a view of the portion of this list between the specified fromIndex, inclusive, and toIndex, exclusive.

public List<A>
take(int n)

Create a new list from the first n elements of this list

public <T> T[]
toArray(T[] vec)

Overrides java.util.AbstractCollection.toArray.

Implements java.util.List.toArray, java.util.Collection.toArray.

Copy successive elements of this list into given vector until list is exhausted or end of vector is reached.

public Object[]
toArray()

Overrides java.util.AbstractCollection.toArray.

Implements java.util.List.toArray, java.util.Collection.toArray.

Returns an array containing all of the elements in this list in proper sequence (from first to last element).

public String
toString(String sep)

Form a string listing all elements with given separator character.

public String
toString()

Overrides java.util.AbstractCollection.toString.

Form a string listing all elements with comma as the separator character.

Inherited from java.util.AbstractCollection:
addaddAllclearcontainsAllremoveremoveAllretainAll

Field Detail

EMPTY_LISTback to summary
private static final List<?> EMPTY_LIST
tailback to summary
public List<A> tail

The remainder of the list except for its first element, supposed to be immutable.

Constructor Detail

Listback to summary
pack-priv List(A head, List<A> tail)

Construct a list given its head and tail.

Method Detail

addback to summary
public void add(int index, A element)

Implements java.util.List.add.

Doc from java.util.List.add.

Inserts the specified element at the specified position in this list (optional operation). Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices).

addAllback to summary
public boolean addAll(int index, Collection<? extends A> c)

Implements java.util.List.addAll.

Doc from java.util.List.addAll.

Inserts all of the elements in the specified collection into this list at the specified position (optional operation). Shifts the element currently at that position (if any) and any subsequent elements to the right (increases their indices). The new elements will appear in this list in the order that they are returned by the specified collection's iterator. The behavior of this operation is undefined if the specified collection is modified while the operation is in progress. (Note that this will occur if the specified collection is this list, and it's nonempty.)

appendback to summary
public List<A> append(A x)

Append given element at length, forming and returning a new list.

appendListback to summary
public List<A> appendList(List<A> x)

Append given list at length, forming and returning a new list.

appendListback to summary
public List<A> appendList(ListBuffer<A> x)

Append given list buffer at length, forming and returning a new list.

collectorback to summary
public static <Z> Collector<Z, ListBuffer<Z>, List<Z>> collector()

Collect elements into a new list (using a ListBuffer)

containsback to summary
public boolean contains(Object x)

Overrides java.util.AbstractCollection.contains.

Implements java.util.List.contains, java.util.Collection.contains.

Does the list contain the specified element?

Annotations
@Override
convertback to summary
public static <T> List<T> convert(Class<T> klass, List<?> list)
Annotations
@SuppressWarnings:unchecked
diffback to summary
public List<A> diff(List<A> that)
equalsback to summary
public boolean equals(Object other)

Overrides java.lang.Object.equals.

Implements java.util.List.equals, java.util.Collection.equals.

Is this list the same as other list?

Annotations
@Override
See Also
java.util.List#equals
equalsback to summary
public static boolean equals(List<?> xs, List<?> ys)

Are the two lists the same?

fillback to summary
public static <A> List<A> fill(int len, A init)

Deprecated

Construct a list consisting of a given number of identical elements.

Parameters
len:int

The number of elements in the list.

init:A

The value of each element.

Annotations
@Deprecated
filterback to summary
public static <A> List<A> filter(List<A> l, A elem)

Returns the list obtained from 'l' after removing all elements 'elem'

fromback to summary
public static <A> List<A> from(A[] array)

Construct a list consisting all elements of given array.

Parameters
array:A[]

an array; if null return an empty list

fromback to summary
public static <A> List<A> from(Iterable<? extends A> coll)
getback to summary
public A get(int index)

Implements java.util.List.get.

Doc from java.util.List.get.

Returns the element at the specified position in this list.

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Implements java.util.List.hashCode, java.util.Collection.hashCode.

Compute a hash code, overrides Object

Annotations
@Override
See Also
java.util.List#hashCode
indexOfback to summary
public int indexOf(Object o)

Implements java.util.List.indexOf.

Doc from java.util.List.indexOf.

Returns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element. More formally, returns the lowest index i such that Objects.equals(o, get(i)), or -1 if there is no such index.

intersectback to summary
public List<A> intersect(List<A> that)
isEmptyback to summary
public boolean isEmpty()

Overrides java.util.AbstractCollection.isEmpty.

Implements java.util.List.isEmpty, java.util.Collection.isEmpty.

Does list have no elements?

Annotations
@Override
iteratorback to summary
public Iterator<A> iterator()

Implements abstract java.util.AbstractCollection.iterator.

Implements java.util.List.iterator, java.util.Collection.iterator.

Doc from java.util.List.iterator.

Returns an iterator over the elements in this list in proper sequence.

Annotations
@Override
lastback to summary
public A last()

The last element in the list, if any, or null.

lastIndexOfback to summary
public int lastIndexOf(Object o)

Implements java.util.List.lastIndexOf.

Doc from java.util.List.lastIndexOf.

Returns the index of the last occurrence of the specified element in this list, or -1 if this list does not contain the element. More formally, returns the highest index i such that Objects.equals(o, get(i)), or -1 if there is no such index.

lengthback to summary
public int length()

Return the number of elements in this list.

listIteratorback to summary
public ListIterator<A> listIterator()

Implements java.util.List.listIterator.

Doc from java.util.List.listIterator.

Returns a list iterator over the elements in this list (in proper sequence).

listIteratorback to summary
public ListIterator<A> listIterator(int index)

Implements java.util.List.listIterator.

Doc from java.util.List.listIterator.

Returns a list iterator over the elements in this list (in proper sequence), starting at the specified position in the list. The specified index indicates the first element that would be returned by an initial call to next. An initial call to previous would return the element with the specified index minus one.

mapback to summary
public <Z> List<Z> map(Function<A, Z> mapper)
Annotations
@SuppressWarnings:unchecked
nilback to summary
public static <A> List<A> nil()

Construct an empty list.

Annotations
@SuppressWarnings:unchecked
nonEmptyback to summary
public boolean nonEmpty()

Does list have elements?

ofback to summary
public static <A> List<A> of(A x1)

Hides java.util.List.of.

Construct a list consisting of given element.

ofback to summary
public static <A> List<A> of(A x1, A x2)

Hides java.util.List.of.

Construct a list consisting of given elements.

ofback to summary
public static <A> List<A> of(A x1, A x2, A x3)

Hides java.util.List.of.

Construct a list consisting of given elements.

ofback to summary
public static <A> List<A> of(A x1, A x2, A x3, A... rest)

Hides java.util.List.of.

Construct a list consisting of given elements.

Annotations
@SuppressWarnings:unchecked
prependback to summary
public List<A> prepend(A x)

Prepend given element to front of list, forming and returning a new list.

prependListback to summary
public List<A> prependList(List<A> xs)

Prepend given list of elements to front of list, forming and returning a new list.

removeback to summary
public A remove(int index)

Implements java.util.List.remove.

Doc from java.util.List.remove.

Removes the element at the specified position in this list (optional operation). Shifts any subsequent elements to the left (subtracts one from their indices). Returns the element that was removed from the list.

reverseback to summary
public List<A> reverse()

Reverse list. If the list is empty or a singleton, then the same list is returned. Otherwise a new list is formed.

setback to summary
public A set(int index, A element)

Implements java.util.List.set.

Doc from java.util.List.set.

Replaces the element at the specified position in this list with the specified element (optional operation).

setTailback to summary
public List<A> setTail(List<A> tail)
sizeback to summary
public int size()

Implements abstract java.util.AbstractCollection.size.

Implements java.util.List.size, java.util.Collection.size.

Doc from java.util.List.size.

Returns the number of elements in this list. If this list contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.

Annotations
@Override
subListback to summary
public List<A> subList(int fromIndex, int toIndex)

Implements java.util.List.subList.

Doc from java.util.List.subList.

Returns a view of the portion of this list between the specified fromIndex, inclusive, and toIndex, exclusive. (If fromIndex and toIndex are equal, the returned list is empty.) The returned list is backed by this list, so non-structural changes in the returned list are reflected in this list, and vice-versa. The returned list supports all of the optional list operations supported by this list.

This method eliminates the need for explicit range operations (of the sort that commonly exist for arrays). Any operation that expects a list can be used as a range operation by passing a subList view instead of a whole list. For example, the following idiom removes a range of elements from a list:

list.subList(from, to).clear();
Similar idioms may be constructed for indexOf and lastIndexOf, and all of the algorithms in the Collections class can be applied to a subList.

The semantics of the list returned by this method become undefined if the backing list (i.e., this list) is structurally modified in any way other than via the returned list. (Structural modifications are those that change the size of this list, or otherwise perturb it in such a fashion that iterations in progress may yield incorrect results.)

takeback to summary
public List<A> take(int n)

Create a new list from the first n elements of this list

toArrayback to summary
public <T> T[] toArray(T[] vec)

Overrides java.util.AbstractCollection.toArray.

Implements java.util.List.toArray, java.util.Collection.toArray.

Copy successive elements of this list into given vector until list is exhausted or end of vector is reached.

Annotations
@Override
@SuppressWarnings:unchecked
toArrayback to summary
public Object[] toArray()

Overrides java.util.AbstractCollection.toArray.

Implements java.util.List.toArray, java.util.Collection.toArray.

Doc from java.util.List.toArray.

Returns an array containing all of the elements in this list in proper sequence (from first to last element).

The returned array will be "safe" in that no references to it are maintained by this list. (In other words, this method must allocate a new array even if this list is backed by an array). The caller is thus free to modify the returned array.

This method acts as bridge between array-based and collection-based APIs.

toStringback to summary
public String toString(String sep)

Form a string listing all elements with given separator character.

toStringback to summary
public String toString()

Overrides java.util.AbstractCollection.toString.

Form a string listing all elements with comma as the separator character.

Annotations
@Override