TUM CCSM Commons

edu.tum.cs.commons.collections
Class UnmodifiableList<E>

java.lang.Object
  extended by edu.tum.cs.commons.collections.UnmodifiableCollection<E>
      extended by edu.tum.cs.commons.collections.UnmodifiableList<E>
All Implemented Interfaces:
Serializable, Iterable<E>, Collection<E>, List<E>

public class UnmodifiableList<E>
extends UnmodifiableCollection<E>
implements List<E>

This is a wrapper for a List prohibiting all calls which would modify its contents. As the construction of this class is performed in constant time it is prefered over copying the list (which takes linear time). Using this class is also preferred to using the unmodifiableX() in class Collections as they return the collection base type that does not signal, that the object ist unmodifiable. Using the classes in this package makes unmodifiability more explicit.

All prohibited methods throw an UnsupportedOperationException. The class is nearly the same as the one returned by Collections.unmodifiableList(List), but by making it a public class we can make the return value of some methods more explicit.

This list is serializable if the wrapped list is serializable.

Version:
$Revision: 26283 $
Author:
Benjamin Hummel, $Author: juergens $
See Also:
Serialized Form
Rating:
GREEN Hash: 4B2E02522B37EA43AB9DDF9C28DCC2E1

Constructor Summary
UnmodifiableList(List<E> l)
          Creates a new unmodifiable list from another list.
 
Method Summary
 void add(int arg0, E arg1)
          Operation is not supported.
 boolean addAll(int arg0, Collection<? extends E> arg1)
          Operation is not supported.
 E get(int index)
          
 int indexOf(Object o)
          
 int lastIndexOf(Object o)
          
 UnmodifiableListIterator<E> listIterator()
          
 UnmodifiableListIterator<E> listIterator(int index)
          
 E remove(int arg0)
          Operation is not supported.
 E set(int arg0, E arg1)
          Operation is not supported.
 List<E> subList(int fromIndex, int toIndex)
          
 
Methods inherited from class edu.tum.cs.commons.collections.UnmodifiableCollection
add, addAll, clear, contains, containsAll, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
add, addAll, clear, contains, containsAll, equals, hashCode, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray
 

Constructor Detail

UnmodifiableList

public UnmodifiableList(List<E> l)
Creates a new unmodifiable list from another list. All modifications to the underlying list will directly be visible in this wrapper.

Method Detail

get

public E get(int index)

Specified by:
get in interface List<E>

indexOf

public int indexOf(Object o)

Specified by:
indexOf in interface List<E>

lastIndexOf

public int lastIndexOf(Object o)

Specified by:
lastIndexOf in interface List<E>

listIterator

public UnmodifiableListIterator<E> listIterator()

Specified by:
listIterator in interface List<E>

listIterator

public UnmodifiableListIterator<E> listIterator(int index)

Specified by:
listIterator in interface List<E>

subList

public List<E> subList(int fromIndex,
                       int toIndex)

Specified by:
subList in interface List<E>

add

public void add(int arg0,
                E arg1)
Operation is not supported.

Specified by:
add in interface List<E>
Throws:
UnsupportedOperationException

addAll

public boolean addAll(int arg0,
                      Collection<? extends E> arg1)
Operation is not supported.

Specified by:
addAll in interface List<E>
Throws:
UnsupportedOperationException

remove

public E remove(int arg0)
Operation is not supported.

Specified by:
remove in interface List<E>
Throws:
UnsupportedOperationException

set

public E set(int arg0,
             E arg1)
Operation is not supported.

Specified by:
set in interface List<E>
Throws:
UnsupportedOperationException

TUM CCSM Commons

TUM CCSM Commons - 2.7