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 |
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 [Iterable.length] and |
17 * operations, and it should catch concurrent modifications of the keys | 17 * [Iterable.contains] operations, and it should catch concurrent modifications |
18 * while iterating. | 18 * of the keys 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> = Object with MapMixin<K, V>; | 23 abstract class MapBase<K, V> = Object with MapMixin<K, V>; |
24 | 24 |
25 /** | 25 /** |
26 * Mixin implementing a [Map]. | 26 * Mixin implementing a [Map]. |
27 * | 27 * |
28 * This mixin has a basic implementation of all but five of the members of | 28 * This mixin has a basic implementation of all but five of the members of |
29 * [Map]. | 29 * [Map]. |
30 * A basic `Map` class can be implemented by mixin in this class and | 30 * A basic `Map` class can be implemented by mixin in this class and |
31 * implementing `keys`, `operator[]`, `operator[]=`, `remove` and `clear`. | 31 * implementing `keys`, `operator[]`, `operator[]=`, `remove` and `clear`. |
32 * The remaining operations are implemented in terms of these five. | 32 * The remaining operations are implemented in terms of these five. |
33 * | 33 * |
34 * The `keys` iterable should have efficient [length] and [contains] | 34 * The `keys` iterable should have efficient [Iterable.length] and |
35 * operations, and it should catch concurrent modifications of the keys | 35 * [Iterable.contains] operations, and it should catch concurrent modifications |
36 * while iterating. | 36 * of the keys while iterating. |
37 * | 37 * |
38 * A more efficient implementation is usually possible by overriding | 38 * A more efficient implementation is usually possible by overriding |
39 * some of the other members as well. | 39 * some of the other members as well. |
40 */ | 40 */ |
41 abstract class MapMixin<K, V> implements Map<K, V> { | 41 abstract class MapMixin<K, V> implements Map<K, V> { |
42 Iterable<K> get keys; | 42 Iterable<K> get keys; |
43 V operator [](Object key); | 43 V operator [](Object key); |
44 operator []=(K key, V value); | 44 operator []=(K key, V value); |
45 V remove(Object key); | 45 V remove(Object key); |
46 // The `clear` operation should not be based on `remove`. | 46 // The `clear` operation should not be based on `remove`. |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 * | 86 * |
87 * This class has a basic implementation of all but two of the members of | 87 * This class has a basic implementation of all but two of the members of |
88 * an umodifiable [Map]. | 88 * an umodifiable [Map]. |
89 * A simple unmodifiable `Map` class can be implemented by extending this | 89 * A simple unmodifiable `Map` class can be implemented by extending this |
90 * class and implementing `keys` and `operator[]`. | 90 * class and implementing `keys` and `operator[]`. |
91 * | 91 * |
92 * Modifying operations throw when used. | 92 * Modifying operations throw when used. |
93 * The remaining non-modifying operations are implemented in terms of `keys` | 93 * The remaining non-modifying operations are implemented in terms of `keys` |
94 * and `operator[]`. | 94 * and `operator[]`. |
95 * | 95 * |
96 * The `keys` iterable should have efficient [length] and [contains] | 96 * The `keys` iterable should have efficient [Iterable.length] and |
97 * operations, and it should catch concurrent modifications of the keys | 97 * [Iterable.contains] operations, and it should catch concurrent modifications |
98 * while iterating. | 98 * of the keys while iterating. |
99 * | 99 * |
100 * A more efficient implementation is usually possible by overriding | 100 * A more efficient implementation is usually possible by overriding |
101 * some of the other members as well. | 101 * some of the other members as well. |
102 */ | 102 */ |
103 abstract class UnmodifiableMapBase<K, V> = MapBase<K, V> | 103 abstract class UnmodifiableMapBase<K, V> = MapBase<K, V> |
104 with _UnmodifiableMapMixin<K, V>; | 104 with _UnmodifiableMapMixin<K, V>; |
105 | 105 |
106 /** | 106 /** |
107 * Implementation of [Map.values] based on the map and its [Map.keys] iterable. | 107 * Implementation of [Map.values] based on the map and its [Map.keys] iterable. |
108 * | 108 * |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 map[keyIterator.current] = valueIterator.current; | 366 map[keyIterator.current] = valueIterator.current; |
367 hasNextKey = keyIterator.moveNext(); | 367 hasNextKey = keyIterator.moveNext(); |
368 hasNextValue = valueIterator.moveNext(); | 368 hasNextValue = valueIterator.moveNext(); |
369 } | 369 } |
370 | 370 |
371 if (hasNextKey || hasNextValue) { | 371 if (hasNextKey || hasNextValue) { |
372 throw new ArgumentError("Iterables do not have same length."); | 372 throw new ArgumentError("Iterables do not have same length."); |
373 } | 373 } |
374 } | 374 } |
375 } | 375 } |
OLD | NEW |