Package org.geotools.util
Class UnmodifiableArrayList<E>
- Object
-
- AbstractCollection<E>
-
- AbstractList<E>
-
- UnmodifiableArrayList<E>
-
- Type Parameters:
E- The type of elements in the list.
- All Implemented Interfaces:
Serializable,Iterable<E>,Collection<E>,List<E>,CheckedCollection<E>
public class UnmodifiableArrayList<E> extends AbstractList<E> implements CheckedCollection<E>, Serializable
An unmodifiable view of an array. Invoking
is equivalent toUnmodifiableArrayList.wrap(array);
But this class provides a very slight performance improvement since it uses one less level of indirection.Collections.unmodifiableList(Arrays.asList(array)));- Since:
- 2.1
- Author:
- Martin Desruisseaux (IRD)
- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from class AbstractList
modCount
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedUnmodifiableArrayList(E... array)Creates a new instance of an array list.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancontains(Object object)Returnstrueif this collection contains the specified element.Eget(int index)Returns the element at the specified index.Class<E>getElementType()Returns the element type of the wrapped array.intindexOf(Object object)Returns the index in this list of the first occurence of the specified element, or -1 if the list does not contain this element.intlastIndexOf(Object object)Returns the index in this list of the last occurence of the specified element, or -1 if the list does not contain this element.intsize()Returns the list size.static <E> UnmodifiableArrayList<E>wrap(E... array)Creates a new instance of an array list.-
Methods inherited from class AbstractList
add, add, addAll, clear, equals, hashCode, iterator, listIterator, listIterator, remove, removeRange, set, subList
-
Methods inherited from class AbstractCollection
addAll, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
-
Methods inherited from interface Collection
parallelStream, removeIf, stream, toArray
-
Methods inherited from interface List
addAll, containsAll, isEmpty, remove, removeAll, replaceAll, retainAll, sort, spliterator, toArray, toArray
-
-
-
-
Constructor Detail
-
UnmodifiableArrayList
@SafeVarargs protected UnmodifiableArrayList(E... array)
Creates a new instance of an array list. A direct reference to the given array is retained (i.e. the array is not cloned). Consequently the given array should not be modified after construction if this list is intented to be immutable.This constructor is for subclassing only. Users should invoke the
wrap(E...)static factory method, which provides more convenient handling of parameterized types.- Parameters:
array- The array to wrap.
-
-
Method Detail
-
wrap
@SafeVarargs public static <E> UnmodifiableArrayList<E> wrap(E... array)
Creates a new instance of an array list. A direct reference to the given array is retained (i.e. the array is not cloned). Consequently the given array should not be modified after construction if this list is intented to be immutable.- Type Parameters:
E- The type of elements in the list.- Parameters:
array- The array to wrap.- Returns:
- The given array wrapped in an unmodifiable list.
- Since:
- 2.5
-
getElementType
public Class<E> getElementType()
Returns the element type of the wrapped array.- Specified by:
getElementTypein interfaceCheckedCollection<E>- Returns:
- The type of elements in the list.
-
size
public int size()
Returns the list size.- Specified by:
sizein interfaceCollection<E>- Specified by:
sizein interfaceList<E>- Specified by:
sizein classAbstractCollection<E>
-
get
public E get(int index)
Returns the element at the specified index.
-
indexOf
public int indexOf(Object object)
Returns the index in this list of the first occurence of the specified element, or -1 if the list does not contain this element. This method is overridden only for performance reason (the default implementation would work as well).
-
lastIndexOf
public int lastIndexOf(Object object)
Returns the index in this list of the last occurence of the specified element, or -1 if the list does not contain this element. This method is overridden only for performance reason (the default implementation would work as well).- Specified by:
lastIndexOfin interfaceList<E>- Overrides:
lastIndexOfin classAbstractList<E>- Parameters:
object- The element to searcch for.
-
contains
public boolean contains(Object object)
Returnstrueif this collection contains the specified element. This method is overridden only for performance reason (the default implementation would work as well).- Specified by:
containsin interfaceCollection<E>- Specified by:
containsin interfaceList<E>- Overrides:
containsin classAbstractCollection<E>- Parameters:
object- The element to check for existence.
-
-