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