Top Description Fields Constructors Methods
org.pcollections

public Class TreePVector<E>

extends AbstractUnmodifiableList<E>
implements PVector<E>, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, org.pcollections.PVector, org.pcollections.PSequence, java.util.List, java.util.SequencedCollection, java.util.Collection, java.lang.Iterable, org.pcollections.PCollection
Imports
java.io.Serializable, java.util.Collection, .Iterator, .Map.Entry, .Objects

A persistent vector of elements.

This implementation is backed by an IntTreePMap and supports logarithmic-time querying, setting, insertion, and removal.

This implementation is thread-safe (assuming Java's AbstractList is thread-safe) although its iterators may not be.

Null values are supported.

Author
harold

Field Summary

Modifier and TypeField and Description
private static final TreePVector<Object>
private final IntTreePMap<E>
private static final long

Constructor Summary

AccessConstructor and Description
private
TreePVector(final IntTreePMap<E> map)

Method Summary

Modifier and TypeMethod and Description
public static <E> TreePVector<E>

Returns:

an empty vector
empty
()

public static <E> TreePVector<E>

Returns:

empty().plusAll(list)
from
(final Collection<? extends E> list)

public E
get(final int
index of the element to return
index
)

Implements abstract java.util.AbstractList.get.

Implements java.util.List.get.

Returns the element at the specified position in this list.

public Iterator<E>
iterator()

Overrides java.util.AbstractList.iterator.

Implements java.util.Collection.iterator, java.util.List.iterator.

Returns an iterator over the elements in this list in proper sequence.

public TreePVector<E>
minus(final Object e)

Implements org.pcollections.PVector.minus.

Returns a sequence consisting of the elements of this without the first occurrence of e.

public TreePVector<E>
minus(final int i)

Implements org.pcollections.PVector.minus.

public TreePVector<E>
public TreePVector<E>
plus(final E e)

Implements org.pcollections.PVector.plus.

Returns a vector consisting of the elements of this with e appended.

public TreePVector<E>
plus(final int i, final E e)

Implements org.pcollections.PVector.plus.

public TreePVector<E>
plusAll(final Collection<? extends E> list)

Implements org.pcollections.PVector.plusAll.

Returns a vector consisting of the elements of this with list appended.

public TreePVector<E>
plusAll(int i, final Collection<? extends E> list)

Implements org.pcollections.PVector.plusAll.

public static <E> TreePVector<E>

Returns:

empty().plus(e)
singleton
(final E e)

public int
size()

Implements abstract java.util.AbstractCollection.size.

Implements java.util.Collection.size, java.util.List.size.

Returns the number of elements in this list.

public TreePVector<E>
subList(int
low endpoint (inclusive) of the subList
start
,
int
high endpoint (exclusive) of the subList
end
)

Overrides java.util.AbstractList.subList.

Implements org.pcollections.PVector.subList, java.util.List.subList.

Returns a view of the portion of this list between the specified fromIndex, inclusive, and toIndex, exclusive.

public PVector<E>
with(final int i, final E e)

Implements org.pcollections.PVector.with.

Inherited from org.pcollections.AbstractUnmodifiableList:
addaddaddAlladdAllclearremoveremoveremoveAllremoveIfreplaceAllretainAllsetsort

Field Detail

EMPTYback to summary
private static final TreePVector<Object> EMPTY
mapback to summary
private final IntTreePMap<E> map
serialVersionUIDback to summary
private static final long serialVersionUID

Constructor Detail

TreePVectorback to summary
private TreePVector(final IntTreePMap<E> map)

Method Detail

emptyback to summary
public static <E> TreePVector<E> empty()
Returns:TreePVector<E>

an empty vector

Annotations
@SuppressWarnings:unchecked
fromback to summary
public static <E> TreePVector<E> from(final Collection<? extends E> list)
Returns:TreePVector<E>

empty().plusAll(list)

Annotations
@SuppressWarnings:unchecked
getback to summary
public E get(final int index)

Implements abstract java.util.AbstractList.get.

Implements java.util.List.get.

Doc from java.util.List.get.

Returns the element at the specified position in this list.

Parameters
index:int

index of the element to return

Returns:E

the element at the specified position in this list

Annotations
@Override
iteratorback to summary
public Iterator<E> iterator()

Overrides java.util.AbstractList.iterator.

Implements java.util.Collection.iterator, java.util.List.iterator.

Doc from java.util.List.iterator.

Returns an iterator over the elements in this list in proper sequence.

Returns:Iterator<E>

an iterator over the elements in this list in proper sequence

Annotations
@Override
minusback to summary
public TreePVector<E> minus(final Object e)

Implements org.pcollections.PVector.minus.

Doc from org.pcollections.PSequence.minus.

Returns a sequence consisting of the elements of this without the first occurrence of e.

Returns:TreePVector<E>

Doc from org.pcollections.PCollection.minus.

this with a single instance of e removed, if e is in this

minusback to summary
public TreePVector<E> minus(final int i)

Implements org.pcollections.PVector.minus.

Returns:TreePVector<E>

Doc from org.pcollections.PSequence.minus.

a sequence consisting of the elements of this with the element at index i removed.

minusAllback to summary
public TreePVector<E> minusAll(final Collection<?> list)

Implements org.pcollections.PVector.minusAll.

Returns:TreePVector<E>

Doc from org.pcollections.PCollection.minusAll.

this with all elements of list completely removed

plusback to summary
public TreePVector<E> plus(final E e)

Implements org.pcollections.PVector.plus.

Doc from org.pcollections.PVector.plus.

Returns a vector consisting of the elements of this with e appended.

Returns:TreePVector<E>

Doc from org.pcollections.PCollection.plus.

a collection which contains e and all of the elements of this

plusback to summary
public TreePVector<E> plus(final int i, final E e)

Implements org.pcollections.PVector.plus.

Returns:TreePVector<E>

Doc from org.pcollections.PSequence.plus.

a sequence consisting of the elements of this with e inserted at index i.

plusAllback to summary
public TreePVector<E> plusAll(final Collection<? extends E> list)

Implements org.pcollections.PVector.plusAll.

Doc from org.pcollections.PVector.plusAll.

Returns a vector consisting of the elements of this with list appended.

Returns:TreePVector<E>

Doc from org.pcollections.PCollection.plusAll.

a collection which contains all of the elements of list and this

plusAllback to summary
public TreePVector<E> plusAll(int i, final Collection<? extends E> list)

Implements org.pcollections.PVector.plusAll.

Returns:TreePVector<E>

Doc from org.pcollections.PSequence.plusAll.

a sequence consisting of the elements of this with list inserted at index i.

singletonback to summary
public static <E> TreePVector<E> singleton(final E e)
Returns:TreePVector<E>

empty().plus(e)

sizeback to summary
public int size()

Implements abstract java.util.AbstractCollection.size.

Implements java.util.Collection.size, java.util.List.size.

Doc from java.util.List.size.

Returns the number of elements in this list. If this list contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.

Returns:int

the number of elements in this list

Annotations
@Override
subListback to summary
public TreePVector<E> subList(int start, int end)

Overrides java.util.AbstractList.subList.

Implements org.pcollections.PVector.subList, java.util.List.subList.

Doc from java.util.List.subList.

Returns a view of the portion of this list between the specified fromIndex, inclusive, and toIndex, exclusive. (If fromIndex and toIndex are equal, the returned list is empty.) The returned list is backed by this list, so non-structural changes in the returned list are reflected in this list, and vice-versa. The returned list supports all of the optional list operations supported by this list.

This method eliminates the need for explicit range operations (of the sort that commonly exist for arrays). Any operation that expects a list can be used as a range operation by passing a subList view instead of a whole list. For example, the following idiom removes a range of elements from a list:

list.subList(from, to).clear();
Similar idioms may be constructed for indexOf and lastIndexOf, and all of the algorithms in the Collections class can be applied to a subList.

The semantics of the list returned by this method become undefined if the backing list (i.e., this list) is structurally modified in any way other than via the returned list. (Structural modifications are those that change the size of this list, or otherwise perturb it in such a fashion that iterations in progress may yield incorrect results.)

Parameters
start:int

low endpoint (inclusive) of the subList

end:int

high endpoint (exclusive) of the subList

Returns:TreePVector<E>

a view of the specified range within this list

Annotations
@Override
withback to summary
public PVector<E> with(final int i, final E e)

Implements org.pcollections.PVector.with.

Returns:PVector<E>

Doc from org.pcollections.PSequence.with.

a sequence consisting of the elements of this with e replacing the element at index i.