| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 /** | |
| 6 * A [Map] is an associative container, mapping a key to a value. | |
| 7 * Null values are supported. | |
| 8 */ | |
| 9 interface Map<K, V> default HashMapImplementation<K extends Hashable, V> { | |
| 10 /** | |
| 11 * Creates a map with the default implementation. | |
| 12 */ | |
| 13 Map(); | |
| 14 | |
| 15 /** | |
| 16 * Creates a [Map] that contains all key value pairs of [other]. | |
| 17 */ | |
| 18 Map.from(Map<K, V> other); | |
| 19 | |
| 20 | |
| 21 /** | |
| 22 * Returns whether this map contains the given [value]. | |
| 23 */ | |
| 24 bool containsValue(V value); | |
| 25 | |
| 26 /** | |
| 27 * Returns whether this map contains the given [key]. | |
| 28 */ | |
| 29 bool containsKey(K key); | |
| 30 | |
| 31 /** | |
| 32 * Returns the value for the given [key] or null if [key] is not | |
| 33 * in the map. Because null values are supported, one should either | |
| 34 * use containsKey to distinguish between an absent key and a null | |
| 35 * value, or use the [putIfAbsent] method. | |
| 36 */ | |
| 37 V operator [](K key); | |
| 38 | |
| 39 /** | |
| 40 * Associates the [key] with the given [value]. | |
| 41 */ | |
| 42 void operator []=(K key, V value); | |
| 43 | |
| 44 /** | |
| 45 * If [key] is not associated to a value, calls [ifAbsent] and | |
| 46 * updates the map by mapping [key] to the value returned by | |
| 47 * [ifAbsent]. Returns the value in the map. | |
| 48 */ | |
| 49 V putIfAbsent(K key, V ifAbsent()); | |
| 50 | |
| 51 /** | |
| 52 * Removes the association for the given [key]. Returns the value for | |
| 53 * [key] in the map or null if [key] is not in the map. Note that values | |
| 54 * can be null and a returned null value does not always imply that the | |
| 55 * key is absent. | |
| 56 */ | |
| 57 V remove(K key); | |
| 58 | |
| 59 /** | |
| 60 * Removes all pairs from the map. | |
| 61 */ | |
| 62 void clear(); | |
| 63 | |
| 64 /** | |
| 65 * Applies [f] to each {key, value} pair of the map. | |
| 66 */ | |
| 67 void forEach(void f(K key, V value)); | |
| 68 | |
| 69 /** | |
| 70 * Returns a collection containing all the keys in the map. | |
| 71 */ | |
| 72 Collection<K> getKeys(); | |
| 73 | |
| 74 /** | |
| 75 * Returns a collection containing all the values in the map. | |
| 76 */ | |
| 77 Collection<V> getValues(); | |
| 78 | |
| 79 /** | |
| 80 * The number of {key, value} pairs in the map. | |
| 81 */ | |
| 82 int get length(); | |
| 83 | |
| 84 /** | |
| 85 * Returns true if there is no {key, value} pair in the map. | |
| 86 */ | |
| 87 bool isEmpty(); | |
| 88 } | |
| 89 | |
| 90 /** | |
| 91 * Hash map version of the [Map] interface. A [HashMap] does not | |
| 92 * provide any guarantees on the order of keys and values in [getKeys] | |
| 93 * and [getValues]. | |
| 94 */ | |
| 95 interface HashMap<K extends Hashable, V> extends Map<K, V> | |
| 96 default HashMapImplementation<K extends Hashable, V> { | |
| 97 /** | |
| 98 * Creates a map with the default implementation. | |
| 99 */ | |
| 100 HashMap(); | |
| 101 | |
| 102 /** | |
| 103 * Creates a [HashMap] that contains all key value pairs of [other]. | |
| 104 */ | |
| 105 HashMap.from(Map<K, V> other); | |
| 106 } | |
| 107 | |
| 108 /** | |
| 109 * Hash map version of the [Map] interface that preserves insertion | |
| 110 * order. | |
| 111 */ | |
| 112 interface LinkedHashMap<K extends Hashable, V> extends HashMap<K, V> | |
| 113 default LinkedHashMapImplementation<K extends Hashable, V> { | |
| 114 /** | |
| 115 * Creates a map with the default implementation. | |
| 116 */ | |
| 117 LinkedHashMap(); | |
| 118 | |
| 119 /** | |
| 120 * Creates a [LinkedHashMap] that contains all key value pairs of [other]. | |
| 121 */ | |
| 122 LinkedHashMap.from(Map<K, V> other); | |
| 123 } | |
| OLD | NEW |