OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * Wrappers that prevent a List, Set, or Map object from being modified. | 6 * Wrappers that prevent a List, Set, or Map object from being modified. |
7 * | 7 * |
8 * The [Set] and [Map] wrappers allow reading from the wrapped collection, | 8 * The [Set] and [Map] wrappers allow reading from the wrapped collection, |
9 * but prohibit writing. | 9 * but prohibit writing. |
10 * | 10 * |
11 * The [List] wrapper prevents changes to the length of the wrapped list, | 11 * The [List] wrapper prevents changes to the length of the wrapped list, |
12 * but allows changes to the contents. | 12 * but allows changes to the contents. |
13 */ | 13 */ |
14 part of dart.pkg.collection.wrappers; | 14 library collection.unmodifiable_wrappers; |
| 15 |
| 16 import "dart:collection"; |
| 17 |
| 18 import '../wrappers.dart'; |
| 19 |
| 20 export "dart:collection" show UnmodifiableListView, UnmodifiableMapView; |
15 | 21 |
16 /** | 22 /** |
17 * A fixed-length list. | 23 * A fixed-length list. |
18 * | 24 * |
19 * A `NonGrowableListView` contains a [List] object and ensures that | 25 * A `NonGrowableListView` contains a [List] object and ensures that |
20 * its length does not change. | 26 * its length does not change. |
21 * Methods that would change the length of the list, | 27 * Methods that would change the length of the list, |
22 * such as [add] and [remove], throw an [UnsupportedError]. | 28 * such as [add] and [remove], throw an [UnsupportedError]. |
23 * All other methods work directly on the underlying list. | 29 * All other methods work directly on the underlying list. |
24 * | 30 * |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 void retainWhere(bool test(E element)) => _throw(); | 192 void retainWhere(bool test(E element)) => _throw(); |
187 | 193 |
188 /** | 194 /** |
189 * Throws an [UnsupportedError]; | 195 * Throws an [UnsupportedError]; |
190 * operations that change the set are disallowed. | 196 * operations that change the set are disallowed. |
191 */ | 197 */ |
192 void clear() => _throw(); | 198 void clear() => _throw(); |
193 } | 199 } |
194 | 200 |
195 /** | 201 /** |
196 * An unmodifiable map. | |
197 * | |
198 * An UnmodifiableMapView contains a [Map] object and ensures | |
199 * that it does not change. | |
200 * Methods that would change the map, | |
201 * such as [addAll] and [remove], throw an [UnsupportedError]. | |
202 * Permitted operations defer to the wrapped map. | |
203 */ | |
204 class UnmodifiableMapView<K, V> extends DelegatingMap<K, V> | |
205 with UnmodifiableMapMixin<K, V> { | |
206 UnmodifiableMapView(Map<K, V> baseMap) : super(baseMap); | |
207 } | |
208 | |
209 /** | |
210 * Mixin class that implements a throwing version of all map operations that | 202 * Mixin class that implements a throwing version of all map operations that |
211 * change the Map. | 203 * change the Map. |
212 */ | 204 */ |
213 abstract class UnmodifiableMapMixin<K, V> implements Map<K, V> { | 205 abstract class UnmodifiableMapMixin<K, V> implements Map<K, V> { |
214 static _throw() { | 206 static _throw() { |
215 throw new UnsupportedError("Cannot modify an unmodifiable Map"); | 207 throw new UnsupportedError("Cannot modify an unmodifiable Map"); |
216 } | 208 } |
217 | 209 |
218 /** | 210 /** |
219 * Throws an [UnsupportedError]; | 211 * Throws an [UnsupportedError]; |
(...skipping 18 matching lines...) Expand all Loading... |
238 * operations that change the map are disallowed. | 230 * operations that change the map are disallowed. |
239 */ | 231 */ |
240 V remove(K key) => _throw(); | 232 V remove(K key) => _throw(); |
241 | 233 |
242 /** | 234 /** |
243 * Throws an [UnsupportedError]; | 235 * Throws an [UnsupportedError]; |
244 * operations that change the map are disallowed. | 236 * operations that change the map are disallowed. |
245 */ | 237 */ |
246 void clear() => _throw(); | 238 void clear() => _throw(); |
247 } | 239 } |
OLD | NEW |