com.sun.tools.javac.util
Class List<A>

java.lang.Object
  extended by java.util.AbstractCollection<A>
      extended by com.sun.tools.javac.util.List<A>
All Implemented Interfaces:
java.lang.Iterable<A>, java.util.Collection<A>, java.util.List<A>

public class List<A>
extends java.util.AbstractCollection<A>
implements java.util.List<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 algorthms 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 API supported by Sun Microsystems. 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
private static List<?> EMPTY_LIST
           
private static java.util.Iterator<?> EMPTYITERATOR
           
 A head
          The first element of the list, supposed to be immutable.
 List<A> tail
          The remainder of the list except for its first element, supposed to be immutable.
 
Constructor Summary
List(A head, List<A> tail)
          Construct a list given its head and tail.
 
Method Summary
 void add(int index, A element)
           
 boolean addAll(int index, java.util.Collection<? extends A> c)
           
 List<A> append(A x)
          Append given element at length, forming and returning a new list.
 List<A> appendList(List<A> x)
          Append given list at length, forming and returning a new list.
 List<A> appendList(ListBuffer<A> x)
          Append given list buffer at length, forming and returning a new list.
 boolean contains(java.lang.Object x)
          Does the list contain the specified element?
static
<T> List<T>
convert(java.lang.Class<T> klass, List<?> list)
           
private static
<A> java.util.Iterator<A>
emptyIterator()
           
static boolean equals(List<?> xs, List<?> ys)
          Are the two lists the same?
 boolean equals(java.lang.Object other)
          Is this list the same as other list?
static
<A> List<A>
fill(int len, A init)
          Deprecated. 
static
<A> List<A>
from(A[] array)
          Construct a list consisting all elements of given array.
 A get(int index)
           
 int hashCode()
          Compute a hash code, overrides Object
 int indexOf(java.lang.Object o)
           
 boolean isEmpty()
          Does list have no elements?
 java.util.Iterator<A> iterator()
           
 A last()
          The last element in the list, if any, or null.
 int lastIndexOf(java.lang.Object o)
           
 int length()
          Return the number of elements in this list.
 java.util.ListIterator<A> listIterator()
           
 java.util.ListIterator<A> listIterator(int index)
           
static
<A> List<A>
nil()
          Construct an empty list.
 boolean nonEmpty()
          Does list have elements?
static
<A> List<A>
of(A x1)
          Construct a list consisting of given element.
static
<A> List<A>
of(A x1, A x2)
          Construct a list consisting of given elements.
static
<A> List<A>
of(A x1, A x2, A x3)
          Construct a list consisting of given elements.
static
<A> List<A>
of(A x1, A x2, A x3, A... rest)
          Construct a list consisting of given elements.
 List<A> prepend(A x)
          Prepend given element to front of list, forming and returning a new list.
 List<A> prependList(List<A> xs)
          Prepend given list of elements to front of list, forming and returning a new list.
 A remove(int index)
           
 List<A> reverse()
          Reverse list.
 A set(int index, A element)
           
 List<A> setTail(List<A> tail)
           
 int size()
           
 java.util.List<A> subList(int fromIndex, int toIndex)
           
 java.lang.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.
 java.lang.String toString()
          Form a string listing all elements with comma as the separator character.
 java.lang.String toString(java.lang.String sep)
          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.List
add, addAll, clear, containsAll, remove, removeAll, retainAll
 

Field Detail

head

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


tail

public List<A> tail
The remainder of the list except for its first element, supposed to be immutable.


EMPTY_LIST

private static List<?> EMPTY_LIST

EMPTYITERATOR

private static java.util.Iterator<?> EMPTYITERATOR
Constructor Detail

List

List(A head,
     List<A> tail)
Construct a list given its head and tail.

Method Detail

nil

public static <A> List<A> nil()
Construct an empty list.


of

public static <A> List<A> of(A x1)
Construct a list consisting of given element.


of

public static <A> List<A> of(A x1,
                             A x2)
Construct a list consisting of given elements.


of

public static <A> List<A> of(A x1,
                             A x2,
                             A x3)
Construct a list consisting of given elements.


of

public static <A> List<A> of(A x1,
                             A x2,
                             A x3,
                             A... rest)
Construct a list consisting of given elements.


from

public static <A> List<A> from(A[] array)
Construct a list consisting all elements of given array.

Parameters:
array - an array; if null return an empty list

fill

@Deprecated
public static <A> List<A> fill(int len,
                                          A init)
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 interface java.util.Collection<A>
Specified by:
isEmpty in interface java.util.List<A>
Overrides:
isEmpty in class java.util.AbstractCollection<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 interface java.util.Collection<A>
Specified by:
size in interface java.util.List<A>
Specified by:
size in class java.util.AbstractCollection<A>

setTail

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

prepend

public List<A> prepend(A x)
Prepend given element to front of list, forming and returning a new list.


prependList

public List<A> prependList(List<A> xs)
Prepend given list of elements to front of list, forming and returning a new list.


reverse

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.


append

public List<A> append(A x)
Append given element at length, forming and returning a new list.


appendList

public List<A> appendList(List<A> x)
Append given list at length, forming and returning a new list.


appendList

public List<A> appendList(ListBuffer<A> x)
Append given list buffer at length, forming and returning a new list.


toArray

public <T> T[] toArray(T[] vec)
Copy successive elements of this list into given vector until list is exhausted or end of vector is reached.

Specified by:
toArray in interface java.util.Collection<A>
Specified by:
toArray in interface java.util.List<A>
Overrides:
toArray in class java.util.AbstractCollection<A>

toArray

public java.lang.Object[] toArray()
Specified by:
toArray in interface java.util.Collection<A>
Specified by:
toArray in interface java.util.List<A>
Overrides:
toArray in class java.util.AbstractCollection<A>

toString

public java.lang.String toString(java.lang.String sep)
Form a string listing all elements with given separator character.


toString

public java.lang.String toString()
Form a string listing all elements with comma as the separator character.

Overrides:
toString in class java.util.AbstractCollection<A>

hashCode

public int hashCode()
Compute a hash code, overrides Object

Specified by:
hashCode in interface java.util.Collection<A>
Specified by:
hashCode in interface java.util.List<A>
Overrides:
hashCode in class java.lang.Object
See Also:
List.hashCode()

equals

public boolean equals(java.lang.Object other)
Is this list the same as other list?

Specified by:
equals in interface java.util.Collection<A>
Specified by:
equals in interface java.util.List<A>
Overrides:
equals in class java.lang.Object
See Also:
List.equals(java.lang.Object)

equals

public static boolean equals(List<?> xs,
                             List<?> ys)
Are the two lists the same?


contains

public boolean contains(java.lang.Object x)
Does the list contain the specified element?

Specified by:
contains in interface java.util.Collection<A>
Specified by:
contains in interface java.util.List<A>
Overrides:
contains in class java.util.AbstractCollection<A>

last

public A last()
The last element in the list, if any, or null.


convert

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

emptyIterator

private static <A> java.util.Iterator<A> emptyIterator()

iterator

public java.util.Iterator<A> iterator()
Specified by:
iterator in interface java.lang.Iterable<A>
Specified by:
iterator in interface java.util.Collection<A>
Specified by:
iterator in interface java.util.List<A>
Specified by:
iterator in class java.util.AbstractCollection<A>

get

public A get(int index)
Specified by:
get in interface java.util.List<A>

addAll

public boolean addAll(int index,
                      java.util.Collection<? extends A> c)
Specified by:
addAll in interface java.util.List<A>

set

public A set(int index,
             A element)
Specified by:
set in interface java.util.List<A>

add

public void add(int index,
                A element)
Specified by:
add in interface java.util.List<A>

remove

public A remove(int index)
Specified by:
remove in interface java.util.List<A>

indexOf

public int indexOf(java.lang.Object o)
Specified by:
indexOf in interface java.util.List<A>

lastIndexOf

public int lastIndexOf(java.lang.Object o)
Specified by:
lastIndexOf in interface java.util.List<A>

listIterator

public java.util.ListIterator<A> listIterator()
Specified by:
listIterator in interface java.util.List<A>

listIterator

public java.util.ListIterator<A> listIterator(int index)
Specified by:
listIterator in interface java.util.List<A>

subList

public java.util.List<A> subList(int fromIndex,
                                 int toIndex)
Specified by:
subList in interface java.util.List<A>