View Javadoc

1   /*
2    * File: ImmutableList.java
3    * Created: 11-čen-06 7:39:20 
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  import java.util.List;
26  import java.util.ListIterator;
27  
28  /**
29   * @author Michal Burda
30   * @param <T>
31   */
32  public final class ImmutableList<T> implements List<T> {
33      private List<? extends T> list;
34  
35      /**
36       * 
37       */
38      public ImmutableList(final List<? extends T> list) {
39          super();
40          this.list = list;
41      }
42  
43      /**
44       * @see java.util.List#containsAll(java.util.Collection)
45       */
46      public boolean containsAll(final Collection<?> c) {
47          return this.list.containsAll(c);
48      }
49  
50      /**
51       * @see java.util.List#contains(java.lang.Object)
52       */
53      public boolean contains(final Object o) {
54          return this.list.contains(o);
55      }
56  
57      /**
58       * @see java.util.List#equals(java.lang.Object)
59       */
60      @Override
61      public boolean equals(final Object o) {
62          return this.list.equals(o);
63      }
64  
65      /**
66       * @see java.util.List#get(int)
67       */
68      public T get(final int index) {
69          return this.list.get(index);
70      }
71  
72      /**
73       * @see java.util.List#hashCode()
74       */
75      @Override
76      public int hashCode() {
77          return this.list.hashCode();
78      }
79  
80      /**
81       * @see java.util.List#indexOf(java.lang.Object)
82       */
83      public int indexOf(final Object o) {
84          return this.list.indexOf(o);
85      }
86  
87      /**
88       * @see java.util.List#isEmpty()
89       */
90      public boolean isEmpty() {
91          return this.list.isEmpty();
92      }
93  
94      /**
95       * @see java.util.List#lastIndexOf(java.lang.Object)
96       */
97      public int lastIndexOf(final Object o) {
98          return this.list.lastIndexOf(o);
99      }
100 
101     /**
102      * @see java.util.List#size()
103      */
104     public int size() {
105         return this.list.size();
106     }
107 
108     /**
109      * @see java.util.List#subList(int, int)
110      */
111     public List<T> subList(final int fromIndex, final int toIndex) {
112         return new ImmutableList<T>(this.list.subList(fromIndex, toIndex));
113     }
114 
115     /**
116      * @see java.util.List#toArray(T[])
117      */
118     public <K> K[] toArray(final K[] a) {
119         return this.list.toArray(a);
120     }
121 
122     /**
123      * @see java.util.List#toArray()
124      */
125     public Object[] toArray() {
126         return this.list.toArray();
127     }
128 
129     /**
130      * @see java.util.List#iterator()
131      */
132     public Iterator<T> iterator() {
133         return new ImmutableIterator<T>(this.list.iterator());
134     }
135 
136     /**
137      * @see java.util.List#add(E)
138      */
139     public boolean add(final T o) {
140         throw new UnsupportedOperationException("ImmutableList.add");
141     }
142 
143     /**
144      * @see java.util.List#remove(java.lang.Object)
145      */
146     public boolean remove(final Object o) {
147         throw new UnsupportedOperationException("ImmutableList.remove");
148     }
149 
150     /**
151      * @see java.util.List#addAll(java.util.Collection)
152      */
153     public boolean addAll(final Collection<? extends T> c) {
154         throw new UnsupportedOperationException("ImmutableList.addAll");
155     }
156 
157     /**
158      * @see java.util.List#addAll(int, java.util.Collection)
159      */
160     public boolean addAll(final int index, final Collection<? extends T> c) {
161         throw new UnsupportedOperationException("ImmutableList.addAll");
162     }
163 
164     /**
165      * @see java.util.List#removeAll(java.util.Collection)
166      */
167     public boolean removeAll(final Collection<?> c) {
168         throw new UnsupportedOperationException("ImmutableList.removeAll");
169     }
170 
171     /**
172      * @see java.util.List#retainAll(java.util.Collection)
173      */
174     public boolean retainAll(final Collection<?> c) {
175         throw new UnsupportedOperationException("ImmutableList.retainAll");
176     }
177 
178     /**
179      * @see java.util.List#clear()
180      */
181     public void clear() {
182         throw new UnsupportedOperationException("ImmutableList.clear");
183     }
184 
185     /**
186      * @see java.util.List#set(int, E)
187      */
188     public T set(final int index, final T element) {
189         throw new UnsupportedOperationException("ImmutableList.set");
190     }
191 
192     /**
193      * @see java.util.List#add(int, E)
194      */
195     public void add(final int index, final T element) {
196         throw new UnsupportedOperationException("ImmutableList.add");
197     }
198 
199     /**
200      * @see java.util.List#remove(int)
201      */
202     public T remove(final int index) {
203         throw new UnsupportedOperationException("ImmutableList.remove");
204     }
205 
206     /**
207      * @see java.util.List#listIterator()
208      */
209     public ListIterator<T> listIterator() {
210         return new ImmutableListIterator<T>(this.list.listIterator());
211     }
212 
213     /**
214      * @see java.util.List#listIterator(int)
215      */
216     public ListIterator<T> listIterator(final int index) {
217         return new ImmutableListIterator<T>(this.list.listIterator(index));
218     }
219 
220 }