TUM CCSM Commons

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

java.lang.Object
  extended by edu.tum.cs.commons.collections.UnmodifiableCollection<E>
All Implemented Interfaces:
java.io.Serializable, java.lang.Iterable<E>, java.util.Collection<E>
Direct Known Subclasses:
UnmodifiableList, UnmodifiableSet

public class UnmodifiableCollection<E>
extends java.lang.Object
implements java.util.Collection<E>, java.io.Serializable

This is a wrapper for a Collection prohibiting all calls which would modify its contents. As the construction of this class is performed in constant time it is preferred over copying the collection (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 is 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.unmodifiableCollection(Collection), but by making it a public class we can make the return value of some methods more explicit.

This collection is serializable if the wrapped collection is serializable.

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

Constructor Summary
UnmodifiableCollection(java.util.Collection<E> c)
          Creates a new unmodifiable collection from another collection.
 
Method Summary
 boolean add(E arg0)
          Operation is not supported.
 boolean addAll(java.util.Collection<? extends E> arg0)
          Operation is not supported.
 void clear()
          Operation is not supported.
 boolean contains(java.lang.Object o)
          
 boolean containsAll(java.util.Collection<?> other)
          
 boolean isEmpty()
          
 UnmodifiableIterator<E> iterator()
          
 boolean remove(java.lang.Object arg0)
          Operation is not supported.
 boolean removeAll(java.util.Collection<?> arg0)
          Operation is not supported.
 boolean retainAll(java.util.Collection<?> arg0)
          Operation is not supported.
 int size()
          
 java.lang.Object[] toArray()
          
<T> T[]
toArray(T[] a)
          
 java.lang.String toString()
          Returns a string representation of this collection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Collection
equals, hashCode
 

Constructor Detail

UnmodifiableCollection

public UnmodifiableCollection(java.util.Collection<E> c)
Creates a new unmodifiable collection from another collection. All modifications to the underlying collection will directly be visible in this wrapper.

Method Detail

isEmpty

public boolean isEmpty()

Specified by:
isEmpty in interface java.util.Collection<E>

size

public int size()

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

contains

public boolean contains(java.lang.Object o)

Specified by:
contains in interface java.util.Collection<E>

containsAll

public boolean containsAll(java.util.Collection<?> other)

Specified by:
containsAll in interface java.util.Collection<E>

iterator

public UnmodifiableIterator<E> iterator()

Specified by:
iterator in interface java.lang.Iterable<E>
Specified by:
iterator in interface java.util.Collection<E>

toArray

public java.lang.Object[] toArray()

Specified by:
toArray in interface java.util.Collection<E>

toArray

public <T> T[] toArray(T[] a)

Specified by:
toArray in interface java.util.Collection<E>

add

public boolean add(E arg0)
Operation is not supported.

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

addAll

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

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

clear

public void clear()
Operation is not supported.

Specified by:
clear in interface java.util.Collection<E>
Throws:
java.lang.UnsupportedOperationException

remove

public boolean remove(java.lang.Object arg0)
Operation is not supported.

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

removeAll

public boolean removeAll(java.util.Collection<?> arg0)
Operation is not supported.

Specified by:
removeAll in interface java.util.Collection<E>
Throws:
java.lang.UnsupportedOperationException

retainAll

public boolean retainAll(java.util.Collection<?> arg0)
Operation is not supported.

Specified by:
retainAll in interface java.util.Collection<E>
Throws:
java.lang.UnsupportedOperationException

toString

public java.lang.String toString()
Returns a string representation of this collection.

Overrides:
toString in class java.lang.Object

TUM CCSM Commons

TUM CCSM Commons - 2.7