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:
java.io.Serializable, java.lang.Iterable<E>, java.util.Collection<E>, java.util.List<E>

public class UnmodifiableList<E>
extends UnmodifiableCollection<E>
implements java.util.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(java.util.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, java.util.Collection<? extends E> arg1)
          Operation is not supported.
 E get(int index)
          
 int indexOf(java.lang.Object o)
          
 int lastIndexOf(java.lang.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.
 java.util.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(java.util.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 java.util.List<E>

indexOf

public int indexOf(java.lang.Object o)

Specified by:
indexOf in interface java.util.List<E>

lastIndexOf

public int lastIndexOf(java.lang.Object o)

Specified by:
lastIndexOf in interface java.util.List<E>

listIterator

public UnmodifiableListIterator<E> listIterator()

Specified by:
listIterator in interface java.util.List<E>

listIterator

public UnmodifiableListIterator<E> listIterator(int index)

Specified by:
listIterator in interface java.util.List<E>

subList

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

Specified by:
subList in interface java.util.List<E>

add

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

Specified by:
add in interface java.util.List<E>
Throws:
java.lang.UnsupportedOperationException

addAll

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

Specified by:
addAll in interface java.util.List<E>
Throws:
java.lang.UnsupportedOperationException

remove

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

Specified by:
remove in interface java.util.List<E>
Throws:
java.lang.UnsupportedOperationException

set

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

Specified by:
set in interface java.util.List<E>
Throws:
java.lang.UnsupportedOperationException

TUM CCSM Commons

TUM CCSM Commons - 2.7