1.1 --- a/src/share/classes/com/sun/tools/javac/util/ListBuffer.java Thu Jul 10 11:25:23 2008 -0700 1.2 +++ b/src/share/classes/com/sun/tools/javac/util/ListBuffer.java Thu Jul 10 16:50:38 2008 -0700 1.3 @@ -25,6 +25,7 @@ 1.4 1.5 package com.sun.tools.javac.util; 1.6 1.7 +import java.util.AbstractQueue; 1.8 import java.util.Collection; 1.9 import java.util.Iterator; 1.10 import java.util.NoSuchElementException; 1.11 @@ -37,12 +38,18 @@ 1.12 * This code and its internal interfaces are subject to change or 1.13 * deletion without notice.</b> 1.14 */ 1.15 -public class ListBuffer<A> implements Collection<A> { 1.16 +public class ListBuffer<A> extends AbstractQueue<A> { 1.17 1.18 public static <T> ListBuffer<T> lb() { 1.19 return new ListBuffer<T>(); 1.20 } 1.21 1.22 + public static <T> ListBuffer<T> of(T x) { 1.23 + ListBuffer<T> lb = new ListBuffer<T>(); 1.24 + lb.add(x); 1.25 + return lb; 1.26 + } 1.27 + 1.28 /** The list of elements of this buffer. 1.29 */ 1.30 public List<A> elems; 1.31 @@ -119,6 +126,7 @@ 1.32 /** Append an element to buffer. 1.33 */ 1.34 public ListBuffer<A> append(A x) { 1.35 + x.getClass(); // null check 1.36 if (shared) copy(); 1.37 last.head = x; 1.38 last.setTail(new List<A>(null,null)); 1.39 @@ -180,20 +188,14 @@ 1.40 return elems.head; 1.41 } 1.42 1.43 - /** Remove the first element in this buffer. 1.44 + /** Return first element in this buffer and remove 1.45 */ 1.46 - public void remove() { 1.47 + public A next() { 1.48 + A x = elems.head; 1.49 if (elems != last) { 1.50 elems = elems.tail; 1.51 count--; 1.52 } 1.53 - } 1.54 - 1.55 - /** Return first element in this buffer and remove 1.56 - */ 1.57 - public A next() { 1.58 - A x = elems.head; 1.59 - remove(); 1.60 return x; 1.61 } 1.62 1.63 @@ -219,21 +221,46 @@ 1.64 } 1.65 1.66 public boolean add(A a) { 1.67 - throw new UnsupportedOperationException(); 1.68 + append(a); 1.69 + return true; 1.70 } 1.71 + 1.72 public boolean remove(Object o) { 1.73 throw new UnsupportedOperationException(); 1.74 } 1.75 + 1.76 public boolean containsAll(Collection<?> c) { 1.77 - throw new UnsupportedOperationException(); 1.78 + for (Object x: c) { 1.79 + if (!contains(x)) 1.80 + return false; 1.81 + } 1.82 + return true; 1.83 } 1.84 + 1.85 public boolean addAll(Collection<? extends A> c) { 1.86 - throw new UnsupportedOperationException(); 1.87 + for (A a: c) 1.88 + append(a); 1.89 + return true; 1.90 } 1.91 + 1.92 public boolean removeAll(Collection<?> c) { 1.93 throw new UnsupportedOperationException(); 1.94 } 1.95 + 1.96 public boolean retainAll(Collection<?> c) { 1.97 throw new UnsupportedOperationException(); 1.98 } 1.99 + 1.100 + public boolean offer(A a) { 1.101 + append(a); 1.102 + return true; 1.103 + } 1.104 + 1.105 + public A poll() { 1.106 + return next(); 1.107 + } 1.108 + 1.109 + public A peek() { 1.110 + return first(); 1.111 + } 1.112 }