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

Side by Side Diff: pkg/collection/lib/wrappers.dart

Issue 252133002: pkg/collection: define delegating collection constructors as const (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 7 months 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 | « no previous file | pkg/collection/pubspec.yaml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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.
(...skipping 13 matching lines...) Expand all
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 final 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 const 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
40 E elementAt(int index) => _base.elementAt(index); 40 E elementAt(int index) => _base.elementAt(index);
41 41
42 bool every(bool test(E element)) => _base.every(test); 42 bool every(bool test(E element)) => _base.every(test);
43 43
44 Iterable expand(Iterable f(E element)) => _base.expand(f); 44 Iterable expand(Iterable f(E element)) => _base.expand(f);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 95
96 96
97 /** 97 /**
98 * Creates a [List] that delegates all operations to a base list. 98 * Creates a [List] that delegates all operations to a base list.
99 * 99 *
100 * This class can be used hide non-`List` methods of a list object, 100 * This class can be used hide non-`List` methods of a list object,
101 * or it can be extended to add extra functionality on top of an existing 101 * or it can be extended to add extra functionality on top of an existing
102 * list object. 102 * list object.
103 */ 103 */
104 class DelegatingList<E> extends DelegatingIterable<E> implements List<E> { 104 class DelegatingList<E> extends DelegatingIterable<E> implements List<E> {
105 DelegatingList(List<E> base) : super(base); 105 const DelegatingList(List<E> base) : super(base);
106 106
107 List<E> get _listBase => _base; 107 List<E> get _listBase => _base;
108 108
109 E operator [](int index) => _listBase[index]; 109 E operator [](int index) => _listBase[index];
110 110
111 void operator []=(int index, E value) { 111 void operator []=(int index, E value) {
112 _listBase[index] = value; 112 _listBase[index] = value;
113 } 113 }
114 114
115 void add(E value) { 115 void add(E value) {
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 194
195 195
196 /** 196 /**
197 * Creates a [Set] that delegates all operations to a base set. 197 * Creates a [Set] that delegates all operations to a base set.
198 * 198 *
199 * This class can be used hide non-`Set` methods of a set object, 199 * This class can be used hide non-`Set` methods of a set object,
200 * or it can be extended to add extra functionality on top of an existing 200 * or it can be extended to add extra functionality on top of an existing
201 * set object. 201 * set object.
202 */ 202 */
203 class DelegatingSet<E> extends DelegatingIterable<E> implements Set<E> { 203 class DelegatingSet<E> extends DelegatingIterable<E> implements Set<E> {
204 DelegatingSet(Set<E> base) : super(base); 204 const DelegatingSet(Set<E> base) : super(base);
205 205
206 Set<E> get _setBase => _base; 206 Set<E> get _setBase => _base;
207 207
208 bool add(E value) => _setBase.add(value); 208 bool add(E value) => _setBase.add(value);
209 209
210 void addAll(Iterable<E> elements) { 210 void addAll(Iterable<E> elements) {
211 _setBase.addAll(elements); 211 _setBase.addAll(elements);
212 } 212 }
213 213
214 void clear() { 214 void clear() {
(...skipping 30 matching lines...) Expand all
245 } 245 }
246 246
247 /** 247 /**
248 * Creates a [Queue] that delegates all operations to a base queue. 248 * Creates a [Queue] that delegates all operations to a base queue.
249 * 249 *
250 * This class can be used hide non-`Queue` methods of a queue object, 250 * This class can be used hide non-`Queue` methods of a queue object,
251 * or it can be extended to add extra functionality on top of an existing 251 * or it can be extended to add extra functionality on top of an existing
252 * queue object. 252 * queue object.
253 */ 253 */
254 class DelegatingQueue<E> extends DelegatingIterable<E> implements Queue<E> { 254 class DelegatingQueue<E> extends DelegatingIterable<E> implements Queue<E> {
255 DelegatingQueue(Queue<E> queue) : super(queue); 255 const DelegatingQueue(Queue<E> queue) : super(queue);
256 256
257 Queue<E> get _baseQueue => _base; 257 Queue<E> get _baseQueue => _base;
258 258
259 void add(E value) { 259 void add(E value) {
260 _baseQueue.add(value); 260 _baseQueue.add(value);
261 } 261 }
262 262
263 void addAll(Iterable<E> iterable) { 263 void addAll(Iterable<E> iterable) {
264 _baseQueue.addAll(iterable); 264 _baseQueue.addAll(iterable);
265 } 265 }
(...skipping 24 matching lines...) Expand all
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 final Map<K, V> _base; 298 final Map<K, V> _base;
299 299
300 DelegatingMap(Map<K, V> base) : _base = base; 300 const DelegatingMap(Map<K, V> base) : _base = base;
301 301
302 V operator [](Object key) => _base[key]; 302 V operator [](Object key) => _base[key];
303 303
304 void operator []=(K key, V value) { 304 void operator []=(K key, V value) {
305 _base[key] = value; 305 _base[key] = value;
306 } 306 }
307 307
308 void addAll(Map<K, V> other) { 308 void addAll(Map<K, V> other) {
309 _base.addAll(other); 309 _base.addAll(other);
310 } 310 }
(...skipping 19 matching lines...) Expand all
330 int get length => _base.length; 330 int get length => _base.length;
331 331
332 V putIfAbsent(K key, V ifAbsent()) => _base.putIfAbsent(key, ifAbsent); 332 V putIfAbsent(K key, V ifAbsent()) => _base.putIfAbsent(key, ifAbsent);
333 333
334 V remove(Object key) => _base.remove(key); 334 V remove(Object key) => _base.remove(key);
335 335
336 Iterable<V> get values => _base.values; 336 Iterable<V> get values => _base.values;
337 337
338 String toString() => _base.toString(); 338 String toString() => _base.toString();
339 } 339 }
OLDNEW
« no previous file with comments | « no previous file | pkg/collection/pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698