Package org.djutils.immutablecollections
Class ImmutableArrayList<E>
- java.lang.Object
-
- org.djutils.immutablecollections.ImmutableAbstractCollection<E>
-
- org.djutils.immutablecollections.ImmutableAbstractList<E>
-
- org.djutils.immutablecollections.ImmutableArrayList<E>
-
- Type Parameters:
E
- the type of content of this List
- All Implemented Interfaces:
Serializable
,Iterable<E>
,RandomAccess
,ImmutableCollection<E>
,ImmutableList<E>
public class ImmutableArrayList<E> extends ImmutableAbstractList<E>
An immutable wrapper for an ArrayList.Copyright (c) 2016-2021 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.
$, initial version May 7, 2016- Author:
- Alexander Verbraeck, Peter Knoppers
- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from class org.djutils.immutablecollections.ImmutableAbstractCollection
copyOrWrap
-
-
Constructor Summary
Constructors Constructor Description ImmutableArrayList(Collection<? extends E> collection)
ImmutableArrayList(List<E> list, Immutable copyOrWrap)
ImmutableArrayList(ImmutableAbstractCollection<? extends E> collection)
ImmutableArrayList(ImmutableAbstractList<E> list, Immutable copyOrWrap)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected List<E>
getUnderlyingCollection()
Returns the underlying collection of this immutable collection.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.ArrayList<E>
toList()
Returns a modifiable copy of this immutable list.String
toString()
Force to redefine toString.-
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, toCollection
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.djutils.immutablecollections.ImmutableCollection
isCopy
-
-
-
-
Constructor Detail
-
ImmutableArrayList
public ImmutableArrayList(Collection<? extends E> collection)
- Parameters:
collection
- Collection<? extends E>; the collection to use for the immutable list.
-
ImmutableArrayList
public ImmutableArrayList(List<E> list, Immutable copyOrWrap)
- Parameters:
list
- List<E>; the list to use for the immutable list.copyOrWrap
- COPY stores a safe, internal copy of the collection; WRAP stores a pointer to the original collection
-
ImmutableArrayList
public ImmutableArrayList(ImmutableAbstractCollection<? extends E> collection)
- Parameters:
collection
- ImmutableAbstractCollection<? extends E>; the collection to use for the immutable list.
-
ImmutableArrayList
public ImmutableArrayList(ImmutableAbstractList<E> list, Immutable copyOrWrap)
- Parameters:
list
- ImmutableAbstractList<E>; the list to use for the immutable list.copyOrWrap
- COPY stores a safe, internal copy of the collection; WRAP stores a pointer to the original collection
-
-
Method Detail
-
toList
public final ArrayList<E> toList()
Returns a modifiable copy of this immutable list.- Returns:
- a modifiable copy of this immutable list.
-
getUnderlyingCollection
protected List<E> getUnderlyingCollection()
Returns 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:
getUnderlyingCollection
in classImmutableAbstractList<E>
- Returns:
- the underlying collection of this immutable collection.
-
subList
public 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. (IffromIndex
andtoIndex
are equal, the returned immutable list is empty).- Parameters:
fromIndex
- int; low endpoint (inclusive) of the subListtoIndex
- int; high endpoint (exclusive) of the subList- Returns:
- a view of the specified range within this immutable list
-
-