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

Side by Side Diff: lib/src/wrappers.dart

Issue 1838353002: Fix the invocation of type-safe constructors. (Closed) Base URL: git@github.com:dart-lang/collection@master
Patch Set: Created 4 years, 8 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
« no previous file with comments | « no previous file | no next file » | 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 import "dart:collection"; 5 import "dart:collection";
6 import "dart:math" as math; 6 import "dart:math" as math;
7 7
8 import "typed_wrappers.dart"; 8 import "typed_wrappers.dart";
9 import "unmodifiable_wrappers.dart"; 9 import "unmodifiable_wrappers.dart";
10 10
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 /// Creates a wrapper that asserts the types of values in [base]. 96 /// Creates a wrapper that asserts the types of values in [base].
97 /// 97 ///
98 /// This soundly converts an [Iterable] without a generic type to an 98 /// This soundly converts an [Iterable] without a generic type to an
99 /// `Iterable<E>` by asserting that its elements are instances of `E` whenever 99 /// `Iterable<E>` by asserting that its elements are instances of `E` whenever
100 /// they're accessed. If they're not, it throws a [CastError]. 100 /// they're accessed. If they're not, it throws a [CastError].
101 /// 101 ///
102 /// This forwards all operations to [base], so any changes in [base] will be 102 /// This forwards all operations to [base], so any changes in [base] will be
103 /// reflected in [this]. If [base] is already an `Iterable<E>`, it's returned 103 /// reflected in [this]. If [base] is already an `Iterable<E>`, it's returned
104 /// unmodified. 104 /// unmodified.
105 static Iterable/*<E>*/ typed/*<E>*/(Iterable base) => 105 static Iterable/*<E>*/ typed/*<E>*/(Iterable base) =>
106 base is Iterable/*<E>*/ ? base : new TypedIterable/*<E>*/(base); 106 base is Iterable/*<E>*/ ? base : new TypeSafeIterable/*<E>*/(base);
107 } 107 }
108 108
109 109
110 /// A [List] that delegates all operations to a base list. 110 /// A [List] that delegates all operations to a base list.
111 /// 111 ///
112 /// This class can be used to hide non-`List` methods of a list object, or it 112 /// This class can be used to hide non-`List` methods of a list object, or it
113 /// can be extended to add extra functionality on top of an existing list 113 /// can be extended to add extra functionality on top of an existing list
114 /// object. 114 /// object.
115 class DelegatingList<E> extends DelegatingIterable<E> implements List<E> { 115 class DelegatingList<E> extends DelegatingIterable<E> implements List<E> {
116 const DelegatingList(List<E> base) : super(base); 116 const DelegatingList(List<E> base) : super(base);
117 117
118 /// Creates a wrapper that asserts the types of values in [base]. 118 /// Creates a wrapper that asserts the types of values in [base].
119 /// 119 ///
120 /// This soundly converts a [List] without a generic type to a `List<E>` by 120 /// This soundly converts a [List] without a generic type to a `List<E>` by
121 /// asserting that its elements are instances of `E` whenever they're 121 /// asserting that its elements are instances of `E` whenever they're
122 /// accessed. If they're not, it throws a [CastError]. Note that even if an 122 /// accessed. If they're not, it throws a [CastError]. Note that even if an
123 /// operation throws a [CastError], it may still mutate the underlying 123 /// operation throws a [CastError], it may still mutate the underlying
124 /// collection. 124 /// collection.
125 /// 125 ///
126 /// This forwards all operations to [base], so any changes in [base] will be 126 /// This forwards all operations to [base], so any changes in [base] will be
127 /// reflected in [this]. If [base] is already a `List<E>`, it's returned 127 /// reflected in [this]. If [base] is already a `List<E>`, it's returned
128 /// unmodified. 128 /// unmodified.
129 static List/*<E>*/ typed/*<E>*/(List base) => 129 static List/*<E>*/ typed/*<E>*/(List base) =>
130 base is List/*<E>*/ ? base : new TypedList/*<E>*/(base); 130 base is List/*<E>*/ ? base : new TypeSafeList/*<E>*/(base);
131 131
132 List<E> get _listBase => _base; 132 List<E> get _listBase => _base;
133 133
134 E operator [](int index) => _listBase[index]; 134 E operator [](int index) => _listBase[index];
135 135
136 void operator []=(int index, E value) { 136 void operator []=(int index, E value) {
137 _listBase[index] = value; 137 _listBase[index] = value;
138 } 138 }
139 139
140 void add(E value) { 140 void add(E value) {
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 /// This soundly converts a [Set] without a generic type to a `Set<E>` by 230 /// This soundly converts a [Set] without a generic type to a `Set<E>` by
231 /// asserting that its elements are instances of `E` whenever they're 231 /// asserting that its elements are instances of `E` whenever they're
232 /// accessed. If they're not, it throws a [CastError]. Note that even if an 232 /// accessed. If they're not, it throws a [CastError]. Note that even if an
233 /// operation throws a [CastError], it may still mutate the underlying 233 /// operation throws a [CastError], it may still mutate the underlying
234 /// collection. 234 /// collection.
235 /// 235 ///
236 /// This forwards all operations to [base], so any changes in [base] will be 236 /// This forwards all operations to [base], so any changes in [base] will be
237 /// reflected in [this]. If [base] is already a `Set<E>`, it's returned 237 /// reflected in [this]. If [base] is already a `Set<E>`, it's returned
238 /// unmodified. 238 /// unmodified.
239 static Set/*<E>*/ typed/*<E>*/(Set base) => 239 static Set/*<E>*/ typed/*<E>*/(Set base) =>
240 base is Set/*<E>*/ ? base : new TypedSet/*<E>*/(base); 240 base is Set/*<E>*/ ? base : new TypeSafeSet/*<E>*/(base);
241 241
242 Set<E> get _setBase => _base; 242 Set<E> get _setBase => _base;
243 243
244 bool add(E value) => _setBase.add(value); 244 bool add(E value) => _setBase.add(value);
245 245
246 void addAll(Iterable<E> elements) { 246 void addAll(Iterable<E> elements) {
247 _setBase.addAll(elements); 247 _setBase.addAll(elements);
248 } 248 }
249 249
250 void clear() { 250 void clear() {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 /// This soundly converts a [Queue] without a generic type to a `Queue<E>` by 295 /// This soundly converts a [Queue] without a generic type to a `Queue<E>` by
296 /// asserting that its elements are instances of `E` whenever they're 296 /// asserting that its elements are instances of `E` whenever they're
297 /// accessed. If they're not, it throws a [CastError]. Note that even if an 297 /// accessed. If they're not, it throws a [CastError]. Note that even if an
298 /// operation throws a [CastError], it may still mutate the underlying 298 /// operation throws a [CastError], it may still mutate the underlying
299 /// collection. 299 /// collection.
300 /// 300 ///
301 /// This forwards all operations to [base], so any changes in [base] will be 301 /// This forwards all operations to [base], so any changes in [base] will be
302 /// reflected in [this]. If [base] is already a `Queue<E>`, it's returned 302 /// reflected in [this]. If [base] is already a `Queue<E>`, it's returned
303 /// unmodified. 303 /// unmodified.
304 static Queue/*<E>*/ typed/*<E>*/(Queue base) => 304 static Queue/*<E>*/ typed/*<E>*/(Queue base) =>
305 base is Queue/*<E>*/ ? base : new TypedQueue/*<E>*/(base); 305 base is Queue/*<E>*/ ? base : new TypeSafeQueue/*<E>*/(base);
306 306
307 Queue<E> get _baseQueue => _base; 307 Queue<E> get _baseQueue => _base;
308 308
309 void add(E value) { 309 void add(E value) {
310 _baseQueue.add(value); 310 _baseQueue.add(value);
311 } 311 }
312 312
313 void addAll(Iterable<E> iterable) { 313 void addAll(Iterable<E> iterable) {
314 _baseQueue.addAll(iterable); 314 _baseQueue.addAll(iterable);
315 } 315 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 /// This soundly converts a [Map] without generic types to a `Map<K, V>` by 352 /// This soundly converts a [Map] without generic types to a `Map<K, V>` by
353 /// asserting that its keys are instances of `E` and its values are instances 353 /// asserting that its keys are instances of `E` and its values are instances
354 /// of `V` whenever they're accessed. If they're not, it throws a [CastError]. 354 /// of `V` whenever they're accessed. If they're not, it throws a [CastError].
355 /// Note that even if an operation throws a [CastError], it may still mutate 355 /// Note that even if an operation throws a [CastError], it may still mutate
356 /// the underlying collection. 356 /// the underlying collection.
357 /// 357 ///
358 /// This forwards all operations to [base], so any changes in [base] will be 358 /// This forwards all operations to [base], so any changes in [base] will be
359 /// reflected in [this]. If [base] is already a `Map<K, V>`, it's returned 359 /// reflected in [this]. If [base] is already a `Map<K, V>`, it's returned
360 /// unmodified. 360 /// unmodified.
361 static Map/*<K, V>*/ typed/*<K, V>*/(Map base) => 361 static Map/*<K, V>*/ typed/*<K, V>*/(Map base) =>
362 base is Map<K, V> ? base : new TypedMap<K, V>(base); 362 base is Map<K, V> ? base : new TypeSafeMap<K, V>(base);
363 363
364 V operator [](Object key) => _base[key]; 364 V operator [](Object key) => _base[key];
365 365
366 void operator []=(K key, V value) { 366 void operator []=(K key, V value) {
367 _base[key] = value; 367 _base[key] = value;
368 } 368 }
369 369
370 void addAll(Map<K, V> other) { 370 void addAll(Map<K, V> other) {
371 _base.addAll(other); 371 _base.addAll(other);
372 } 372 }
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
597 597
598 /// Returns a new set which contains all the elements of [this] and [other]. 598 /// Returns a new set which contains all the elements of [this] and [other].
599 /// 599 ///
600 /// That is, the returned set contains all the elements of this [Set] and all 600 /// That is, the returned set contains all the elements of this [Set] and all
601 /// the elements of [other]. 601 /// the elements of [other].
602 /// 602 ///
603 /// Note that the returned set will use the default equality operation, which 603 /// Note that the returned set will use the default equality operation, which
604 /// may be different than the equality operation [this] uses. 604 /// may be different than the equality operation [this] uses.
605 Set<V> union(Set<V> other) => toSet()..addAll(other); 605 Set<V> union(Set<V> other) => toSet()..addAll(other);
606 } 606 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698