View Javadoc

1   /*
2    * File: ImmutableCollection.java
3    * Created: 11-čen-06 6:55:40 
4    *
5    * Copyright 2006 Michal Burda.
6    *
7    * This program is free software; you can redistribute it and/or modify
8    * it under the terms of the GNU General Public License as published by
9    * the Free Software Foundation; either version 2 of the License, or
10   * (at your option) any later version.
11   *
12   * This program is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   * GNU General Public License for more details.
16   *
17   * You should have received a copy of the GNU General Public License
18   * along with this program; if not, write to the Free Software
19   * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20   */
21  package net.sf.webmancer.util.immutable;
22  
23  import java.util.Collection;
24  import java.util.Iterator;
25  
26  /**
27   * @author Michal Burda
28   * @param <T>
29   */
30  public final class ImmutableCollection<T> implements Collection<T> {
31      private Collection<? extends T> collection;
32  
33      /**
34       * @param collection
35       */
36      public ImmutableCollection(final Collection<? extends T> collection) {
37          super();
38          this.collection = collection;
39      }
40  
41      /**
42       * @see java.util.Collection#containsAll(java.util.Collection)
43       */
44      public boolean containsAll(final Collection<?> c) {
45          return this.collection.containsAll(c);
46      }
47  
48      /**
49       * @see java.util.Collection#contains(java.lang.Object)
50       */
51      public boolean contains(final Object o) {
52          return this.collection.contains(o);
53      }
54  
55      /**
56       * @see java.util.Collection#equals(java.lang.Object)
57       */
58      @Override
59      public boolean equals(final Object o) {
60          return this.collection.equals(o);
61      }
62  
63      /**
64       * @see java.util.Collection#hashCode()
65       */
66      @Override
67      public int hashCode() {
68          return this.collection.hashCode();
69      }
70  
71      /**
72       * @see java.util.Collection#isEmpty()
73       */
74      public boolean isEmpty() {
75          return this.collection.isEmpty();
76      }
77  
78      /**
79       * @see java.util.Collection#size()
80       */
81      public int size() {
82          return this.collection.size();
83      }
84  
85      /**
86       * @see java.util.Collection#toArray(T[])
87       */
88      public <K> K[] toArray(final K[] a) {
89          return this.collection.toArray(a);
90      }
91  
92      /**
93       * @see java.util.Collection#toArray()
94       */
95      public Object[] toArray() {
96          return this.collection.toArray();
97      }
98  
99      /**
100      * @see java.util.Collection#iterator()
101      */
102     public Iterator<T> iterator() {
103         return new ImmutableIterator<T>(this.collection.iterator());
104     }
105 
106     /**
107      * @see java.util.Collection#add(E)
108      */
109     public boolean add(final T o) {
110         throw new UnsupportedOperationException("ImmutableCollection.add");
111     }
112 
113     /**
114      * @see java.util.Collection#remove(java.lang.Object)
115      */
116     public boolean remove(final Object o) {
117         throw new UnsupportedOperationException("ImmutableCollection.remove");
118     }
119 
120     /**
121      * @see java.util.Collection#addAll(java.util.Collection)
122      */
123     public boolean addAll(final Collection<? extends T> c) {
124         throw new UnsupportedOperationException("ImmutableCollection.addAll");
125     }
126 
127     /**
128      * @see java.util.Collection#removeAll(java.util.Collection)
129      */
130     public boolean removeAll(final Collection<?> c) {
131         throw new UnsupportedOperationException("ImmutableCollection.removeAll");
132     }
133 
134     /**
135      * @see java.util.Collection#retainAll(java.util.Collection)
136      */
137     public boolean retainAll(final Collection<?> c) {
138         throw new UnsupportedOperationException("ImmutableCollection.retainAll");
139     }
140 
141     /**
142      * @see java.util.Collection#clear()
143      */
144     public void clear() {
145         throw new UnsupportedOperationException("ImmutableCollection.clear");
146     }
147 
148 }