Class 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
      int count
      The number of element in this buffer.
      ImmutableList<A> elements
      The list of elements of this buffer.
      ImmutableList<A> last
      A pointer pointing to the last, sentinel element of `elements'.
      boolean shared
      Has 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
      boolean add​(A a)  
      boolean addAll​(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.
      void clear()  
      boolean contains​(java.lang.Object x)
      Does the list contain the specified element?
      boolean containsAll​(java.util.Collection<?> c)  
      private void copy()
      Copy list and sets last.
      A first()
      The first element in this buffer.
      boolean isEmpty()
      Is buffer empty?
      java.util.Iterator<A> iterator()
      An enumeration of all elements in this buffer.
      static <T> ListBuffer<T> lb()  
      int length()
      Return the number of elements in this buffer.
      A next()
      Return first element in this buffer and remove
      boolean nonEmpty()
      Is buffer not empty?
      static <T> ListBuffer<T> of​(T x)  
      boolean offer​(A a)  
      A peek()  
      A poll()  
      ListBuffer<A> prepend​(A x)
      Prepend an element to buffer.
      boolean remove​(java.lang.Object o)  
      boolean removeAll​(java.util.Collection<?> c)  
      boolean retainAll​(java.util.Collection<?> c)  
      int size()  
      java.lang.Object[] toArray()  
      <T> T[] toArray​(T[] vec)
      Convert buffer to an array
      ImmutableList<A> toList()
      Convert buffer to a list of all its elements.
      • Methods inherited from class java.util.AbstractQueue

        element, remove
      • Methods inherited from class java.util.AbstractCollection

        toString
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.util.Collection

        equals, hashCode, parallelStream, removeIf, spliterator, stream, toArray
      • Methods inherited from interface java.lang.Iterable

        forEach
    • 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?
    • Constructor Detail

      • ListBuffer

        public ListBuffer()
        Create a new initially empty list buffer.
    • Method Detail

      • of

        public static <T> ListBuffer<T> of​(T x)
      • clear

        public final void clear()
        Specified by:
        clear in interface java.util.Collection<A>
        Overrides:
        clear in class java.util.AbstractQueue<A>
      • length

        public int length()
        Return the number of elements in this buffer.
      • size

        public int size()
        Specified by:
        size in interface java.util.Collection<A>
        Specified by:
        size in class java.util.AbstractCollection<A>
      • isEmpty

        public boolean isEmpty()
        Is buffer empty?
        Specified by:
        isEmpty in interface java.util.Collection<A>
        Overrides:
        isEmpty in class java.util.AbstractCollection<A>
      • 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.
      • 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?
        Specified by:
        contains in interface java.util.Collection<A>
        Overrides:
        contains in class java.util.AbstractCollection<A>
      • toArray

        @NotNull
        public <T> T[] toArray​(T[] vec)
        Convert buffer to an array
        Specified by:
        toArray in interface java.util.Collection<A>
        Overrides:
        toArray in class java.util.AbstractCollection<A>
      • toArray

        @NotNull
        public java.lang.Object[] toArray()
        Specified by:
        toArray in interface java.util.Collection<A>
        Overrides:
        toArray in class java.util.AbstractCollection<A>
      • 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.
        Specified by:
        iterator in interface java.util.Collection<A>
        Specified by:
        iterator in interface java.lang.Iterable<A>
        Specified by:
        iterator in class java.util.AbstractCollection<A>
      • add

        public boolean add​(A a)
        Specified by:
        add in interface java.util.Collection<A>
        Specified by:
        add in interface java.util.Queue<A>
        Overrides:
        add in class java.util.AbstractQueue<A>
      • remove

        public boolean remove​(java.lang.Object o)
        Specified by:
        remove in interface java.util.Collection<A>
        Overrides:
        remove in class java.util.AbstractCollection<A>
      • containsAll

        public boolean containsAll​(java.util.Collection<?> c)
        Specified by:
        containsAll in interface java.util.Collection<A>
        Overrides:
        containsAll in class java.util.AbstractCollection<A>
      • addAll

        public boolean addAll​(java.util.Collection<? extends A> c)
        Specified by:
        addAll in interface java.util.Collection<A>
        Overrides:
        addAll in class java.util.AbstractQueue<A>
      • removeAll

        public boolean removeAll​(java.util.Collection<?> c)
        Specified by:
        removeAll in interface java.util.Collection<A>
        Overrides:
        removeAll in class java.util.AbstractCollection<A>
      • retainAll

        public boolean retainAll​(java.util.Collection<?> c)
        Specified by:
        retainAll in interface java.util.Collection<A>
        Overrides:
        retainAll in class java.util.AbstractCollection<A>
      • offer

        public boolean offer​(A a)
      • poll

        public A poll()
      • peek

        public A peek()