Package org.djutils.immutablecollections
Class ImmutableVector<E>
java.lang.Object
org.djutils.immutablecollections.ImmutableAbstractCollection<E>
org.djutils.immutablecollections.ImmutableAbstractList<E>
org.djutils.immutablecollections.ImmutableVector<E>
- Type Parameters:
 E- the type of content of this ImmutableVector
- All Implemented Interfaces:
 Iterable<E>,RandomAccess,ImmutableCollection<E>,ImmutableList<E>
An immutable wrapper for a Vector.
 
Copyright (c) 2016-2025 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See for project information https://djutils.org. The DJUTILS project is distributed under a three-clause BSD-style license, which can be found at https://djutils.org/docs/license.html.
- Author:
 - Alexander Verbraeck, Peter Knoppers
 
- 
Field Summary
Fields inherited from class org.djutils.immutablecollections.ImmutableAbstractCollection
copyOrWrap - 
Constructor Summary
ConstructorsConstructorDescriptionImmutableVector(Collection<? extends E> collection) ImmutableVector(Vector<E> vector, Immutable copyOrWrap) ImmutableVector(ImmutableAbstractCollection<? extends E> collection) ImmutableVector(ImmutableVector<E> vector, Immutable copyOrWrap)  - 
Method Summary
Modifier and TypeMethodDescriptionfinal intcapacity()Returns the current capacity of this immutable vector.final voidCopies the components of this immutable vector into the specified array.final EelementAt(int index) Returns the component at the specified index.final Enumeration<E>elements()Returns an enumeration of the components of this vector.final EReturns the first component (the item at index0) of this immutable vector.Returns the underlying collection of this immutable collection.final intReturns the index of the first occurrence of the specified element in this immutable vector, searching forwards fromindex, or returns -1 if the element is not found.final EReturns the last component of the immutable vector.final intlastIndexOf(Object o, int index) Returns the index of the last occurrence of the specified element in this immutable vector, searching backwards fromindex, or returns -1 if the element is not found.final ImmutableList<E>subList(int fromIndex, int toIndex) Returns a safe, immutable copy of the portion of this immutable list between the specifiedfromIndex, inclusive, andtoIndex, exclusive.toList()Returns a modifiable copy of this immutable list.final StringtoString()Force to redefine toString.toVector()Returns a modifiable copy of this immutable vector.Methods inherited from class org.djutils.immutablecollections.ImmutableAbstractList
contains, containsAll, containsAll, equals, forEach, get, hashCode, indexOf, isEmpty, isWrap, iterator, lastIndexOf, parallelStream, size, spliterator, stream, toArray, toArray, toCollectionMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.djutils.immutablecollections.ImmutableCollection
isCopy 
- 
Constructor Details
- 
ImmutableVector
- Parameters:
 collection- the collection to use for the immutable vector.
 - 
ImmutableVector
- Parameters:
 vector- the vector to use for the immutable vector.copyOrWrap- WRAP stores a pointer to the original collection
 - 
ImmutableVector
- Parameters:
 collection- the immutable collection to use for the immutable vector.
 - 
ImmutableVector
- Parameters:
 vector- the vector to use for the immutable vector.copyOrWrap- WRAP stores a pointer to the original collection
 
 - 
 - 
Method Details
- 
toList
Description copied from interface:ImmutableListReturns a modifiable copy of this immutable list.- Returns:
 - a modifiable copy of this immutable list.
 
 - 
toVector
Returns a modifiable copy of this immutable vector.- Returns:
 - a modifiable copy of this immutable vector.
 
 - 
getUnderlyingCollection
Description copied from class:ImmutableAbstractCollectionReturns the underlying collection of this immutable collection. In case of Immutable.WRAP, this will be the original collection. In case of IMMUTABLE.COPY, this will be the internally stored (mutable) copy of the collection.- Overrides:
 getUnderlyingCollectionin classImmutableAbstractList<E>- Returns:
 - the underlying collection of this immutable collection.
 
 - 
subList
Description copied from interface:ImmutableListReturns a safe, immutable copy of the portion of this immutable list between the specifiedfromIndex, inclusive, andtoIndex, exclusive. (IffromIndexandtoIndexare equal, the returned immutable list is empty).- Parameters:
 fromIndex- low endpoint (inclusive) of the subListtoIndex- high endpoint (exclusive) of the subList- Returns:
 - a view of the specified range within this immutable list
 
 - 
copyInto
Copies the components of this immutable vector into the specified array. The item at indexkin this immutable vector is copied into componentkofanArray.- Parameters:
 anArray- the array into which the components get copied- Throws:
 NullPointerException- if the given array is nullIndexOutOfBoundsException- if the specified array is not large enough to hold all the components of this immutable vectorArrayStoreException- if a component of this immutable vector is not of a runtime type that can be stored in the specified array- See Also:
 
 - 
capacity
public final int capacity()Returns the current capacity of this immutable vector.- Returns:
 - the current capacity of this immutable vector.
 
 - 
elements
Returns an enumeration of the components of this vector. The returnedEnumerationobject will generate all items in this vector. The first item generated is the item at index0, then the item at index1, and so on.- Returns:
 - an enumeration of the components of this vector
 - See Also:
 
 - 
indexOf
Returns the index of the first occurrence of the specified element in this immutable vector, searching forwards fromindex, or returns -1 if the element is not found. More formally, returns the lowest indexisuch that(i >= index && (o==null ? get(i)==null : o.equals(get(i)))), or -1 if there is no such index.- Parameters:
 o- element to search forindex- index to start searching from- Returns:
 - the index of the first occurrence of the element in this immutable vector at position 
indexor later in the vector;-1if the element is not found. - Throws:
 IndexOutOfBoundsException- if the specified index is negative- See Also:
 
 - 
lastIndexOf
Returns the index of the last occurrence of the specified element in this immutable vector, searching backwards fromindex, or returns -1 if the element is not found. More formally, returns the highest indexisuch that(i <= index && (o==null ? get(i)==null : o.equals(get(i)))), or -1 if there is no such index.- Parameters:
 o- element to search forindex- index to start searching backwards from- Returns:
 - the index of the last occurrence of the element at position less than or equal to 
indexin this immutable vector; -1 if the element is not found. - Throws:
 IndexOutOfBoundsException- if the specified index is greater than or equal to the current size of this immutable vector
 - 
elementAt
Returns the component at the specified index.This method is identical in functionality to the
ImmutableAbstractList.get(int)method (which is part of theListinterface).- Parameters:
 index- an index into this immutable vector- Returns:
 - the component at the specified index
 - Throws:
 ArrayIndexOutOfBoundsException- if the index is out of range (index < 0 || index >= size())
 - 
firstElement
Returns the first component (the item at index0) of this immutable vector.- Returns:
 - the first component of this immutable vector
 - Throws:
 NoSuchElementException- if this immutable vector has no components
 - 
lastElement
Returns the last component of the immutable vector.- Returns:
 - the last component of the immutable vector, i.e., the component at index 
size() - 1. - Throws:
 NoSuchElementException- if this immutable vector is empty
 - 
toString
Description copied from interface:ImmutableListForce to redefine toString.- Specified by:
 toStringin interfaceImmutableList<E>- Overrides:
 toStringin classObject- Returns:
 - a description of this immutable list
 
 
 -