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

Side by Side Diff: sdk/lib/collection/maps.dart

Issue 1319783003: Add static ensure() methods to unmodifiable views. Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 3 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
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 part of dart.collection; 5 part of dart.collection;
6 6
7 /** 7 /**
8 * Base class for implementing a [Map]. 8 * Base class for implementing a [Map].
9 * 9 *
10 * This class has a basic implementation of all but five of the members of 10 * This class has a basic implementation of all but five of the members of
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 Iterable<V> get values => _map.values; 201 Iterable<V> get values => _map.values;
202 } 202 }
203 203
204 /** 204 /**
205 * View of a [Map] that disallow modifying the map. 205 * View of a [Map] that disallow modifying the map.
206 * 206 *
207 * A wrapper around a `Map` that forwards all members to the map provided in 207 * A wrapper around a `Map` that forwards all members to the map provided in
208 * the constructor, except for operations that modify the map. 208 * the constructor, except for operations that modify the map.
209 * Modifying operations throw instead. 209 * Modifying operations throw instead.
210 */ 210 */
211 class UnmodifiableMapView<K, V> = 211 class UnmodifiableMapView<K, V> extends MapView<K, V>
212 MapView<K, V> with _UnmodifiableMapMixin<K, V>; 212 with _UnmodifiableMapMixin<K, V> {
213 /**
214 * Returns a view of [source] that's guaranteed to be unmodifiable.
215 *
216 * If [source] already extends [UnmodifiableMapBase] or [UnmodifiableMapView],
217 * this avoids re-wrapping it.
Lasse Reichstein Nielsen 2015/08/27 07:59:04 Also say that it returns the original object unwra
nweiz 2015/08/27 19:25:37 Done.
218 */
219 static Map ensure(Map source) =>
Lasse Reichstein Nielsen 2015/08/27 07:59:04 Move below constructor, and also don't like name h
nweiz 2015/08/27 19:25:37 Done.
220 source is _UnmodifiableMapMixin || source is ImmutableMap
Lasse Reichstein Nielsen 2015/08/27 07:59:04 What is ImmutableMap? It looks like the VM's cons
nweiz 2015/08/27 19:25:37 Yes, this was intended to handle constant maps. I
221 ? source
222 : new UnmodifiableMapView(source);
223
224 UnmodifiableMapView(Map<K, V> map) : super(map);
225 }
213 226
214 /** 227 /**
215 * Helper class which implements complex [Map] operations 228 * Helper class which implements complex [Map] operations
216 * in term of basic ones ([Map.keys], [Map.operator []], 229 * in term of basic ones ([Map.keys], [Map.operator []],
217 * [Map.operator []=] and [Map.remove].) Not all methods are 230 * [Map.operator []=] and [Map.remove].) Not all methods are
218 * necessary to implement each particular operation. 231 * necessary to implement each particular operation.
219 */ 232 */
220 class Maps { 233 class Maps {
221 static bool containsValue(Map map, value) { 234 static bool containsValue(Map map, value) {
222 for (final v in map.values) { 235 for (final v in map.values) {
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 map[keyIterator.current] = valueIterator.current; 357 map[keyIterator.current] = valueIterator.current;
345 hasNextKey = keyIterator.moveNext(); 358 hasNextKey = keyIterator.moveNext();
346 hasNextValue = valueIterator.moveNext(); 359 hasNextValue = valueIterator.moveNext();
347 } 360 }
348 361
349 if (hasNextKey || hasNextValue) { 362 if (hasNextKey || hasNextValue) {
350 throw new ArgumentError("Iterables do not have same length."); 363 throw new ArgumentError("Iterables do not have same length.");
351 } 364 }
352 } 365 }
353 } 366 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698