001    /*
002     * Licensed to the Apache Software Foundation (ASF) under one
003     * or more contributor license agreements.  See the NOTICE file
004     * distributed with this work for additional information
005     * regarding copyright ownership.  The ASF licenses this file
006     * to you under the Apache License, Version 2.0 (the
007     * "License"); you may not use this file except in compliance
008     * with the License.  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,
013     * software distributed under the License is distributed on an
014     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015     * KIND, either express or implied.  See the License for the
016     * specific language governing permissions and limitations
017     * under the License.
018     */
019    package org.apache.felix.framework.util;
020    
021    import java.util.Collection;
022    import java.util.Iterator;
023    
024    /** This collection wraps any other collection but prohibits calls to add
025     *  elements to the collection.
026     */
027    public class ShrinkableCollection implements Collection
028    {
029        private final Collection m_delegate;
030    
031        public ShrinkableCollection(Collection delegate)
032        {
033            m_delegate = delegate;
034        }
035    
036        public boolean add(Object o)
037        {
038            throw new UnsupportedOperationException();
039        }
040    
041        public boolean addAll(Collection c)
042        {
043            throw new UnsupportedOperationException();
044        }
045    
046        public void clear()
047        {
048            m_delegate.clear();
049        }
050    
051        public boolean contains(Object o)
052        {
053            return m_delegate.contains(o);
054        }
055    
056        public boolean containsAll(Collection c)
057        {
058            return m_delegate.containsAll(c);
059        }
060    
061        public boolean equals(Object o)
062        {
063            return m_delegate.equals(o);
064        }
065    
066        public int hashCode()
067        {
068            return m_delegate.hashCode();
069        }
070    
071        public boolean isEmpty()
072        {
073            return m_delegate.isEmpty();
074        }
075    
076        public Iterator iterator()
077        {
078            return m_delegate.iterator();
079        }
080    
081        public boolean remove(Object o)
082        {
083            return m_delegate.remove(o);
084        }
085    
086        public boolean removeAll(Collection c)
087        {
088            return m_delegate.removeAll(c);
089        }
090    
091        public boolean retainAll(Collection c)
092        {
093            return m_delegate.retainAll(c);
094        }
095    
096        public int size()
097        {
098            return m_delegate.size();
099        }
100    
101        public Object[] toArray()
102        {
103            return m_delegate.toArray();
104        }
105    
106        public Object[] toArray(Object[] a)
107        {
108            return m_delegate.toArray(a);
109        }
110    }