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 * Delegating wrappers for [Iterable], [List], [Set], [Queue] and [Map]. | 6 * Delegating wrappers for [Iterable], [List], [Set], [Queue] and [Map]. |
7 * | 7 * |
8 * Also adds unmodifiable views for `Set` and `Map`, and a fixed length | 8 * Also adds unmodifiable views for `Set` and `Map`, and a fixed length |
9 * view for `List`. The unmodifable list view from `dart:collection` is exported | 9 * view for `List`. The unmodifable list view from `dart:collection` is exported |
10 * as well, just for completeness. | 10 * as well, just for completeness. |
11 */ | 11 */ |
12 library dart.pkg.collection.wrappers; | 12 library dart.pkg.collection.wrappers; |
13 | 13 |
14 import "dart:collection"; | 14 import "dart:collection"; |
15 import "dart:math" show Random; | 15 import "dart:math" show Random; |
16 | 16 |
17 export "dart:collection" show UnmodifiableListView; | 17 export "dart:collection" show UnmodifiableListView; |
18 | 18 |
19 part "src/unmodifiable_wrappers.dart"; | 19 part "src/unmodifiable_wrappers.dart"; |
20 | 20 |
21 /** | 21 /** |
22 * Creates an [Iterable] that delegates all operations to a base iterable. | 22 * Creates an [Iterable] that delegates all operations to a base iterable. |
23 * | 23 * |
24 * This class can be used hide non-`Iterable` methods of an iterable object, | 24 * This class can be used hide non-`Iterable` methods of an iterable object, |
25 * or it can be extended to add extra functionality on top of an existing | 25 * or it can be extended to add extra functionality on top of an existing |
26 * iterable object. | 26 * iterable object. |
27 */ | 27 */ |
28 class DelegatingIterable<E> implements Iterable<E> { | 28 class DelegatingIterable<E> implements Iterable<E> { |
29 Iterable<E> _base; | 29 final Iterable<E> _base; |
30 | 30 |
31 /** | 31 /** |
32 * Create a wrapper that forwards operations to [base]. | 32 * Create a wrapper that forwards operations to [base]. |
33 */ | 33 */ |
34 DelegatingIterable(Iterable<E> base) : _base = base; | 34 DelegatingIterable(Iterable<E> base) : _base = base; |
35 | 35 |
36 bool any(bool test(E element)) => _base.any(test); | 36 bool any(bool test(E element)) => _base.any(test); |
37 | 37 |
38 bool contains(Object element) => _base.contains(element); | 38 bool contains(Object element) => _base.contains(element); |
39 | 39 |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 } | 288 } |
289 | 289 |
290 /** | 290 /** |
291 * Creates a [Map] that delegates all operations to a base map. | 291 * Creates a [Map] that delegates all operations to a base map. |
292 * | 292 * |
293 * This class can be used hide non-`Map` methods of an object that extends | 293 * This class can be used hide non-`Map` methods of an object that extends |
294 * `Map`, or it can be extended to add extra functionality on top of an existing | 294 * `Map`, or it can be extended to add extra functionality on top of an existing |
295 * map object. | 295 * map object. |
296 */ | 296 */ |
297 class DelegatingMap<K, V> implements Map<K, V> { | 297 class DelegatingMap<K, V> implements Map<K, V> { |
298 Map<K, V> _base; | 298 final Map<K, V> _base; |
| 299 |
299 DelegatingMap(Map<K, V> base) : _base = base; | 300 DelegatingMap(Map<K, V> base) : _base = base; |
300 | 301 |
301 V operator [](Object key) => _base[key]; | 302 V operator [](Object key) => _base[key]; |
302 | 303 |
303 void operator []=(K key, V value) { | 304 void operator []=(K key, V value) { |
304 _base[key] = value; | 305 _base[key] = value; |
305 } | 306 } |
306 | 307 |
307 void addAll(Map<K, V> other) { | 308 void addAll(Map<K, V> other) { |
308 _base.addAll(other); | 309 _base.addAll(other); |
(...skipping 20 matching lines...) Expand all Loading... |
329 int get length => _base.length; | 330 int get length => _base.length; |
330 | 331 |
331 V putIfAbsent(K key, V ifAbsent()) => _base.putIfAbsent(key, ifAbsent); | 332 V putIfAbsent(K key, V ifAbsent()) => _base.putIfAbsent(key, ifAbsent); |
332 | 333 |
333 V remove(Object key) => _base.remove(key); | 334 V remove(Object key) => _base.remove(key); |
334 | 335 |
335 Iterable<V> get values => _base.values; | 336 Iterable<V> get values => _base.values; |
336 | 337 |
337 String toString() => _base.toString(); | 338 String toString() => _base.toString(); |
338 } | 339 } |
OLD | NEW |