Package org.djutils.immutablecollections
Interface ImmutableList<E>
- Type Parameters:
- E- the type of content of this List
- All Superinterfaces:
- ImmutableCollection<E>,- Iterable<E>,- Serializable
- All Known Implementing Classes:
- ImmutableAbstractList,- ImmutableArrayList,- ImmutableVector
A List interface without the methods that can change it. The constructor of the ImmutableList needs to be given an initial
 List.
 
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
- 
Method SummaryModifier and TypeMethodDescriptionbooleanForce to redefine equals for the implementations of immutable collection classes.get(int index) Returns the element at the specified position in this immutable list.inthashCode()Force to redefine hashCode for the implementations of immutable collection classes.intReturns 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.intReturns 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.static <E> ImmutableList<E>of()Return an empty ImmutableList, backed by a ArrayList.static <E> ImmutableList<E>of(E v1) Return an ImmutableList with 1 entry, backed by a ArrayList.static <E> ImmutableList<E>of(E v1, E v2) Return an ImmutableList with 2 entries, backed by a ArrayList.static <E> ImmutableList<E>of(E v1, E v2, E v3) Return an ImmutableList with 3 entries, backed by a ArrayList.static <E> ImmutableList<E>of(E v1, E v2, E v3, E v4) Return an ImmutableList with 4 entries, backed by a ArrayList.static <E> ImmutableList<E>of(E v1, E v2, E v3, E v4, E v5, E... vn) Return an ImmutableList with 5 or more entries, backed by a ArrayList.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.toString()Force to redefine toString.Methods inherited from interface org.djutils.immutablecollections.ImmutableCollectioncontains, containsAll, containsAll, isCopy, isEmpty, isWrap, iterator, parallelStream, size, spliterator, stream, toArray, toArray, toCollection
- 
Method Details- 
getReturns the element at the specified position in this immutable list.- Parameters:
- index- index of the element to return
- Returns:
- the element at the specified position in this immutable list
- Throws:
- IndexOutOfBoundsException- if the index is out of range (- index < 0 || index >= size())
 
- 
indexOfReturns 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.- Parameters:
- o- 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
- Throws:
- ClassCastException- if the type of the specified element is incompatible with this immutable list
- NullPointerException- if the specified element is null and this immutable list does not permit null elements
 
- 
lastIndexOfReturns 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.- Parameters:
- o- 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
- Throws:
- ClassCastException- if the type of the specified element is incompatible with this immutable list
- NullPointerException- if the specified element is null and this immutable list does not permit null elements
 
- 
subListReturns 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 subList
- toIndex- high endpoint (exclusive) of the subList
- Returns:
- a view of the specified range within this immutable list
- Throws:
- IndexOutOfBoundsException- for an illegal endpoint index value (- fromIndex < 0 || toIndex > size || fromIndex > toIndex)
 
- 
toListReturns a modifiable copy of this immutable list.- Returns:
- a modifiable copy of this immutable list.
 
- 
equalsForce to redefine equals for the implementations of immutable collection classes.- Specified by:
- equalsin interface- ImmutableCollection<E>
- Overrides:
- equalsin class- Object
- Parameters:
- obj- the object to compare this collection with
- Returns:
- whether the objects are equal
 
- 
hashCodeint hashCode()Force to redefine hashCode for the implementations of immutable collection classes.- Specified by:
- hashCodein interface- ImmutableCollection<E>
- Overrides:
- hashCodein class- Object
- Returns:
- the calculated hashCode
 
- 
toStringString toString()Force to redefine toString.
- 
ofReturn an empty ImmutableList, backed by a ArrayList.- Type Parameters:
- E- the value type
- Returns:
- an empty ImmutableList
 
- 
ofReturn an ImmutableList with 1 entry, backed by a ArrayList.- Type Parameters:
- E- the value type
- Parameters:
- v1- value 1
- Returns:
- an ImmutableList with 1 entry, backed by a ArrayList
 
- 
ofReturn an ImmutableList with 2 entries, backed by a ArrayList.- Type Parameters:
- E- the value type
- Parameters:
- v1- value 1
- v2- value 2
- Returns:
- an ImmutableList with 2 entries, backed by a ArrayList
 
- 
ofReturn an ImmutableList with 3 entries, backed by a ArrayList.- Type Parameters:
- E- the value type
- Parameters:
- v1- value 1
- v2- value 2
- v3- value 3
- Returns:
- an ImmutableList with 3 entries, backed by a ArrayList
 
- 
ofReturn an ImmutableList with 4 entries, backed by a ArrayList.- Type Parameters:
- E- the value type
- Parameters:
- v1- value 1
- v2- value 2
- v3- value 3
- v4- value 4
- Returns:
- an ImmutableList with 4 entries, backed by a ArrayList
 
- 
ofReturn an ImmutableList with 5 or more entries, backed by a ArrayList.- Type Parameters:
- E- the value type
- Parameters:
- v1- value 1
- v2- value 2
- v3- value 3
- v4- value 4
- v5- value 5
- vn- values 6 and beyond
- Returns:
- an ImmutableList with 5 or more entries, backed by a ArrayList
 
 
-