Chromium Code Reviews| 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 |
| 11 * [Map]. | 11 * [Map]. |
| 12 * A basic `Map` class can be implemented by extending this class and | 12 * A basic `Map` class can be implemented by extending this class and |
|
kevmoo
2014/04/29 13:41:11
While you're at it, add a blank line here, too.
Lasse Reichstein Nielsen
2014/04/29 13:52:27
I wanted this to be part of the same paragraph as
| |
| 13 * implementing `keys`, `operator[]`, `operator[]=`, `remove` and `clear`. | 13 * implementing `keys`, `operator[]`, `operator[]=`, `remove` and `clear`. |
| 14 * The remaining operations are implemented in terms of these five. | 14 * The remaining operations are implemented in terms of these five. |
| 15 * | 15 * |
| 16 * The `keys` iterable should have efficient [length] and [contains] | 16 * The `keys` iterable should have efficient [length] and [contains] |
| 17 * operations, and it should catch concurrent modifications of the keys | 17 * operations, and it should catch concurrent modifications of the keys |
| 18 * while iterating. | 18 * while iterating. |
| 19 * | 19 * |
| 20 * A more efficient implementation is usually possible by overriding | 20 * A more efficient implementation is usually possible by overriding |
| 21 * some of the other members as well. | 21 * some of the other members as well. |
| 22 */ | 22 */ |
| 23 abstract class MapBase<K, V> implements Map<K, V> { | 23 abstract class MapBase<K, V> = Object with MapMixin<K, V>; |
| 24 MapBase(); // Prevents use as mixin. | |
| 25 | 24 |
| 25 | |
| 26 /** | |
| 27 * Mixin implementing a [Map]. | |
| 28 * | |
| 29 * This mixin has a basic implementation of all but five of the members of | |
| 30 * [Map]. | |
| 31 * A basic `Map` class can be implemented by mixin in this class and | |
|
kevmoo
2014/04/29 13:41:11
include a blank line after the first sentence.
| |
| 32 * implementing `keys`, `operator[]`, `operator[]=`, `remove` and `clear`. | |
| 33 * The remaining operations are implemented in terms of these five. | |
| 34 * | |
| 35 * The `keys` iterable should have efficient [length] and [contains] | |
| 36 * operations, and it should catch concurrent modifications of the keys | |
| 37 * while iterating. | |
| 38 * | |
| 39 * A more efficient implementation is usually possible by overriding | |
| 40 * some of the other members as well. | |
| 41 */ | |
| 42 abstract class MapMixin<K, V> implements Map<K, V> { | |
| 26 Iterable<K> get keys; | 43 Iterable<K> get keys; |
| 27 V operator[](Object key); | 44 V operator[](Object key); |
| 28 operator []=(K key, V value); | 45 operator []=(K key, V value); |
| 29 V remove(Object key); | 46 V remove(Object key); |
| 30 // The `clear` operation should not be based on `remove`. | 47 // The `clear` operation should not be based on `remove`. |
| 31 // It should clear the map even if some keys are not equal to themselves. | 48 // It should clear the map even if some keys are not equal to themselves. |
| 32 void clear(); | 49 void clear(); |
| 33 | 50 |
| 34 void forEach(void action(K key, V value)) { | 51 void forEach(void action(K key, V value)) { |
| 35 for (K key in keys) { | 52 for (K key in keys) { |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 331 map[keyIterator.current] = valueIterator.current; | 348 map[keyIterator.current] = valueIterator.current; |
| 332 hasNextKey = keyIterator.moveNext(); | 349 hasNextKey = keyIterator.moveNext(); |
| 333 hasNextValue = valueIterator.moveNext(); | 350 hasNextValue = valueIterator.moveNext(); |
| 334 } | 351 } |
| 335 | 352 |
| 336 if (hasNextKey || hasNextValue) { | 353 if (hasNextKey || hasNextValue) { |
| 337 throw new ArgumentError("Iterables do not have same length."); | 354 throw new ArgumentError("Iterables do not have same length."); |
| 338 } | 355 } |
| 339 } | 356 } |
| 340 } | 357 } |
| OLD | NEW |