langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/util/ListBuffer.java
author mcimadamore
Fri, 16 Dec 2016 15:27:47 +0000
changeset 42828 cce89649f958
parent 29291 076c277565f7
permissions -rw-r--r--
8171371: Remove redundant type-arguments from generic method calls Reviewed-by: jjg, rfield, mchung
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
20249
93f8eae31092 6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents: 14803
diff changeset
     2
 * Copyright (c) 1999, 2013, 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
864
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 10
diff changeset
    43
    public static <T> ListBuffer<T> of(T x) {
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22159
diff changeset
    44
        ListBuffer<T> lb = new ListBuffer<>();
864
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 10
diff changeset
    45
        lb.add(x);
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 10
diff changeset
    46
        return lb;
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 10
diff changeset
    47
    }
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 10
diff changeset
    48
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
    /** The list of elements of this buffer.
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
     */
14803
88347e495d34 8004504: ListBuffer could reuse List.nil() as the sentinel element
jlahoda
parents: 5847
diff changeset
    51
    private List<A> elems;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
14803
88347e495d34 8004504: ListBuffer could reuse List.nil() as the sentinel element
jlahoda
parents: 5847
diff changeset
    53
    /** A pointer pointing to the last element of 'elems' containing data,
88347e495d34 8004504: ListBuffer could reuse List.nil() as the sentinel element
jlahoda
parents: 5847
diff changeset
    54
     *  or null if the list is empty.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
     */
14803
88347e495d34 8004504: ListBuffer could reuse List.nil() as the sentinel element
jlahoda
parents: 5847
diff changeset
    56
    private List<A> last;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
    /** The number of element in this buffer.
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
     */
14803
88347e495d34 8004504: ListBuffer could reuse List.nil() as the sentinel element
jlahoda
parents: 5847
diff changeset
    60
    private int count;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
    /** Has a list been created from this buffer yet?
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
     */
14803
88347e495d34 8004504: ListBuffer could reuse List.nil() as the sentinel element
jlahoda
parents: 5847
diff changeset
    64
    private boolean shared;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
    /** Create a new initially empty list buffer.
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
    public ListBuffer() {
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
        clear();
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
    public final void clear() {
14803
88347e495d34 8004504: ListBuffer could reuse List.nil() as the sentinel element
jlahoda
parents: 5847
diff changeset
    73
        this.elems = List.nil();
88347e495d34 8004504: ListBuffer could reuse List.nil() as the sentinel element
jlahoda
parents: 5847
diff changeset
    74
        this.last = null;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
        count = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
        shared = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
    /** Return the number of elements in this buffer.
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
    public int length() {
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
        return count;
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
    public int size() {
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
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
    /** Is buffer empty?
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
    public boolean isEmpty() {
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
        return count == 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
    /** Is buffer not empty?
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
    public boolean nonEmpty() {
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
        return count != 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
    /** Copy list and sets last.
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
    private void copy() {
14803
88347e495d34 8004504: ListBuffer could reuse List.nil() as the sentinel element
jlahoda
parents: 5847
diff changeset
   103
        if (elems.nonEmpty()) {
88347e495d34 8004504: ListBuffer could reuse List.nil() as the sentinel element
jlahoda
parents: 5847
diff changeset
   104
            List<A> orig = elems;
88347e495d34 8004504: ListBuffer could reuse List.nil() as the sentinel element
jlahoda
parents: 5847
diff changeset
   105
42828
cce89649f958 8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents: 29291
diff changeset
   106
            elems = last = List.of(orig.head);
14803
88347e495d34 8004504: ListBuffer could reuse List.nil() as the sentinel element
jlahoda
parents: 5847
diff changeset
   107
88347e495d34 8004504: ListBuffer could reuse List.nil() as the sentinel element
jlahoda
parents: 5847
diff changeset
   108
            while ((orig = orig.tail).nonEmpty()) {
42828
cce89649f958 8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents: 29291
diff changeset
   109
                last.tail = List.of(orig.head);
14803
88347e495d34 8004504: ListBuffer could reuse List.nil() as the sentinel element
jlahoda
parents: 5847
diff changeset
   110
                last = last.tail;
88347e495d34 8004504: ListBuffer could reuse List.nil() as the sentinel element
jlahoda
parents: 5847
diff changeset
   111
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
    /** Prepend an element to buffer.
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
    public ListBuffer<A> prepend(A x) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
        elems = elems.prepend(x);
14803
88347e495d34 8004504: ListBuffer could reuse List.nil() as the sentinel element
jlahoda
parents: 5847
diff changeset
   119
        if (last == null) last = elems;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
        count++;
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
        return this;
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
    /** Append an element to buffer.
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
    public ListBuffer<A> append(A x) {
29291
076c277565f7 8073550: java* tools: replace obj.getClass hacks with Assert.checkNonNull or Objects.requireNonNull
mcimadamore
parents: 25874
diff changeset
   127
        Assert.checkNonNull(x);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
        if (shared) copy();
42828
cce89649f958 8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents: 29291
diff changeset
   129
        List<A> newLast = List.of(x);
14803
88347e495d34 8004504: ListBuffer could reuse List.nil() as the sentinel element
jlahoda
parents: 5847
diff changeset
   130
        if (last != null) {
88347e495d34 8004504: ListBuffer could reuse List.nil() as the sentinel element
jlahoda
parents: 5847
diff changeset
   131
            last.tail = newLast;
88347e495d34 8004504: ListBuffer could reuse List.nil() as the sentinel element
jlahoda
parents: 5847
diff changeset
   132
            last = newLast;
88347e495d34 8004504: ListBuffer could reuse List.nil() as the sentinel element
jlahoda
parents: 5847
diff changeset
   133
        } else {
88347e495d34 8004504: ListBuffer could reuse List.nil() as the sentinel element
jlahoda
parents: 5847
diff changeset
   134
            elems = last = newLast;
88347e495d34 8004504: ListBuffer could reuse List.nil() as the sentinel element
jlahoda
parents: 5847
diff changeset
   135
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
        count++;
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
        return this;
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
    /** Append all elements in a list to buffer.
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
    public ListBuffer<A> appendList(List<A> xs) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
        while (xs.nonEmpty()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
            append(xs.head);
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
            xs = xs.tail;
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
        return this;
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
    /** Append all elements in a list to buffer.
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
    public ListBuffer<A> appendList(ListBuffer<A> xs) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
        return appendList(xs.toList());
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
    /** Append all elements in an array to buffer.
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
    public ListBuffer<A> appendArray(A[] xs) {
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 20249
diff changeset
   159
        for (A x : xs) {
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 20249
diff changeset
   160
            append(x);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   162
        return this;
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
    /** Convert buffer to a list of all its elements.
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
    public List<A> toList() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   168
        shared = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   169
        return elems;
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
    /** Does the list contain the specified element?
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
    public boolean contains(Object x) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
        return elems.contains(x);
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
    /** Convert buffer to an array
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
    public <T> T[] toArray(T[] vec) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
        return elems.toArray(vec);
06bc494ca11e Initial load
duke
parents:
diff changeset
   182
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
    public Object[] toArray() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
        return toArray(new Object[size()]);
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
06bc494ca11e Initial load
duke
parents:
diff changeset
   187
    /** The first element in this buffer.
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
    public A first() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
        return elems.head;
06bc494ca11e Initial load
duke
parents:
diff changeset
   191
    }
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
    /** Return first element in this buffer and remove
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   194
     */
864
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 10
diff changeset
   195
    public A next() {
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 10
diff changeset
   196
        A x = elems.head;
14803
88347e495d34 8004504: ListBuffer could reuse List.nil() as the sentinel element
jlahoda
parents: 5847
diff changeset
   197
        if (!elems.isEmpty()) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   198
            elems = elems.tail;
14803
88347e495d34 8004504: ListBuffer could reuse List.nil() as the sentinel element
jlahoda
parents: 5847
diff changeset
   199
            if (elems.isEmpty()) last = null;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
            count--;
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
        return x;
06bc494ca11e Initial load
duke
parents:
diff changeset
   203
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   204
06bc494ca11e Initial load
duke
parents:
diff changeset
   205
    /** An enumeration of all elements in this buffer.
06bc494ca11e Initial load
duke
parents:
diff changeset
   206
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   207
    public Iterator<A> iterator() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   208
        return new Iterator<A>() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   209
            List<A> elems = ListBuffer.this.elems;
06bc494ca11e Initial load
duke
parents:
diff changeset
   210
            public boolean hasNext() {
14803
88347e495d34 8004504: ListBuffer could reuse List.nil() as the sentinel element
jlahoda
parents: 5847
diff changeset
   211
                return !elems.isEmpty();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   212
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   213
            public A next() {
14803
88347e495d34 8004504: ListBuffer could reuse List.nil() as the sentinel element
jlahoda
parents: 5847
diff changeset
   214
                if (elems.isEmpty())
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   215
                    throw new NoSuchElementException();
06bc494ca11e Initial load
duke
parents:
diff changeset
   216
                A elem = elems.head;
06bc494ca11e Initial load
duke
parents:
diff changeset
   217
                elems = elems.tail;
06bc494ca11e Initial load
duke
parents:
diff changeset
   218
                return elem;
06bc494ca11e Initial load
duke
parents:
diff changeset
   219
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   220
            public void remove() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   221
                throw new UnsupportedOperationException();
06bc494ca11e Initial load
duke
parents:
diff changeset
   222
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   223
        };
06bc494ca11e Initial load
duke
parents:
diff changeset
   224
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   225
06bc494ca11e Initial load
duke
parents:
diff changeset
   226
    public boolean add(A a) {
864
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 10
diff changeset
   227
        append(a);
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 10
diff changeset
   228
        return true;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   229
    }
864
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 10
diff changeset
   230
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   231
    public boolean remove(Object o) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   232
        throw new UnsupportedOperationException();
06bc494ca11e Initial load
duke
parents:
diff changeset
   233
    }
864
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 10
diff changeset
   234
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   235
    public boolean containsAll(Collection<?> c) {
864
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 10
diff changeset
   236
        for (Object x: c) {
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 10
diff changeset
   237
            if (!contains(x))
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 10
diff changeset
   238
                return false;
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 10
diff changeset
   239
        }
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 10
diff changeset
   240
        return true;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   241
    }
864
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 10
diff changeset
   242
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   243
    public boolean addAll(Collection<? extends A> c) {
864
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 10
diff changeset
   244
        for (A a: c)
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 10
diff changeset
   245
            append(a);
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 10
diff changeset
   246
        return true;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   247
    }
864
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 10
diff changeset
   248
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   249
    public boolean removeAll(Collection<?> c) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   250
        throw new UnsupportedOperationException();
06bc494ca11e Initial load
duke
parents:
diff changeset
   251
    }
864
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 10
diff changeset
   252
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   253
    public boolean retainAll(Collection<?> c) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   254
        throw new UnsupportedOperationException();
06bc494ca11e Initial load
duke
parents:
diff changeset
   255
    }
864
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 10
diff changeset
   256
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 10
diff changeset
   257
    public boolean offer(A a) {
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 10
diff changeset
   258
        append(a);
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 10
diff changeset
   259
        return true;
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 10
diff changeset
   260
    }
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
    public A poll() {
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 10
diff changeset
   263
        return next();
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 10
diff changeset
   264
    }
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 10
diff changeset
   265
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 10
diff changeset
   266
    public A peek() {
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 10
diff changeset
   267
        return first();
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 10
diff changeset
   268
    }
14803
88347e495d34 8004504: ListBuffer could reuse List.nil() as the sentinel element
jlahoda
parents: 5847
diff changeset
   269
88347e495d34 8004504: ListBuffer could reuse List.nil() as the sentinel element
jlahoda
parents: 5847
diff changeset
   270
    public A last() {
88347e495d34 8004504: ListBuffer could reuse List.nil() as the sentinel element
jlahoda
parents: 5847
diff changeset
   271
        return last != null ? last.head : null;
88347e495d34 8004504: ListBuffer could reuse List.nil() as the sentinel element
jlahoda
parents: 5847
diff changeset
   272
    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   273
}