| 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 * Returns whether this map contains the given [value]. | 23 * Returns whether this map contains the given [value]. |
| 24 */ | 24 */ |
| 25 bool containsValue(V value); | 25 bool containsValue(Object value); |
| 26 | 26 |
| 27 /** | 27 /** |
| 28 * Returns whether this map contains the given [key]. | 28 * Returns whether this map contains the given [key]. |
| 29 */ | 29 */ |
| 30 bool containsKey(K key); | 30 bool containsKey(Object key); |
| 31 | 31 |
| 32 /** | 32 /** |
| 33 * Returns the value for the given [key] or null if [key] is not | 33 * Returns the value for the given [key] or null if [key] is not |
| 34 * in the map. Because null values are supported, one should either | 34 * in the map. Because null values are supported, one should either |
| 35 * use containsKey to distinguish between an absent key and a null | 35 * use containsKey to distinguish between an absent key and a null |
| 36 * value, or use the [putIfAbsent] method. | 36 * value, or use the [putIfAbsent] method. |
| 37 */ | 37 */ |
| 38 V operator [](K key); | 38 V operator [](Object key); |
| 39 | 39 |
| 40 /** | 40 /** |
| 41 * Associates the [key] with the given [value]. | 41 * Associates the [key] with the given [value]. |
| 42 */ | 42 */ |
| 43 void operator []=(K key, V value); | 43 void operator []=(K key, V value); |
| 44 | 44 |
| 45 /** | 45 /** |
| 46 * If [key] is not associated to a value, calls [ifAbsent] and | 46 * If [key] is not associated to a value, calls [ifAbsent] and |
| 47 * updates the map by mapping [key] to the value returned by | 47 * updates the map by mapping [key] to the value returned by |
| 48 * [ifAbsent]. Returns the value in the map. | 48 * [ifAbsent]. Returns the value in the map. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 62 * therefore not change during the iteration. | 62 * therefore not change during the iteration. |
| 63 */ | 63 */ |
| 64 void addAll(Map<K, V> other); | 64 void addAll(Map<K, V> other); |
| 65 | 65 |
| 66 /** | 66 /** |
| 67 * Removes the association for the given [key]. Returns the value for | 67 * Removes the association for the given [key]. Returns the value for |
| 68 * [key] in the map or null if [key] is not in the map. Note that values | 68 * [key] in the map or null if [key] is not in the map. Note that values |
| 69 * can be null and a returned null value does not always imply that the | 69 * can be null and a returned null value does not always imply that the |
| 70 * key is absent. | 70 * key is absent. |
| 71 */ | 71 */ |
| 72 V remove(K key); | 72 V remove(Object key); |
| 73 | 73 |
| 74 /** | 74 /** |
| 75 * Removes all pairs from the map. | 75 * Removes all pairs from the map. |
| 76 */ | 76 */ |
| 77 void clear(); | 77 void clear(); |
| 78 | 78 |
| 79 /** | 79 /** |
| 80 * Applies [f] to each {key, value} pair of the map. | 80 * Applies [f] to each {key, value} pair of the map. |
| 81 * | 81 * |
| 82 * It is an error to add or remove keys from the map during iteration. | 82 * It is an error to add or remove keys from the map during iteration. |
| 83 */ | 83 */ |
| 84 void forEach(void f(K key, V value)); | 84 void forEach(void f(K key, V value)); |
| 85 | 85 |
| 86 /** | 86 /** |
| 87 * The keys of [this]. | 87 * The keys of [this]. |
| 88 */ | 88 */ |
| 89 // TODO(floitsch): this should return a [Set]. | |
| 90 Iterable<K> get keys; | 89 Iterable<K> get keys; |
| 91 | 90 |
| 92 /** | 91 /** |
| 93 * The values of [this]. | 92 * The values of [this]. |
| 94 */ | 93 */ |
| 95 Iterable<V> get values; | 94 Iterable<V> get values; |
| 96 | 95 |
| 97 /** | 96 /** |
| 98 * The number of {key, value} pairs in the map. | 97 * The number of {key, value} pairs in the map. |
| 99 */ | 98 */ |
| 100 int get length; | 99 int get length; |
| 101 | 100 |
| 102 /** | 101 /** |
| 103 * Returns true if there is no {key, value} pair in the map. | 102 * Returns true if there is no {key, value} pair in the map. |
| 104 */ | 103 */ |
| 105 bool get isEmpty; | 104 bool get isEmpty; |
| 106 | 105 |
| 107 /** | 106 /** |
| 108 * Returns true if there is at least one {key, value} pair in the map. | 107 * Returns true if there is at least one {key, value} pair in the map. |
| 109 */ | 108 */ |
| 110 bool get isNotEmpty; | 109 bool get isNotEmpty; |
| 111 } | 110 } |
| OLD | NEW |