org.geotools.resources
Class UnmodifiableArrayList<E>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<E>
          extended by org.geotools.resources.UnmodifiableArrayList<E>
Type Parameters:
E - The type of elements in the list.
All Implemented Interfaces:
java.io.Serializable, java.lang.Iterable<E>, java.util.Collection<E>, java.util.List<E>, CheckedCollection<E>

public class UnmodifiableArrayList<E>
extends java.util.AbstractList<E>
implements CheckedCollection<E>, java.io.Serializable

An unmodifiable view of an array. Invoking

UnmodifiableArrayList.wrap(array);
is equivalent to
Collections.unmodifiableList(Arrays.asList(array)));
But this class provides a very slight performance improvement since it uses one less level of indirection.

Since:
2.1
Version:
$Id: UnmodifiableArrayList.java 30640 2008-06-12 17:34:32Z acuster $
Author:
Martin Desruisseaux (IRD)
See Also:
Serialized Form

Field Summary
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
protected UnmodifiableArrayList(E[] array)
          Creates a new instance of an array list.
 
Method Summary
 boolean contains(java.lang.Object object)
          Returns true if this collection contains the specified element.
 E get(int index)
          Returns the element at the specified index.
 java.lang.Class<E> getElementType()
          Returns the element type of the wrapped array.
 int indexOf(java.lang.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.
 int lastIndexOf(java.lang.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.
 int size()
          Returns the list size.
static
<E> UnmodifiableArrayList<E>
wrap(E[] array)
          Creates a new instance of an array list.
 
Methods inherited from class java.util.AbstractList
add, add, addAll, clear, equals, hashCode, iterator, listIterator, listIterator, remove, removeRange, set, subList
 
Methods inherited from class java.util.AbstractCollection
addAll, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Collection
add, addAll, clear, containsAll, equals, hashCode, isEmpty, iterator, remove, removeAll, retainAll, toArray, toArray
 
Methods inherited from interface java.util.List
addAll, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray
 

Constructor Detail

UnmodifiableArrayList

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

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 java.lang.Class<E> getElementType()
Returns the element type of the wrapped array.

Specified by:
getElementType in interface CheckedCollection<E>
Returns:
The type of elements in the list.

size

public int size()
Returns the list size.

Specified by:
size in interface java.util.Collection<E>
Specified by:
size in interface java.util.List<E>
Specified by:
size in class java.util.AbstractCollection<E>

get

public E get(int index)
Returns the element at the specified index.

Specified by:
get in interface java.util.List<E>
Specified by:
get in class java.util.AbstractList<E>

indexOf

public int indexOf(java.lang.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).

Specified by:
indexOf in interface java.util.List<E>
Overrides:
indexOf in class java.util.AbstractList<E>
Parameters:
object - The element to search for.

lastIndexOf

public int lastIndexOf(java.lang.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:
lastIndexOf in interface java.util.List<E>
Overrides:
lastIndexOf in class java.util.AbstractList<E>
Parameters:
object - The element to searcch for.

contains

public boolean contains(java.lang.Object object)
Returns true if this collection contains the specified element. This method is overridden only for performance reason (the default implementation would work as well).

Specified by:
contains in interface java.util.Collection<E>
Specified by:
contains in interface java.util.List<E>
Overrides:
contains in class java.util.AbstractCollection<E>
Parameters:
object - The element to check for existence.


Copyright © 1996-2010 Geotools. All Rights Reserved.