langtools/src/share/classes/com/sun/tools/javac/util/ListBuffer.java
author jjg
Thu, 10 Jun 2010 16:08:01 -0700
changeset 5847 1908176fd6e3
parent 5520 86e4b9a9da40
child 14803 88347e495d34
permissions -rw-r--r--
6944312: Potential rebranding issues in openjdk/langtools repository sources Reviewed-by: darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1264
diff changeset
     2
 * Copyright (c) 1999, 2008, Oracle and/or its affiliates. All rights reserved.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
06bc494ca11e Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1264
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1264
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    10
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
06bc494ca11e Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
06bc494ca11e Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
06bc494ca11e Initial load
duke
parents:
diff changeset
    20
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1264
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1264
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1264
diff changeset
    23
 * questions.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
06bc494ca11e Initial load
duke
parents:
diff changeset
    26
package com.sun.tools.javac.util;
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
864
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 10
diff changeset
    28
import java.util.AbstractQueue;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
import java.util.Collection;
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
import java.util.Iterator;
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
import java.util.NoSuchElementException;
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
/** A class for constructing lists by appending elements. Modelled after
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
 *  java.lang.StringBuffer.
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
 *
5847
1908176fd6e3 6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5520
diff changeset
    36
 *  <p><b>This is NOT part of any supported API.
1908176fd6e3 6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5520
diff changeset
    37
 *  If you write code that depends on this, you do so at your own risk.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
 *  This code and its internal interfaces are subject to change or
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
 *  deletion without notice.</b>
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
 */
864
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 10
diff changeset
    41
public class ListBuffer<A> extends AbstractQueue<A> {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
    public static <T> ListBuffer<T> lb() {
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
        return new ListBuffer<T>();
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
864
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 10
diff changeset
    47
    public static <T> ListBuffer<T> of(T x) {
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 10
diff changeset
    48
        ListBuffer<T> lb = new ListBuffer<T>();
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 10
diff changeset
    49
        lb.add(x);
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 10
diff changeset
    50
        return lb;
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 10
diff changeset
    51
    }
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 10
diff changeset
    52
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
    /** The list of elements of this buffer.
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
    public List<A> elems;
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
    /** A pointer pointing to the last, sentinel element of `elems'.
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
    public List<A> last;
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
    /** The number of element in this buffer.
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
    public int count;
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
    /** Has a list been created from this buffer yet?
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
    public boolean shared;
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
    /** Create a new initially empty list buffer.
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
    public ListBuffer() {
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
        clear();
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
    public final void clear() {
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
        this.elems = new List<A>(null,null);
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
        this.last = this.elems;
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
        count = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
        shared = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
    /** Return the number of elements in this buffer.
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
    public int length() {
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
        return count;
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
    public int size() {
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
        return count;
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
    /** Is buffer empty?
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
    public boolean isEmpty() {
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
        return count == 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
    /** Is buffer not empty?
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
    public boolean nonEmpty() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
        return count != 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
    /** Copy list and sets last.
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
    private void copy() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
        List<A> p = elems = new List<A>(elems.head, elems.tail);
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
        while (true) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
            List<A> tail = p.tail;
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
            if (tail == null) break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
            tail = new List<A>(tail.head, tail.tail);
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
            p.setTail(tail);
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
            p = tail;
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
        last = p;
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
        shared = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
    /** Prepend an element to buffer.
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
    public ListBuffer<A> prepend(A x) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
        elems = elems.prepend(x);
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
        count++;
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
        return this;
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
    /** Append an element to buffer.
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
    public ListBuffer<A> append(A x) {
864
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 10
diff changeset
   129
        x.getClass(); // null check
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
        if (shared) copy();
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
        last.head = x;
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
        last.setTail(new List<A>(null,null));
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
        last = last.tail;
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
        count++;
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
        return this;
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
    /** Append all elements in a list to buffer.
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
    public ListBuffer<A> appendList(List<A> xs) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
        while (xs.nonEmpty()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
            append(xs.head);
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
            xs = xs.tail;
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
        return this;
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
    /** Append all elements in a list to buffer.
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
    public ListBuffer<A> appendList(ListBuffer<A> xs) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
        return appendList(xs.toList());
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
    /** Append all elements in an array to buffer.
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
    public ListBuffer<A> appendArray(A[] xs) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
        for (int i = 0; i < xs.length; i++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
            append(xs[i]);
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
        return this;
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   162
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
    /** Convert buffer to a list of all its elements.
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
    public List<A> toList() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
        shared = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
        return elems;
06bc494ca11e Initial load
duke
parents:
diff changeset
   168
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   169
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
    /** Does the list contain the specified element?
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
    public boolean contains(Object x) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
        return elems.contains(x);
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
    /** Convert buffer to an array
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
    public <T> T[] toArray(T[] vec) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
        return elems.toArray(vec);
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
    public Object[] toArray() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   182
        return toArray(new Object[size()]);
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
    /** The first element in this buffer.
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   187
    public A first() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
        return elems.head;
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
864
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 10
diff changeset
   191
    /** Return first element in this buffer and remove
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   192
     */
864
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 10
diff changeset
   193
    public A next() {
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 10
diff changeset
   194
        A x = elems.head;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   195
        if (elems != last) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   196
            elems = elems.tail;
06bc494ca11e Initial load
duke
parents:
diff changeset
   197
            count--;
06bc494ca11e Initial load
duke
parents:
diff changeset
   198
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   199
        return x;
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
    /** An enumeration of all elements in this buffer.
06bc494ca11e Initial load
duke
parents:
diff changeset
   203
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   204
    public Iterator<A> iterator() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   205
        return new Iterator<A>() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   206
            List<A> elems = ListBuffer.this.elems;
06bc494ca11e Initial load
duke
parents:
diff changeset
   207
            public boolean hasNext() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   208
                return elems != last;
06bc494ca11e Initial load
duke
parents:
diff changeset
   209
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   210
            public A next() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   211
                if (elems == last)
06bc494ca11e Initial load
duke
parents:
diff changeset
   212
                    throw new NoSuchElementException();
06bc494ca11e Initial load
duke
parents:
diff changeset
   213
                A elem = elems.head;
06bc494ca11e Initial load
duke
parents:
diff changeset
   214
                elems = elems.tail;
06bc494ca11e Initial load
duke
parents:
diff changeset
   215
                return elem;
06bc494ca11e Initial load
duke
parents:
diff changeset
   216
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   217
            public void remove() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   218
                throw new UnsupportedOperationException();
06bc494ca11e Initial load
duke
parents:
diff changeset
   219
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   220
        };
06bc494ca11e Initial load
duke
parents:
diff changeset
   221
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   222
06bc494ca11e Initial load
duke
parents:
diff changeset
   223
    public boolean add(A a) {
864
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 10
diff changeset
   224
        append(a);
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 10
diff changeset
   225
        return true;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   226
    }
864
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 10
diff changeset
   227
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   228
    public boolean remove(Object o) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   229
        throw new UnsupportedOperationException();
06bc494ca11e Initial load
duke
parents:
diff changeset
   230
    }
864
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 10
diff changeset
   231
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   232
    public boolean containsAll(Collection<?> c) {
864
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 10
diff changeset
   233
        for (Object x: c) {
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 10
diff changeset
   234
            if (!contains(x))
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 10
diff changeset
   235
                return false;
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 10
diff changeset
   236
        }
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 10
diff changeset
   237
        return true;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   238
    }
864
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 10
diff changeset
   239
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   240
    public boolean addAll(Collection<? extends A> c) {
864
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 10
diff changeset
   241
        for (A a: c)
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 10
diff changeset
   242
            append(a);
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 10
diff changeset
   243
        return true;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   244
    }
864
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 10
diff changeset
   245
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   246
    public boolean removeAll(Collection<?> c) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   247
        throw new UnsupportedOperationException();
06bc494ca11e Initial load
duke
parents:
diff changeset
   248
    }
864
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 10
diff changeset
   249
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   250
    public boolean retainAll(Collection<?> c) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   251
        throw new UnsupportedOperationException();
06bc494ca11e Initial load
duke
parents:
diff changeset
   252
    }
864
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 10
diff changeset
   253
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 10
diff changeset
   254
    public boolean offer(A a) {
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 10
diff changeset
   255
        append(a);
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 10
diff changeset
   256
        return true;
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 10
diff changeset
   257
    }
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 10
diff changeset
   258
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 10
diff changeset
   259
    public A poll() {
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 10
diff changeset
   260
        return next();
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 10
diff changeset
   261
    }
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 10
diff changeset
   262
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 10
diff changeset
   263
    public A peek() {
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 10
diff changeset
   264
        return first();
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 10
diff changeset
   265
    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   266
}