Package org.organicdesign.fp.collections
Class PersistentVector<E>
- java.lang.Object
-
- org.organicdesign.fp.collections.AbstractUnmodIterable<E>
-
- org.organicdesign.fp.collections.UnmodList.AbstractUnmodList<E>
-
- org.organicdesign.fp.collections.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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classPersistentVector.MutableVector<F>-
Nested classes/interfaces inherited from interface org.organicdesign.fp.collections.UnmodList
UnmodList.AbstractUnmodList<E>
-
-
Field Summary
Fields Modifier and Type Field Description static PersistentVector<?>EMPTY
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description PersistentVector<E>append(E val)Inserts a new item at the end of the Vecsicle.PersistentVector<E>concat(java.lang.Iterable<? extends E> items)Efficiently adds items to the end of this PersistentVector.static <T> PersistentVector<T>empty()Returns the empty ImList (there only needs to be one)static <T> PersistentVector.MutableVector<T>emptyMutable()Returns a new mutable vector.Eget(int i)Returns the item specified by the given index.UnmodListIterator<E>listIterator(int index)Subclasses should override this when they can do so more efficiently.PersistentVector.MutableVector<E>mutable()Returns a mutable list (builder)static <T> PersistentVector<T>ofIter(java.lang.Iterable<T> items)Public static factory method to create a vector from an Iterable.PersistentVector<E>replace(int i, E val)Replace the item at the given index.intsize()Returns the number of items in this collection or iterable.-
Methods inherited from class org.organicdesign.fp.collections.UnmodList.AbstractUnmodList
equals, hashCode
-
Methods inherited from class org.organicdesign.fp.collections.AbstractUnmodIterable
toString
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.organicdesign.fp.xform.Transformable
toImList, toImMap, toImRrbt, toImSet, toImSortedMap, toImSortedSet, toMutableList, toMutableMap, toMutableRrbt, toMutableSet, toMutableSortedMap, toMutableSortedSet
-
-
-
-
Field Detail
-
EMPTY
public static final PersistentVector<?> EMPTY
-
-
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...).
-
mutable
public PersistentVector.MutableVector<E> mutable()
Description copied from interface:ImListReturns a mutable list (builder)
-
get
public E get(int i)
Returns the item specified by the given index.- Specified by:
getin interfacejava.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.
-
size
public int size()
Returns the number of items in this collection or iterable.
-
append
public PersistentVector<E> append(E val)
Inserts a new item at the end of the Vecsicle.
-
concat
public PersistentVector<E> concat(java.lang.Iterable<? extends E> items)
Efficiently adds items to the end of this PersistentVector.- Specified by:
concatin interfaceBaseList<E>- Specified by:
concatin interfaceImList<E>- Specified by:
concatin interfaceTransformable<E>- Specified by:
concatin interfaceUnmodIterable<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:
listIteratorin interfacejava.util.List<E>- Specified by:
listIteratorin interfaceUnmodList<E>
-
-