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 class
PersistentVector.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 PersistentVector<E>
append(E val)
Inserts a new item at the end of the Vecsicle.@NotNull PersistentVector<E>
concat(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.E
get(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.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.PersistentVector<E>
replace(int i, E val)
Replace the item at the given index.int
size()
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
public PersistentVector.MutVector<E> mutable()
Description copied from interface:ImList
Returns a mutable list (builder)
-
get
public E get(int i)
Returns the item specified by the given index.
-
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
@NotNull public @NotNull PersistentVector<E> concat(Iterable<? extends E> items)
Efficiently adds items to the end of this PersistentVector.- Specified by:
concat
in interfaceBaseList<E>
- Specified by:
concat
in interfaceImList<E>
- Specified by:
concat
in interfaceTransformable<E>
- Specified by:
concat
in 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:
listIterator
in interfaceList<E>
- Specified by:
listIterator
in interfaceUnmodList<E>
-
-