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:
Serializable,Iterable<E>,Collection<E>,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>, 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.MutVector<F>-
Nested classes/interfaces inherited from interface org.organicdesign.fp.collections.UnmodIterable
UnmodIterable.UnIterable
-
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 @NotNull PersistentVector<E>append(E val)Inserts a new item at the end of the vector@NotNull PersistentVector<E>appendSome(@NotNull Fn0<? extends @NotNull Option<E>> supplier)If supplier returns Some, return a new BaseList with the additional item at the end.@NotNull PersistentVector<E>concat(@Nullable 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.MutVector<T>emptyMutable()Returns a new mutable vector.Eget(int i)Returns the item specified by the given index.@NotNull UnmodListIterator<E>listIterator(int index)Subclasses should override this when they can do so more efficiently.@NotNull PersistentVector.MutVector<E>mutable()Returns a mutable list (builder)static <T> PersistentVector<T>ofIter(Iterable<T> items)Public static factory method to create a vector from an Iterable.@NotNull 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 java.util.Collection
parallelStream, stream, toArray
-
Methods inherited from interface java.util.List
equals, hashCode, spliterator
-
Methods inherited from interface org.organicdesign.fp.xform.Transformable
any, toImList, toImMap, toImRrbt, toImSet, toImSortedMap, toImSortedSet, toMutList, toMutMap, toMutRrbt, toMutSet, toMutSortedMap, toMutSortedSet
-
-
-
-
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.MutVector<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(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
@NotNull public @NotNull PersistentVector.MutVector<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.
-
replace
@NotNull public @NotNull 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
@NotNull public @NotNull PersistentVector<E> append(E val)
Inserts a new item at the end of the vector
-
appendSome
@NotNull public @NotNull PersistentVector<E> appendSome(@NotNull @NotNull Fn0<? extends @NotNull Option<E>> supplier)
If supplier returns Some, return a new BaseList with the additional item at the end. If None, just return this BaseList unmodified.- Specified by:
appendSomein interfaceBaseList<E>- Specified by:
appendSomein interfaceImList<E>- Parameters:
supplier- returnOption.Someto append,Nonefor a no-op.
-
concat
@NotNull public @NotNull PersistentVector<E> concat(@Nullable @Nullable 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
@NotNull public @NotNull UnmodListIterator<E> listIterator(int index)
Subclasses should override this when they can do so more efficiently.- Specified by:
listIteratorin interfaceList<E>- Specified by:
listIteratorin interfaceUnmodList<E>
-
-