Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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.core; | 5 part of dart.core; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * A [Map] is an associative container, mapping a key to a value. | 8 * A [Map] is an associative container, mapping a key to a value. |
| 9 * Null values are supported, but null keys are not. | 9 * Null values are supported, but null keys are not. |
| 10 */ | 10 */ |
| 11 abstract class Map<K, V> { | 11 abstract class Map<K, V> { |
| 12 /** | 12 /** |
| 13 * Creates a map with the default implementation. | 13 * Creates a map with the default implementation. |
| 14 */ | 14 */ |
| 15 factory Map() => new HashMap<K, V>(); | 15 factory Map() => new HashMap<K, V>(); |
| 16 | 16 |
| 17 /** | 17 /** |
| 18 * Creates a [Map] that contains all key value pairs of [other]. | 18 * Creates a [Map] that contains all key value pairs of [other]. |
| 19 */ | 19 */ |
| 20 factory Map.from(Map<K, V> other) => new HashMap<K, V>.from(other); | 20 factory Map.from(Map<K, V> other) => new HashMap<K, V>.from(other); |
| 21 | 21 |
| 22 | 22 |
| 23 /** | 23 /** |
| 24 * Returns whether this map contains the given [value]. | 24 * Returns whether this map contains the given [value]. |
| 25 */ | 25 */ |
| 26 bool containsValue(V value); | 26 bool containsValue(Object value); |
| 27 | 27 |
| 28 /** | 28 /** |
| 29 * Returns whether this map contains the given [key]. | 29 * Returns whether this map contains the given [key]. |
| 30 */ | 30 */ |
| 31 bool containsKey(K key); | 31 bool containsKey(Object key); |
| 32 | 32 |
| 33 /** | 33 /** |
| 34 * Returns the value for the given [key] or null if [key] is not | 34 * Returns the value for the given [key] or null if [key] is not |
| 35 * in the map. Because null values are supported, one should either | 35 * in the map. Because null values are supported, one should either |
| 36 * use containsKey to distinguish between an absent key and a null | 36 * use containsKey to distinguish between an absent key and a null |
| 37 * value, or use the [putIfAbsent] method. | 37 * value, or use the [putIfAbsent] method. |
| 38 */ | 38 */ |
| 39 V operator [](K key); | 39 V operator [](Object key); |
| 40 | 40 |
| 41 /** | 41 /** |
| 42 * Associates the [key] with the given [value]. | 42 * Associates the [key] with the given [value]. |
| 43 */ | 43 */ |
| 44 void operator []=(K key, V value); | 44 void operator []=(K key, V value); |
| 45 | 45 |
| 46 /** | 46 /** |
| 47 * If [key] is not associated to a value, calls [ifAbsent] and | 47 * If [key] is not associated to a value, calls [ifAbsent] and |
| 48 * updates the map by mapping [key] to the value returned by | 48 * updates the map by mapping [key] to the value returned by |
| 49 * [ifAbsent]. Returns the value in the map. | 49 * [ifAbsent]. Returns the value in the map. |
| 50 * | 50 * |
| 51 * It is an error to add or remove keys from map during the call to | 51 * It is an error to add or remove keys from map during the call to |
| 52 * [ifAbsent]. | 52 * [ifAbsent]. |
| 53 */ | 53 */ |
| 54 V putIfAbsent(K key, V ifAbsent()); | 54 V putIfAbsent(K key, V ifAbsent()); |
| 55 | 55 |
| 56 /** | 56 /** |
| 57 * Removes the association for the given [key]. Returns the value for | 57 * Removes the association for the given [key]. Returns the value for |
| 58 * [key] in the map or null if [key] is not in the map. Note that values | 58 * [key] in the map or null if [key] is not in the map. Note that values |
| 59 * can be null and a returned null value does not always imply that the | 59 * can be null and a returned null value does not always imply that the |
| 60 * key is absent. | 60 * key is absent. |
| 61 */ | 61 */ |
| 62 V remove(K key); | 62 V remove(Object key); |
| 63 | 63 |
| 64 /** | 64 /** |
| 65 * Removes all pairs from the map. | 65 * Removes all pairs from the map. |
| 66 */ | 66 */ |
| 67 void clear(); | 67 void clear(); |
| 68 | 68 |
| 69 /** | 69 /** |
| 70 * Applies [f] to each {key, value} pair of the map. | 70 * Applies [f] to each {key, value} pair of the map. |
| 71 * | 71 * |
| 72 * It is an error to add or remove keys from the map during iteration. | 72 * It is an error to add or remove keys from the map during iteration. |
| 73 */ | 73 */ |
| 74 void forEach(void f(K key, V value)); | 74 void forEach(void f(K key, V value)); |
| 75 | 75 |
| 76 /** | 76 /** |
| 77 * The keys of [this]. | 77 * The keys of [this]. |
| 78 */ | 78 */ |
| 79 // TODO(floitsch): this should return a [Set]. | 79 // TODO(floitsch): this should return a [Set]. |
|
Lasse Reichstein Nielsen
2013/04/24 09:11:18
Remove TODO? I doubt we'll do it, as it would be b
floitsch
2013/06/17 18:25:34
Done.
| |
| 80 Iterable<K> get keys; | 80 Iterable<K> get keys; |
| 81 | 81 |
| 82 /** | 82 /** |
| 83 * The values of [this]. | 83 * The values of [this]. |
| 84 */ | 84 */ |
| 85 Iterable<V> get values; | 85 Iterable<V> get values; |
| 86 | 86 |
| 87 /** | 87 /** |
| 88 * The number of {key, value} pairs in the map. | 88 * The number of {key, value} pairs in the map. |
| 89 */ | 89 */ |
| 90 int get length; | 90 int get length; |
| 91 | 91 |
| 92 /** | 92 /** |
| 93 * Returns true if there is no {key, value} pair in the map. | 93 * Returns true if there is no {key, value} pair in the map. |
| 94 */ | 94 */ |
| 95 bool get isEmpty; | 95 bool get isEmpty; |
| 96 } | 96 } |
| OLD | NEW |