Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(320)

Side by Side Diff: pkg/collection_helpers/lib/unmodifiable_wrappers.dart

Issue 113883002: Create associated packages for the dart:collection and dart:async libs. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Update SDK dependency to 1.0.0 Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/collection_helpers/lib/typed_buffers.dart ('k') | pkg/collection_helpers/lib/wrappers.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 /**
6 * Wrappers that prevent a List, Set, or Map object from being modified.
7 *
8 * The [Set] and [Map] wrappers allow reading from the wrapped collection,
9 * but prohibit writing.
10 *
11 * The [List] wrapper prevents changes to the length of the wrapped list,
12 * but allows changes to the contents.
13 */
14 part of dart.collection_helpers.wrappers;
15
16 /**
17 * A fixed-length list.
18 *
19 * A `NonGrowableListView` contains a [List] object and ensures that
20 * its length does not change.
21 * Methods that would change the length of the list,
22 * such as [add] and [remove], throw an [UnsupportedError].
23 * All other methods work directly on the underlying list.
24 *
25 * This class _does_ allow changes to the contents of the wrapped list.
26 * You can, for example, [sort] the list.
27 * Permitted operations defer to the wrapped list.
28 */
29 class NonGrowableListView<E> extends DelegatingList<E>
30 with NonGrowableListMixin<E> {
31 NonGrowableListView(List<E> listBase) : super(listBase);
32 }
33
34 /**
35 * Mixin class that implements a throwing version of all list operations that
36 * change the List's length.
37 */
38 abstract class NonGrowableListMixin<E> implements List<E> {
39 static void _throw() {
40 throw new UnsupportedError(
41 "Cannot change the length of a fixed-length list");
42 }
43
44 /**
45 * Throws an [UnsupportedError];
46 * operations that change the length of the list are disallowed.
47 */
48 void set length(int newLength) => _throw();
49
50 /**
51 * Throws an [UnsupportedError];
52 * operations that change the length of the list are disallowed.
53 */
54 bool add(E value) {
55 _throw();
56 }
57
58 /**
59 * Throws an [UnsupportedError];
60 * operations that change the length of the list are disallowed.
61 */
62 void addAll(Iterable<E> iterable) => _throw();
63
64 /**
65 * Throws an [UnsupportedError];
66 * operations that change the length of the list are disallowed.
67 */
68 void insert(int index, E element) => _throw();
69
70 /**
71 * Throws an [UnsupportedError];
72 * operations that change the length of the list are disallowed.
73 */
74 void insertAll(int index, Iterable<E> iterable) => _throw();
75
76 /**
77 * Throws an [UnsupportedError];
78 * operations that change the length of the list are disallowed.
79 */
80 bool remove(Object value) { _throw(); }
81
82 /**
83 * Throws an [UnsupportedError];
84 * operations that change the length of the list are disallowed.
85 */
86 E removeAt(int index) { _throw(); }
87
88 /**
89 * Throws an [UnsupportedError];
90 * operations that change the length of the list are disallowed.
91 */
92 E removeLast() { _throw(); }
93
94 /**
95 * Throws an [UnsupportedError];
96 * operations that change the length of the list are disallowed.
97 */
98 void removeWhere(bool test(E element)) => _throw();
99
100 /**
101 * Throws an [UnsupportedError];
102 * operations that change the length of the list are disallowed.
103 */
104 void retainWhere(bool test(E element)) => _throw();
105
106 /**
107 * Throws an [UnsupportedError];
108 * operations that change the length of the list are disallowed.
109 */
110 void removeRange(int start, int end) => _throw();
111
112 /**
113 * Throws an [UnsupportedError];
114 * operations that change the length of the list are disallowed.
115 */
116 void replaceRange(int start, int end, Iterable<E> iterable) => _throw();
117
118 /**
119 * Throws an [UnsupportedError];
120 * operations that change the length of the list are disallowed.
121 */
122 void clear() => _throw();
123 }
124
125 /**
126 * An unmodifiable set.
127 *
128 * An UnmodifiableSetView contains a [Set] object and ensures
129 * that it does not change.
130 * Methods that would change the set,
131 * such as [add] and [remove], throw an [UnsupportedError].
132 * Permitted operations defer to the wrapped set.
133 */
134 class UnmodifiableSetView<E> extends DelegatingSet<E>
135 with UnmodifiableSetMixin<E> {
136 UnmodifiableSetView(Set<E> setBase) : super(setBase);
137 }
138
139 /**
140 * Mixin class that implements a throwing version of all set operations that
141 * change the Set.
142 */
143 abstract class UnmodifiableSetMixin<E> implements Set<E> {
144 void _throw() {
145 throw new UnsupportedError("Cannot modify an unmodifiable Set");
146 }
147
148 /**
149 * Throws an [UnsupportedError];
150 * operations that change the set are disallowed.
151 */
152 bool add(E value) {
153 _throw();
154 }
155
156 /**
157 * Throws an [UnsupportedError];
158 * operations that change the set are disallowed.
159 */
160 void addAll(Iterable<E> elements) => _throw();
161
162 /**
163 * Throws an [UnsupportedError];
164 * operations that change the set are disallowed.
165 */
166 bool remove(Object value) { _throw(); }
167
168 /**
169 * Throws an [UnsupportedError];
170 * operations that change the set are disallowed.
171 */
172 void removeAll(Iterable elements) => _throw();
173
174 /**
175 * Throws an [UnsupportedError];
176 * operations that change the set are disallowed.
177 */
178 void retainAll(Iterable elements) => _throw();
179
180 /**
181 * Throws an [UnsupportedError];
182 * operations that change the set are disallowed.
183 */
184 void removeWhere(bool test(E element)) => _throw();
185
186 /**
187 * Throws an [UnsupportedError];
188 * operations that change the set are disallowed.
189 */
190 void retainWhere(bool test(E element)) => _throw();
191
192 /**
193 * Throws an [UnsupportedError];
194 * operations that change the set are disallowed.
195 */
196 void clear() => _throw();
197 }
198
199 /**
200 * An unmodifiable map.
201 *
202 * An UnmodifiableMapView contains a [Map] object and ensures
203 * that it does not change.
204 * Methods that would change the map,
205 * such as [addAll] and [remove], throw an [UnsupportedError].
206 * Permitted operations defer to the wrapped map.
207 */
208 class UnmodifiableMapView<K, V> extends DelegatingMap<K, V>
209 with UnmodifiableMapMixin<K, V> {
210 UnmodifiableMapView(Map<K, V> baseMap) : super(baseMap);
211 }
212
213 /**
214 * Mixin class that implements a throwing version of all map operations that
215 * change the Map.
216 */
217 abstract class UnmodifiableMapMixin<K, V> implements Map<K, V> {
218 static void _throw() {
219 throw new UnsupportedError("Cannot modify an unmodifiable Map");
220 }
221
222 /**
223 * Throws an [UnsupportedError];
224 * operations that change the map are disallowed.
225 */
226 void operator []=(K key, V value) => _throw();
227
228 /**
229 * Throws an [UnsupportedError];
230 * operations that change the map are disallowed.
231 */
232 V putIfAbsent(K key, V ifAbsent()) { _throw(); }
233
234 /**
235 * Throws an [UnsupportedError];
236 * operations that change the map are disallowed.
237 */
238 void addAll(Map<K, V> other) => _throw();
239
240 /**
241 * Throws an [UnsupportedError];
242 * operations that change the map are disallowed.
243 */
244 V remove(K key) { _throw(); }
245
246 /**
247 * Throws an [UnsupportedError];
248 * operations that change the map are disallowed.
249 */
250 void clear() => _throw();
251 }
OLDNEW
« no previous file with comments | « pkg/collection_helpers/lib/typed_buffers.dart ('k') | pkg/collection_helpers/lib/wrappers.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698