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