Class ImmutableAbstractList<E>
- Type Parameters:
 E- the type of content of this List
- All Implemented Interfaces:
 Serializable,Iterable<E>,RandomAccess,ImmutableCollection<E>,ImmutableList<E>
- Direct Known Subclasses:
 ImmutableArrayList,ImmutableVector
public abstract class ImmutableAbstractList<E> extends ImmutableAbstractCollection<E> implements ImmutableList<E>, RandomAccess
Copyright (c) 2016-2020 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, Wouter Schakel
 - See Also:
 - Serialized Form
 
- 
Field Summary
 - 
Constructor Summary
Constructors Modifier Constructor Description protectedImmutableAbstractList(List<E> list, Immutable copyOrWrap)Construct an abstract immutable list. - 
Method Summary
Modifier and Type Method Description booleancontains(Object o)Returnstrueif this immutable collection contains the specified element.booleancontainsAll(Collection<?> c)Returnstrueif this immutable collection contains all of the elements in the specified collection.booleancontainsAll(ImmutableCollection<?> c)Returnstrueif this immutable collection contains all of the elements in the specified immutable collection.booleanequals(Object obj)Force to redefine equals for the implementations of immutable collection classes.voidforEach(Consumer<? super E> action)Eget(int index)Returns the element at the specified position in this immutable list.protected List<E>getUnderlyingCollection()Returns the underlying collection of this immutable collection.inthashCode()Force to redefine hashCode for the implementations of immutable collection classes.intindexOf(Object o)Returns the index of the first occurrence of the specified element in this immutable list, or -1 if this immutable list does not contain the element.booleanisEmpty()Returnstrueif this immutable collection contains no elements.booleanisWrap()Return whether the internal storage is a wrapped pointer to the original collection.ImmutableIterator<E>iterator()Returns an immutable iterator over the elements in this immutable collection.intlastIndexOf(Object o)Returns the index of the last occurrence of the specified element in this immutable list, or -1 if this immutable list does not contain the element.Stream<E>parallelStream()Returns a possibly parallelStreamwith this collection as its source.intsize()Returns the number of elements in this immutable collection.Spliterator<E>spliterator()Creates a Spliterator over the elements in this collection.Stream<E>stream()Returns a sequentialStreamwith this collection as its source.Object[]toArray()Returns an array containing all of the elements in this immutable collection.<T> T[]toArray(T[] a)Returns an array containing all of the elements in this immutable collection; the runtime type of the returned array is that of the specified array.Collection<E>toCollection()Returns a modifiable copy of this immutable collection.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.djutils.immutablecollections.ImmutableList
subList, toList, toString 
- 
Constructor Details
- 
ImmutableAbstractList
Construct an abstract immutable list. Make sure that the argument is a safe copy of the list or pointer to the list of the right type! Copying does not take place in the Abstract class!- Parameters:
 list- List<E>; a safe copy of the list, or pointer to the list to use for the immutable listcopyOrWrap- Immutable; indicate whether the immutable is a copy or a wrap
 
 - 
 - 
Method Details
- 
toCollection
Returns a modifiable copy of this immutable collection.- Specified by:
 toCollectionin interfaceImmutableCollection<E>- Returns:
 - a modifiable copy of this immutable collection.
 
 - 
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.- Specified by:
 getUnderlyingCollectionin classImmutableAbstractCollection<E>- Returns:
 - the underlying collection of this immutable collection.
 
 - 
size
public final int size()Returns the number of elements in this immutable collection. If this immutable collection contains more thanInteger.MAX_VALUEelements, returnsInteger.MAX_VALUE.- Specified by:
 sizein interfaceImmutableCollection<E>- Returns:
 - the number of elements in this immutable collection
 
 - 
isEmpty
public final boolean isEmpty()Returnstrueif this immutable collection contains no elements.- Specified by:
 isEmptyin interfaceImmutableCollection<E>- Returns:
 trueif this immutable collection contains no elements
 - 
contains
Returnstrueif this immutable collection contains the specified element. More formally, returnstrueif and only if this immutable collection contains at least one elementesuch that(o==null ? e==null : o.equals(e)).- Specified by:
 containsin interfaceImmutableCollection<E>- Parameters:
 o- Object; element whose presence in this immutable collection is to be tested- Returns:
 trueif this immutable collection contains the specified element
 - 
indexOf
Returns the index of the first occurrence of the specified element in this immutable list, or -1 if this immutable list does not contain the element. More formally, returns the lowest indexisuch that(o==null ? get(i)==null : o.equals(get(i))), or -1 if there is no such index.- Specified by:
 indexOfin interfaceImmutableList<E>- Parameters:
 o- Object; element to search for- Returns:
 - the index of the first occurrence of the specified element in this immutable list, or -1 if this immutable list does not contain the element
 
 - 
lastIndexOf
Returns the index of the last occurrence of the specified element in this immutable list, or -1 if this immutable list does not contain the element. More formally, returns the highest indexisuch that(o==null ? get(i)==null : o.equals(get(i))), or -1 if there is no such index.- Specified by:
 lastIndexOfin interfaceImmutableList<E>- Parameters:
 o- Object; element to search for- Returns:
 - the index of the last occurrence of the specified element in this immutable list, or -1 if this immutable list does not contain the element
 
 - 
toArray
Returns an array containing all of the elements in this immutable collection. If this immutable collection makes any guarantees as to what order its elements are returned by its iterator, this method must return the elements in the same order.See java.util.Collection.toArray() for more details.
- Specified by:
 toArrayin interfaceImmutableCollection<E>- Returns:
 - an array containing all of the elements in this immutable collection
 
 - 
toArray
public final <T> T[] toArray(T[] a)Returns an array containing all of the elements in this immutable collection; the runtime type of the returned array is that of the specified array. If the immutable collection fits in the specified array, it is returned therein. Otherwise, a new array is allocated with the runtime type of the specified array and the size of this immutable collection.See java.util.Collection.toArray(T[]) for more details.
- Specified by:
 toArrayin interfaceImmutableCollection<E>- Type Parameters:
 T- the runtime type of the array to contain the immutable collection- Parameters:
 a- the array into which the elements of this immutable collection are to be stored, if it is big enough; otherwise, a new array of the same runtime type is allocated for this purpose.- Returns:
 - an array containing all of the elements in this immutable collection
 
 - 
get
Returns the element at the specified position in this immutable list.- Specified by:
 getin interfaceImmutableList<E>- Parameters:
 index- int; index of the element to return- Returns:
 - the element at the specified position in this immutable list
 
 - 
iterator
Returns an immutable iterator over the elements in this immutable collection. There are no guarantees concerning the order in which the elements are returned (unless this immutable collection is an instance of some class that provides a guarantee). The ImmutableIterator is an Iterator where the remove() operation will throw an exception. - 
forEach
 - 
spliterator
Creates a Spliterator over the elements in this collection. Implementations should document characteristic values reported by the spliterator. See java.util.Collection for more information.- Specified by:
 spliteratorin interfaceImmutableCollection<E>- Specified by:
 spliteratorin interfaceIterable<E>- Returns:
 - a 
Spliteratorover the elements in this collection 
 - 
containsAll
Returnstrueif this immutable collection contains all of the elements in the specified collection.- Specified by:
 containsAllin interfaceImmutableCollection<E>- Parameters:
 c- Collection<?>; collection to be checked for containment in this immutable collection- Returns:
 trueif this immutable collection contains all of the elements in the specified collection- See Also:
 ImmutableCollection.contains(Object)
 - 
containsAll
Returnstrueif this immutable collection contains all of the elements in the specified immutable collection.- Specified by:
 containsAllin interfaceImmutableCollection<E>- Parameters:
 c- ImmutableCollection<?>; immutable collection to be checked for containment in this immutable collection- Returns:
 trueif this immutable collection contains all of the elements in the specified immutable collection- See Also:
 ImmutableCollection.contains(Object)
 - 
stream
Returns a sequentialStreamwith this collection as its source.This method should be overridden when the
ImmutableCollection.spliterator()method cannot return a spliterator that isIMMUTABLE,CONCURRENT, or late-binding. (SeeImmutableCollection.spliterator()for details.)- Specified by:
 streamin interfaceImmutableCollection<E>- Returns:
 - a sequential 
Streamover the elements in this collection 
 - 
parallelStream
Returns a possibly parallelStreamwith this collection as its source. It is allowable for this method to return a sequential stream.This method should be overridden when the
ImmutableCollection.spliterator()method cannot return a spliterator that isIMMUTABLE,CONCURRENT, or late-binding. (SeeImmutableCollection.spliterator()for details.)- Specified by:
 parallelStreamin interfaceImmutableCollection<E>- Returns:
 - a possibly parallel 
Streamover the elements in this collection 
 - 
isWrap
public final boolean isWrap()Return whether the internal storage is a wrapped pointer to the original collection. If true, this means that anyone holding a pointer to this data structure can still change it. The users of the ImmutableCollection itself can, however, not make any changes.- Specified by:
 isWrapin interfaceImmutableCollection<E>- Returns:
 - boolean; whether the internal storage is a wrapped pointer to the original collection
 
 - 
hashCode
public int hashCode()Force to redefine hashCode for the implementations of immutable collection classes.- Specified by:
 hashCodein interfaceImmutableCollection<E>- Specified by:
 hashCodein interfaceImmutableList<E>- Overrides:
 hashCodein classObject- Returns:
 - the calculated hashCode
 
 - 
equals
Force to redefine equals for the implementations of immutable collection classes.- Specified by:
 equalsin interfaceImmutableCollection<E>- Specified by:
 equalsin interfaceImmutableList<E>- Overrides:
 equalsin classObject- Parameters:
 obj- Object; the object to compare this collection with- Returns:
 - whether the objects are equal
 
 
 -