Class PersistentVector<E>

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Iterable<E>, java.util.Collection<E>, java.util.List<E>, BaseList<E>, ImList<E>, Sized, UnmodCollection<E>, UnmodIterable<E>, UnmodList<E>, UnmodSortedCollection<E>, UnmodSortedIterable<E>, Transformable<E>

    public class PersistentVector<E>
    extends UnmodList.AbstractUnmodList<E>
    implements ImList<E>, java.io.Serializable
    This started out as Rich Hickey's PersistentVector class from Clojure in late 2014. Glen added generic types, tried to make it a little more pure-Java friendly, and removed dependencies on other Clojure stuff. This file is a derivative work based on a Clojure collection licensed under the Eclipse Public License 1.0 Copyright Rich Hickey
    Author:
    Rich Hickey (Primary author), Glen Peterson (Java-centric editor)
    See Also:
    Serialized Form
    • Method Detail

      • empty

        public static <T> PersistentVector<T> empty()
        Returns the empty ImList (there only needs to be one)
      • emptyMutable

        public static <T> PersistentVector.MutableVector<T> emptyMutable()
        Returns a new mutable vector. For some reason calling empty().mutable() sometimes requires an explicit type parameter in Java, so this convenience method works around that.
      • ofIter

        public static <T> PersistentVector<T> ofIter​(java.lang.Iterable<T> items)
        Public static factory method to create a vector from an Iterable. A varargs version of this method is: StaticImports.vec(Object...).
      • get

        public E get​(int i)
        Returns the item specified by the given index.
        Specified by:
        get in interface java.util.List<E>
      • replace

        public PersistentVector<E> replace​(int i,
                                           E val)
        Replace the item at the given index. Note: i.replace(i.size(), o) used to be equivalent to i.concat(o), but it probably won't be for the RRB tree implementation, so this will change too.
        Specified by:
        replace in interface BaseList<E>
        Specified by:
        replace in interface ImList<E>
        Parameters:
        i - the index where the value should be stored.
        val - the value to store
        Returns:
        a new ImList with the replaced item
      • size

        public int size()
        Returns the number of items in this collection or iterable.
        Specified by:
        size in interface java.util.Collection<E>
        Specified by:
        size in interface java.util.List<E>
        Specified by:
        size in interface Sized
      • append

        public PersistentVector<E> append​(E val)
        Inserts a new item at the end of the Vecsicle.
        Specified by:
        append in interface BaseList<E>
        Specified by:
        append in interface ImList<E>
        Parameters:
        val - the value to insert
        Returns:
        a new Vecsicle with the additional item.
      • concat

        public PersistentVector<E> concat​(java.lang.Iterable<? extends E> items)
        Efficiently adds items to the end of this PersistentVector.
        Specified by:
        concat in interface BaseList<E>
        Specified by:
        concat in interface ImList<E>
        Specified by:
        concat in interface Transformable<E>
        Specified by:
        concat in interface UnmodIterable<E>
        Parameters:
        items - the values to insert
        Returns:
        a new PersistentVector with the additional items at the end.
      • listIterator

        public UnmodListIterator<E> listIterator​(int index)
        Subclasses should override this when they can do so more efficiently.
        Specified by:
        listIterator in interface java.util.List<E>
        Specified by:
        listIterator in interface UnmodList<E>