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
public interface ImmutableList<E> extends ImmutableCollection<E>
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-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
-
Method Summary
Modifier and Type Method Description boolean
equals(Object obj)
Force to redefine equals for the implementations of immutable collection classes.E
get(int index)
Returns the element at the specified position in this immutable list.int
hashCode()
Force to redefine hashCode for the implementations of immutable collection classes.int
indexOf(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.int
lastIndexOf(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.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.List<E>
toList()
Returns a modifiable copy of this immutable list.String
toString()
Force to redefine toString.Methods inherited from interface org.djutils.immutablecollections.ImmutableCollection
contains, containsAll, containsAll, isCopy, isEmpty, isWrap, iterator, parallelStream, size, spliterator, stream, toArray, toArray, toCollection
-
Method Details
-
get
Returns the element at the specified position in this immutable list.- Parameters:
index
- int; 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()
)
-
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 indexi
such that(o==null ? get(i)==null : o.equals(get(i)))
, or -1 if there is no such index.- 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
- Throws:
ClassCastException
- if the type of the specified element is incompatible with this immutable listNullPointerException
- if the specified element is null and this immutable list does not permit null elements
-
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 indexi
such that(o==null ? get(i)==null : o.equals(get(i)))
, or -1 if there is no such index.- 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
- Throws:
ClassCastException
- if the type of the specified element is incompatible with this immutable listNullPointerException
- if the specified element is null and this immutable list does not permit null elements
-
subList
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
- Throws:
IndexOutOfBoundsException
- for an illegal endpoint index value (fromIndex < 0 || toIndex > size || fromIndex > toIndex
)
-
toList
Returns a modifiable copy of this immutable list.- Returns:
- a modifiable copy of this immutable list.
-
equals
Force to redefine equals for the implementations of immutable collection classes.- Specified by:
equals
in interfaceImmutableCollection<E>
- Overrides:
equals
in classObject
- Parameters:
obj
- Object; the object to compare this collection with- Returns:
- whether the objects are equal
-
hashCode
int hashCode()Force to redefine hashCode for the implementations of immutable collection classes.- Specified by:
hashCode
in interfaceImmutableCollection<E>
- Overrides:
hashCode
in classObject
- Returns:
- the calculated hashCode
-
toString
String toString()Force to redefine toString.
-