View Javadoc

1   /*
2    * Copyright (c) 2005, The K-Wf Grid Consortium
3    * Fraunhofer Institute for Computer Architecture and Software Technology
4    * See http://www.kwfgrid.eu and http://www.first.fraunhofer.de for more details.
5    */
6   package net.kwfgrid.gworkflowdl.protocol.util;
7   
8   import java.util.*;
9   
10  /***
11     A decorator for a <code>List</code> which makes the list unmodifieable.
12     All modifiying methods throw an <code>UnsupportedOperationException</code>.
13   */
14  public class UnmodifieableListDecorator implements List {
15      private List _delegate;
16  
17      /***
18         Constructor.
19         @param delegate The <code>List</code> to be decorated by this decorator.
20         @exception NullPointerException If delegate is <code>null</code>.
21       */
22      public UnmodifieableListDecorator(List delegate) throws NullPointerException {
23  	if (delegate == null)
24  	    throw new NullPointerException("Delegate list must not be null.");
25  	_delegate = delegate;
26      }
27  
28      /***
29         @exception UnsupportedOperationException Always.
30       */
31      public void add(int index, Object element) throws UnsupportedOperationException {
32  	throw new UnsupportedOperationException("It is not allowed to modify this List.");
33      }
34  
35      /***
36         @exception UnsupportedOperationException Always.
37       */
38      public boolean add(Object element) throws UnsupportedOperationException {
39  	throw new UnsupportedOperationException("It is not allowed to modify this List.");
40      }
41  
42      /***
43         @exception UnsupportedOperationException Always.
44       */
45      public boolean addAll(Collection c) throws UnsupportedOperationException {
46  	throw new UnsupportedOperationException("It is not allowed to modify this List.");
47      }
48  
49      /***
50         @exception UnsupportedOperationException Always.
51       */
52      public boolean addAll(int i, Collection c) throws UnsupportedOperationException {
53  	throw new UnsupportedOperationException("It is not allowed to modify this List.");
54      }
55  
56      /***
57         @exception UnsupportedOperationException Always.
58       */
59      public void clear() throws UnsupportedOperationException {
60  	throw new UnsupportedOperationException("It is not allowed to modify this List.");
61      }
62  
63      /***
64         @exception UnsupportedOperationException Always.
65       */
66      public Object remove(int i) throws UnsupportedOperationException {
67  	throw new UnsupportedOperationException("It is not allowed to modify this List.");
68      }
69  
70      /***
71         @exception UnsupportedOperationException Always.
72       */
73      public boolean remove(Object o) throws UnsupportedOperationException {
74  	throw new UnsupportedOperationException("It is not allowed to modify this List.");
75      }
76  
77      /***
78         @exception UnsupportedOperationException Always.
79       */
80      public boolean removeAll(Collection c) throws UnsupportedOperationException {
81  	throw new UnsupportedOperationException("It is not allowed to modify this List.");
82      }
83  
84      /***
85         @exception UnsupportedOperationException Always.
86       */
87      public boolean retainAll(Collection c) throws UnsupportedOperationException {
88  	throw new UnsupportedOperationException("It is not allowed to modify this List.");
89      }
90  
91      /***
92         @exception UnsupportedOperationException Always.
93       */
94      public Object set(int i, Object o) throws UnsupportedOperationException {
95  	throw new UnsupportedOperationException("It is not allowed to modify this List.");
96      }
97  
98      public boolean contains(Object o) {
99  	return _delegate.contains(o);
100     }
101 
102     public boolean containsAll(Collection o) {
103 	return _delegate.containsAll(o);
104     }
105 
106     public boolean equals(Object o) {
107 	return _delegate.equals(o);
108     }
109 
110     public Object get(int i) {
111 	return _delegate.get(i);
112     }
113 
114     public int hashCode() {
115 	return _delegate.hashCode();
116     }
117 
118     public int indexOf(Object o) {
119 	return _delegate.indexOf(o);
120     }
121 
122     public boolean isEmpty() {
123 	return _delegate.isEmpty();
124     }
125 
126     public Iterator iterator() {
127 	return _delegate.iterator();
128     }
129 
130     public int lastIndexOf(Object o) {
131 	return _delegate.lastIndexOf(o);
132     }
133 
134     public ListIterator listIterator() {
135 	return _delegate.listIterator();
136     }
137 
138     public ListIterator listIterator(int i) {
139 	return _delegate.listIterator(i);
140     }
141 
142     public int size() {
143 	return _delegate.size();
144     }
145 
146     /***
147        Returns an unmodifieable sublist of this list.
148        @return The sublist returned by the delegate decorated by a new <code>UnmodifieableListDecorator</code>.
149      */
150     public List subList(int fromIndex, int toIndex) {
151 	return new UnmodifieableListDecorator(_delegate.subList(fromIndex, toIndex));
152     }
153 
154     public Object[] toArray() {
155 	return _delegate.toArray();
156     }
157 
158     public Object[] toArray(Object[] a) {
159 	return _delegate.toArray(a);
160     }
161 }