|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| |
|
19 |
| |
|
20 |
| |
|
21 |
| |
|
22 |
| |
|
23 |
| |
|
24 |
| |
|
25 |
| |
|
26 |
| |
|
27 |
| |
|
28 |
| |
|
29 |
| |
|
30 |
| |
|
31 |
| |
|
32 |
| |
|
33 |
| |
|
34 |
| |
|
35 |
| package edu.rice.cs.plt.collect; |
|
36 |
| |
|
37 |
| import java.util.Iterator; |
|
38 |
| import java.util.Collection; |
|
39 |
| import java.util.AbstractCollection; |
|
40 |
| import java.io.Serializable; |
|
41 |
| import edu.rice.cs.plt.iter.SizedIterable; |
|
42 |
| import edu.rice.cs.plt.iter.IterUtil; |
|
43 |
| import edu.rice.cs.plt.iter.ImmutableIterator; |
|
44 |
| import edu.rice.cs.plt.object.Composite; |
|
45 |
| import edu.rice.cs.plt.object.ObjectUtil; |
|
46 |
| |
|
47 |
| |
|
48 |
| |
|
49 |
| |
|
50 |
| |
|
51 |
| |
|
52 |
| |
|
53 |
| |
|
54 |
| |
|
55 |
| |
|
56 |
| |
|
57 |
| public class ImmutableCollection<T> extends AbstractCollection<T> |
|
58 |
| implements SizedIterable<T>, Composite, Serializable { |
|
59 |
| |
|
60 |
| protected Collection<? extends T> _delegate; |
|
61 |
| |
|
62 |
80
| public ImmutableCollection(Collection<? extends T> collection) { _delegate = collection; }
|
|
63 |
| |
|
64 |
0
| public int compositeHeight() { return ObjectUtil.compositeHeight(_delegate) + 1; }
|
|
65 |
0
| public int compositeSize() { return ObjectUtil.compositeSize(_delegate) + 1; }
|
|
66 |
| |
|
67 |
1
| public Iterator<T> iterator() { return ImmutableIterator.make(_delegate.iterator()); }
|
|
68 |
| |
|
69 |
0
| @Override public boolean isEmpty() { return _delegate.isEmpty(); }
|
|
70 |
1
| public int size() { return _delegate.size(); }
|
|
71 |
0
| public int size(int bound) { return IterUtil.sizeOf(_delegate, bound); }
|
|
72 |
0
| public boolean isInfinite() { return IterUtil.isInfinite(_delegate); }
|
|
73 |
0
| public boolean hasFixedSize() { return IterUtil.hasFixedSize(_delegate); }
|
|
74 |
0
| public boolean isStatic() { return IterUtil.isStatic(_delegate); }
|
|
75 |
| |
|
76 |
0
| @Override public boolean contains(Object o) { return _delegate.contains(o); }
|
|
77 |
0
| @Override public boolean containsAll(Collection<?> c) { return _delegate.containsAll(c); }
|
|
78 |
0
| @Override public Object[] toArray() { return _delegate.toArray(); }
|
|
79 |
0
| @Override public <S> S[] toArray(S[] a) { return _delegate.toArray(a); }
|
|
80 |
| |
|
81 |
0
| @Override public boolean add(T o) { throw new UnsupportedOperationException(); }
|
|
82 |
0
| @Override public boolean addAll(Collection<? extends T> c) { throw new UnsupportedOperationException(); }
|
|
83 |
0
| @Override public boolean remove(Object o) { throw new UnsupportedOperationException(); }
|
|
84 |
0
| @Override public boolean retainAll(Collection<?> c) { throw new UnsupportedOperationException(); }
|
|
85 |
0
| @Override public boolean removeAll(Collection<?> c) { throw new UnsupportedOperationException(); }
|
|
86 |
0
| @Override public void clear() { throw new UnsupportedOperationException(); }
|
|
87 |
| |
|
88 |
0
| protected boolean abstractCollectionIsEmpty() { return super.isEmpty(); }
|
|
89 |
0
| protected boolean abstractCollectionContains(Object o) { return super.contains(o); }
|
|
90 |
0
| protected Object[] abstractCollectionToArray() { return super.toArray(); }
|
|
91 |
0
| protected <S> S[] abstractCollectionToArray(S[] a) { return super.toArray(a); }
|
|
92 |
0
| protected boolean abstractCollectionRemove(T o) { return super.remove(o); }
|
|
93 |
0
| protected boolean abstractCollectionContainsAll(Collection<?> c) { return super.containsAll(c); }
|
|
94 |
0
| protected boolean abstractCollectionAddAll(Collection<? extends T> c) { return super.addAll(c); }
|
|
95 |
0
| protected boolean abstractCollectionRetainAll(Collection<?> c) { return super.retainAll(c); }
|
|
96 |
0
| protected boolean abstractCollectionRemoveAll(Collection<?> c) { return super.removeAll(c); }
|
|
97 |
0
| protected void abstractCollectionClear() { super.clear(); }
|
|
98 |
| |
|
99 |
6
| @Override public String toString() { return _delegate.toString(); }
|
|
100 |
| |
|
101 |
| |
|
102 |
0
| public static <T> ImmutableCollection<T> make(Collection<? extends T> collection) {
|
|
103 |
0
| return new ImmutableCollection<T>(collection);
|
|
104 |
| } |
|
105 |
| |
|
106 |
| } |