001    /*--------------------------------------------------------------------------+
002    $Id: UnmodifiableSet.java 26283 2010-02-18 11:18:57Z juergens $
003    |                                                                          |
004    | Copyright 2005-2010 Technische Universitaet Muenchen                     |
005    |                                                                          |
006    | Licensed under the Apache License, Version 2.0 (the "License");          |
007    | you may not use this file except in compliance with the License.         |
008    | You may obtain a copy of the License at                                  |
009    |                                                                          |
010    |    http://www.apache.org/licenses/LICENSE-2.0                            |
011    |                                                                          |
012    | Unless required by applicable law or agreed to in writing, software      |
013    | distributed under the License is distributed on an "AS IS" BASIS,        |
014    | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
015    | See the License for the specific language governing permissions and      |
016    | limitations under the License.                                           |
017    +--------------------------------------------------------------------------*/
018    package edu.tum.cs.commons.collections;
019    
020    import java.util.Collections;
021    import java.util.Set;
022    
023    /**
024     * This is a wrapper for a {@link Set} prohibiting all calls which would modify
025     * its contents. As the construction of this class is performed in constant time
026     * it is prefered over copying the set (which takes linear time). Using this
027     * class is also preferred to using the <code>unmodifiableX()</code> in class
028     * {@link Collections} as they return the collection base type that does not
029     * signal, that the object ist unmodifiable. Using the classes in this package
030     * makes unmodifiability more explicit.
031     * <p>
032     * All prohibited methods throw an {@link UnsupportedOperationException}. The
033     * class is nearly the same as the one returned by
034     * {@link Collections#unmodifiableSet(java.util.Set)}, but by making it a
035     * public class we can make the return value of some methods more explicit.
036     * 
037     * @author Benjamin Hummel
038     * @author $Author: juergens $
039     * 
040     * @version $Revision: 26283 $
041     * @levd.rating GREEN Hash: 1221FC9A0B5282EB5A1323A35B955157
042     */
043    public class UnmodifiableSet<E> extends UnmodifiableCollection<E> implements
044                    Set<E> {
045    
046            /**
047             * Creates a new unmodifiable set from another set. All modifications to the
048             * underlying set will directly be visible in this wrapper.
049             */
050            public UnmodifiableSet(Set<E> s) {
051                    super(s);
052            }
053    }