1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.collections.bag;
18
19 import java.io.IOException;
20 import java.io.ObjectInputStream;
21 import java.io.ObjectOutputStream;
22 import java.io.Serializable;
23 import java.util.Collection;
24 import java.util.Iterator;
25 import java.util.Set;
26
27 import org.apache.commons.collections.SortedBag;
28 import org.apache.commons.collections.Unmodifiable;
29 import org.apache.commons.collections.iterators.UnmodifiableIterator;
30 import org.apache.commons.collections.set.UnmodifiableSet;
31
32
33
34
35
36
37
38
39
40
41
42 public final class UnmodifiableSortedBag<E>
43 extends AbstractSortedBagDecorator<E> implements Unmodifiable, Serializable {
44
45
46 private static final long serialVersionUID = -3190437252665717841L;
47
48
49
50
51
52
53
54
55
56
57
58 public static <E> SortedBag<E> unmodifiableSortedBag(final SortedBag<E> bag) {
59 if (bag instanceof Unmodifiable) {
60 return bag;
61 }
62 return new UnmodifiableSortedBag<E>(bag);
63 }
64
65
66
67
68
69
70
71
72 private UnmodifiableSortedBag(final SortedBag<E> bag) {
73 super(bag);
74 }
75
76
77
78
79
80
81
82
83 private void writeObject(final ObjectOutputStream out) throws IOException {
84 out.defaultWriteObject();
85 out.writeObject(collection);
86 }
87
88
89
90
91
92
93
94
95 @SuppressWarnings("unchecked")
96 private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException {
97 in.defaultReadObject();
98 collection = (Collection<E>) in.readObject();
99 }
100
101
102 @Override
103 public Iterator<E> iterator() {
104 return UnmodifiableIterator.unmodifiableIterator(decorated().iterator());
105 }
106
107 @Override
108 public boolean add(final E object) {
109 throw new UnsupportedOperationException();
110 }
111
112 @Override
113 public boolean addAll(final Collection<? extends E> coll) {
114 throw new UnsupportedOperationException();
115 }
116
117 @Override
118 public void clear() {
119 throw new UnsupportedOperationException();
120 }
121
122 @Override
123 public boolean remove(final Object object) {
124 throw new UnsupportedOperationException();
125 }
126
127 @Override
128 public boolean removeAll(final Collection<?> coll) {
129 throw new UnsupportedOperationException();
130 }
131
132 @Override
133 public boolean retainAll(final Collection<?> coll) {
134 throw new UnsupportedOperationException();
135 }
136
137
138 @Override
139 public boolean add(final E object, final int count) {
140 throw new UnsupportedOperationException();
141 }
142
143 @Override
144 public boolean remove(final Object object, final int count) {
145 throw new UnsupportedOperationException();
146 }
147
148 @Override
149 public Set<E> uniqueSet() {
150 final Set<E> set = decorated().uniqueSet();
151 return UnmodifiableSet.unmodifiableSet(set);
152 }
153
154 }