Package fj.data

Class List.Buffer<A>

  • All Implemented Interfaces:
    java.lang.Iterable<A>
    Enclosing class:
    List<A>

    public static final class List.Buffer<A>
    extends java.lang.Object
    implements java.lang.Iterable<A>
    A mutable, singly linked list. This structure should be used very sparingly, in favour of the immutable singly linked list structure.
    • Constructor Summary

      Constructors 
      Constructor Description
      Buffer()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      List.Buffer<A> append​(List<A> as)
      Appends the given list to this buffer.
      private void copy()  
      static <A> List.Buffer<A> empty()
      An empty buffer.
      static <A> List.Buffer<A> fromList​(List<A> as)
      Constructs a buffer from the given list.
      boolean isEmpty()
      Returns true if this buffer is empty, false otherwise.
      static <A> List.Buffer<A> iterableBuffer​(java.lang.Iterable<A> i)
      Takes the given iterable to a buffer.
      java.util.Iterator<A> iterator()
      Returns an iterator for this buffer.
      List<A> prependToList​(List<A> as)
      Prepends the elements of this buffer to the given list.
      List.Buffer<A> snoc​(A a)
      Appends (snoc) the given element to this buffer to produce a new buffer.
      java.util.Collection<A> toCollection()
      Projects an immutable collection of this buffer.
      List<A> toList()
      Returns an immutable list projection of this buffer.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.lang.Iterable

        forEach, spliterator
    • Field Detail

      • start

        private List<A> start
      • exported

        private boolean exported
    • Constructor Detail

      • Buffer

        public Buffer()
    • Method Detail

      • iterator

        public java.util.Iterator<A> iterator()
        Returns an iterator for this buffer. This method exists to permit the use in a for-each loop.
        Specified by:
        iterator in interface java.lang.Iterable<A>
        Returns:
        A iterator for this buffer.
      • snoc

        public List.Buffer<A> snoc​(A a)
        Appends (snoc) the given element to this buffer to produce a new buffer.
        Parameters:
        a - The element to append to this buffer.
        Returns:
        This buffer.
      • append

        public List.Buffer<A> append​(List<A> as)
        Appends the given list to this buffer.
        Parameters:
        as - The list to append to this buffer.
        Returns:
        This buffer.
      • prependToList

        public List<A> prependToList​(List<A> as)
        Prepends the elements of this buffer to the given list.
        Parameters:
        as - the list to which elements are prepended.
      • isEmpty

        public boolean isEmpty()
        Returns true if this buffer is empty, false otherwise.
      • toList

        public List<A> toList()
        Returns an immutable list projection of this buffer. Modifications to the underlying buffer will not be reflected in returned lists.
        Returns:
        An immutable list projection of this buffer.
      • toCollection

        public java.util.Collection<A> toCollection()
        Projects an immutable collection of this buffer.
        Returns:
        An immutable collection of this buffer.
      • empty

        public static <A> List.Buffer<A> empty()
        An empty buffer.
        Returns:
        An empty buffer.
      • fromList

        public static <A> List.Buffer<A> fromList​(List<A> as)
        Constructs a buffer from the given list.
        Parameters:
        as - The list to construct a buffer with.
        Returns:
        A buffer from the given list.
      • iterableBuffer

        public static <A> List.Buffer<A> iterableBuffer​(java.lang.Iterable<A> i)
        Takes the given iterable to a buffer.
        Parameters:
        i - The iterable to take to a buffer.
        Returns:
        A buffer from the given iterable.
      • copy

        private void copy()