~brian-thomason/+junk/bouncycastle

« back to all changes in this revision

Viewing changes to jdk1.1/java/util/Collections.java

  • Committer: Brian Thomason
  • Date: 2011-12-20 17:20:32 UTC
  • Revision ID: brian.thomason@canonical.com-20111220172032-rdtm13jgdxtksacr
Initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package java.util;
 
2
 
 
3
import java.io.Serializable;
 
4
 
 
5
public class Collections
 
6
{
 
7
    public static List EMPTY_LIST = new ArrayList();
 
8
 
 
9
    private Collections() {}
 
10
 
 
11
    public static Collection unmodifiableCollection(Collection c)
 
12
    {
 
13
    return new UnmodifiableCollection(c);
 
14
    }
 
15
 
 
16
    static class UnmodifiableCollection implements Collection, Serializable
 
17
    {
 
18
    Collection c;
 
19
 
 
20
    UnmodifiableCollection(Collection c)
 
21
    {
 
22
        this.c = c;
 
23
    }
 
24
 
 
25
    public int size()             {return c.size();}
 
26
    public boolean isEmpty()         {return c.isEmpty();}
 
27
    public boolean contains(Object o)   {return c.contains(o);}
 
28
    public Object[] toArray()         {return c.toArray();}
 
29
    public Object[] toArray(Object[] a) {return c.toArray(a);}
 
30
 
 
31
    public Iterator iterator()
 
32
    {
 
33
        return new Iterator()
 
34
        {
 
35
        Iterator i = c.iterator();
 
36
 
 
37
        public boolean hasNext() {return i.hasNext();}
 
38
        public Object next()      {return i.next();}
 
39
        public void remove()
 
40
        {
 
41
            throw new UnsupportedOperationException();
 
42
                }
 
43
        };
 
44
        }
 
45
 
 
46
    public boolean add(Object o)
 
47
    {
 
48
        throw new UnsupportedOperationException();
 
49
        }
 
50
 
 
51
    public boolean remove(Object o)
 
52
    {
 
53
        throw new UnsupportedOperationException();
 
54
        }
 
55
 
 
56
    public boolean containsAll(Collection coll)
 
57
    {
 
58
        return c.containsAll(coll);
 
59
        }
 
60
 
 
61
    public boolean addAll(Collection coll)
 
62
    {
 
63
        throw new UnsupportedOperationException();
 
64
        }
 
65
 
 
66
    public boolean removeAll(Collection coll)
 
67
    {
 
68
        throw new UnsupportedOperationException();
 
69
        }
 
70
 
 
71
    public boolean retainAll(Collection coll)
 
72
    {
 
73
        throw new UnsupportedOperationException();
 
74
        }
 
75
 
 
76
    public void clear()
 
77
    {
 
78
        throw new UnsupportedOperationException();
 
79
        }
 
80
    
 
81
    public String toString()
 
82
    {
 
83
        return c.toString();
 
84
    }
 
85
    }
 
86
 
 
87
    public static Set unmodifiableSet(Set s)
 
88
    {
 
89
    return new UnmodifiableSet(s);
 
90
    }
 
91
 
 
92
    static class UnmodifiableSet extends UnmodifiableCollection
 
93
                     implements Set, Serializable
 
94
    {
 
95
    UnmodifiableSet(Set s)
 
96
    {
 
97
        super(s);
 
98
    }
 
99
 
 
100
    public boolean equals(Object o)
 
101
    {
 
102
        return c.equals(o);
 
103
    }
 
104
    public int hashCode()
 
105
    {
 
106
        return c.hashCode();
 
107
    }
 
108
    }
 
109
 
 
110
    public static List unmodifiableList(List list)
 
111
    {
 
112
    return new UnmodifiableList(list);
 
113
    }
 
114
 
 
115
    static class UnmodifiableList extends UnmodifiableCollection
 
116
                      implements List
 
117
    {
 
118
    private List list;
 
119
 
 
120
    UnmodifiableList(List list)
 
121
    {
 
122
        super(list);
 
123
        this.list = list;
 
124
    }
 
125
 
 
126
    public boolean equals(Object o) 
 
127
    {
 
128
        return list.equals(o);
 
129
    }
 
130
    public int hashCode()
 
131
    {
 
132
        return list.hashCode();
 
133
    }
 
134
 
 
135
    public Object get(int index)
 
136
    {
 
137
        return list.get(index);
 
138
    }
 
139
 
 
140
    public Object set(int index, Object element)
 
141
    {
 
142
        throw new UnsupportedOperationException();
 
143
        }
 
144
 
 
145
    public void add(int index, Object element)
 
146
    {
 
147
        throw new UnsupportedOperationException();
 
148
        }
 
149
 
 
150
    public Object remove(int index)
 
151
    {
 
152
        throw new UnsupportedOperationException();
 
153
        }
 
154
 
 
155
    public int indexOf(Object o)
 
156
    {
 
157
        return list.indexOf(o);
 
158
    }
 
159
 
 
160
    public int lastIndexOf(Object o)
 
161
    {
 
162
        return list.lastIndexOf(o);
 
163
    }
 
164
 
 
165
    public boolean addAll(int index, Collection c)
 
166
    {
 
167
        throw new UnsupportedOperationException();
 
168
        }
 
169
 
 
170
    public ListIterator listIterator()
 
171
    {
 
172
        return listIterator(0);
 
173
    }
 
174
 
 
175
    public ListIterator listIterator(final int index)
 
176
    {
 
177
        return new ListIterator()
 
178
        {
 
179
        ListIterator i = list.listIterator(index);
 
180
 
 
181
        public boolean hasNext()
 
182
        {
 
183
            return i.hasNext();
 
184
        }
 
185
 
 
186
        public Object next()
 
187
        {
 
188
            return i.next();
 
189
        }
 
190
 
 
191
        public boolean hasPrevious()
 
192
        {
 
193
            return i.hasPrevious();
 
194
        }
 
195
 
 
196
        public Object previous()
 
197
        {
 
198
            return i.previous();
 
199
        }
 
200
 
 
201
        public int nextIndex()
 
202
        {
 
203
            return i.nextIndex();
 
204
        }
 
205
 
 
206
        public int previousIndex()
 
207
        {
 
208
            return i.previousIndex();
 
209
        }
 
210
 
 
211
        public void remove()
 
212
        {
 
213
            throw new UnsupportedOperationException();
 
214
                }
 
215
 
 
216
        public void set(Object o)
 
217
        {
 
218
            throw new UnsupportedOperationException();
 
219
                }
 
220
 
 
221
        public void add(Object o)
 
222
        {
 
223
            throw new UnsupportedOperationException();
 
224
                }
 
225
        };
 
226
    }
 
227
 
 
228
    public List subList(int fromIndex, int toIndex) {
 
229
            return new UnmodifiableList(list.subList(fromIndex, toIndex));
 
230
        }
 
231
    }
 
232
 
 
233
    public static Enumeration enumeration(final Collection c) {
 
234
    return new Enumeration() {
 
235
        Iterator i = c.iterator();
 
236
 
 
237
        public boolean hasMoreElements() {
 
238
        return i.hasNext();
 
239
        }
 
240
 
 
241
        public Object nextElement() {
 
242
        return i.next();
 
243
        }
 
244
        };
 
245
    }
 
246
}