Package com.strobel.collections
Class ListBuffer<A>
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractQueue<A>
-
- com.strobel.collections.ListBuffer<A>
-
- All Implemented Interfaces:
java.lang.Iterable<A>,java.util.Collection<A>,java.util.Queue<A>
public class ListBuffer<A> extends java.util.AbstractQueue<A>A class for constructing lists by appending elements. Modelled after java.lang.StringBuffer.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
Fields Modifier and Type Field Description intcountThe number of element in this buffer.ImmutableList<A>elementsThe list of elements of this buffer.ImmutableList<A>lastA pointer pointing to the last, sentinel element of `elements'.booleansharedHas a list been created from this buffer yet?
-
Constructor Summary
Constructors Constructor Description ListBuffer()Create a new initially empty list buffer.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanadd(A a)booleanaddAll(java.util.Collection<? extends A> c)ListBuffer<A>append(A x)Append an element to buffer.ListBuffer<A>appendArray(A[] xs)Append all elements in an array to buffer.ListBuffer<A>appendList(ImmutableList<A> xs)Append all elements in a list to buffer.ListBuffer<A>appendList(ListBuffer<A> xs)Append all elements in a list to buffer.voidclear()booleancontains(java.lang.Object x)Does the list contain the specified element?booleancontainsAll(java.util.Collection<?> c)private voidcopy()Copy list and sets last.Afirst()The first element in this buffer.booleanisEmpty()Is buffer empty?java.util.Iterator<A>iterator()An enumeration of all elements in this buffer.static <T> ListBuffer<T>lb()intlength()Return the number of elements in this buffer.Anext()Return first element in this buffer and removebooleannonEmpty()Is buffer not empty?static <T> ListBuffer<T>of(T x)booleanoffer(A a)Apeek()Apoll()ListBuffer<A>prepend(A x)Prepend an element to buffer.booleanremove(java.lang.Object o)booleanremoveAll(java.util.Collection<?> c)booleanretainAll(java.util.Collection<?> c)intsize()java.lang.Object[]toArray()<T> T[]toArray(T[] vec)Convert buffer to an arrayImmutableList<A>toList()Convert buffer to a list of all its elements.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
-
-
-
Field Detail
-
elements
public ImmutableList<A> elements
The list of elements of this buffer.
-
last
public ImmutableList<A> last
A pointer pointing to the last, sentinel element of `elements'.
-
count
public int count
The number of element in this buffer.
-
shared
public boolean shared
Has a list been created from this buffer yet?
-
-
Method Detail
-
lb
public static <T> ListBuffer<T> lb()
-
of
public static <T> ListBuffer<T> of(T x)
-
clear
public final void clear()
-
length
public int length()
Return the number of elements in this buffer.
-
size
public int size()
-
isEmpty
public boolean isEmpty()
Is buffer empty?
-
nonEmpty
public boolean nonEmpty()
Is buffer not empty?
-
copy
private void copy()
Copy list and sets last.
-
prepend
public ListBuffer<A> prepend(A x)
Prepend an element to buffer.
-
append
public ListBuffer<A> append(A x)
Append an element to buffer.
-
appendList
public ListBuffer<A> appendList(ImmutableList<A> xs)
Append all elements in a list to buffer.
-
appendList
public ListBuffer<A> appendList(ListBuffer<A> xs)
Append all elements in a list to buffer.
-
appendArray
public ListBuffer<A> appendArray(A[] xs)
Append all elements in an array to buffer.
-
toList
public ImmutableList<A> toList()
Convert buffer to a list of all its elements.
-
contains
public boolean contains(java.lang.Object x)
Does the list contain the specified element?
-
toArray
@NotNull public <T> T[] toArray(T[] vec)
Convert buffer to an array
-
toArray
@NotNull public java.lang.Object[] toArray()
-
first
public A first()
The first element in this buffer.
-
next
public A next()
Return first element in this buffer and remove
-
iterator
@NotNull public java.util.Iterator<A> iterator()
An enumeration of all elements in this buffer.
-
add
public boolean add(A a)
-
remove
public boolean remove(java.lang.Object o)
-
containsAll
public boolean containsAll(java.util.Collection<?> c)
-
addAll
public boolean addAll(java.util.Collection<? extends A> c)
-
removeAll
public boolean removeAll(java.util.Collection<?> c)
-
retainAll
public boolean retainAll(java.util.Collection<?> c)
-
offer
public boolean offer(A a)
-
poll
public A poll()
-
peek
public A peek()
-
-