| OLD | NEW |
| 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 Loading... |
| 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 UnmodifiableMapView(Map<K, V> map) : super(map); |
| 214 |
| 215 /** |
| 216 * Returns a view of [source] that's guaranteed to be unmodifiable. |
| 217 * |
| 218 * If [source] already extends [UnmodifiableMapBase] or [UnmodifiableMapView], |
| 219 * it is returned without re-wrapping it. |
| 220 */ |
| 221 static Map ensure(Map source) => |
| 222 source is _UnmodifiableMapMixin |
| 223 ? source |
| 224 : new UnmodifiableMapView(source); |
| 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 Loading... |
| 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 } |
| OLD | NEW |