Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2056)

Side by Side Diff: sdk/lib/collection/linked_hash_map.dart

Issue 23494027: Make LinkedHashMap also have a factory constructor and be customizable (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 * A hash-table based implementation of [Map]. 8 * A hash-table based implementation of [Map].
9 * 9 *
10 * Keys insertion order is remembered, and keys are iterated in insertion order. 10 * Keys insertion order is remembered, and keys are iterated in insertion order.
11 * Values are iterated in their corresponding key's order. 11 * Values are iterated in their corresponding key's order.
12 * 12 *
13 * The keys of a `LinkedHashMap` must have consistent [Object.operator==] 13 * The keys of a `LinkedHashMap` must have consistent [Object.operator==]
14 * and [Object.hashCode] implementations. This means that the `==` operator 14 * and [Object.hashCode] implementations. This means that the `==` operator
15 * must define a stable equivalence relation on the keys (reflexive, 15 * must define a stable equivalence relation on the keys (reflexive,
16 * anti-symmetric, transitive, and consistent over time), and that `hashCode` 16 * anti-symmetric, transitive, and consistent over time), and that `hashCode`
17 * must be the same for objects that are considered equal by `==`. 17 * must be the same for objects that are considered equal by `==`.
18 * 18 *
19 * The map allows `null` as a key. 19 * The map allows `null` as a key.
20 */ 20 */
21 class LinkedHashMap<K, V> implements HashMap<K, V> { 21 abstract class LinkedHashMap<K, V> implements HashMap<K, V> {
22 external LinkedHashMap(); 22 external factory LinkedHashMap({ bool equals(K key1, K key2),
floitsch 2013/09/05 13:44:28 If we require key1 and key2 to be of type K we mig
Lasse Reichstein Nielsen 2013/09/06 08:49:24 I thought about this and decided that this was the
23 int hashCode(K key) });
23 24
24 /** 25 /**
25 * Creates a [LinkedHashMap] that contains all key value pairs of [other]. 26 * Creates a [LinkedHashMap] that contains all key value pairs of [other].
26 */ 27 */
27 factory LinkedHashMap.from(Map<K, V> other) { 28 factory LinkedHashMap.from(Map<K, V> other) {
28 return new LinkedHashMap<K, V>()..addAll(other); 29 return new LinkedHashMap<K, V>()..addAll(other);
29 } 30 }
30 31
31 /** 32 /**
32 * Creates a [LinkedHashMap] where the keys and values are computed from the 33 * Creates a [LinkedHashMap] where the keys and values are computed from the
(...skipping 24 matching lines...) Expand all
57 * If [keys] contains the same object multiple times, the last occurrence 58 * If [keys] contains the same object multiple times, the last occurrence
58 * overwrites the previous value. 59 * overwrites the previous value.
59 * 60 *
60 * It is an error if the two [Iterable]s don't have the same length. 61 * It is an error if the two [Iterable]s don't have the same length.
61 */ 62 */
62 factory LinkedHashMap.fromIterables(Iterable<K> keys, Iterable<V> values) { 63 factory LinkedHashMap.fromIterables(Iterable<K> keys, Iterable<V> values) {
63 LinkedHashMap<K, V> map = new LinkedHashMap<K, V>(); 64 LinkedHashMap<K, V> map = new LinkedHashMap<K, V>();
64 Maps._fillMapWithIterables(map, keys, values); 65 Maps._fillMapWithIterables(map, keys, values);
65 return map; 66 return map;
66 } 67 }
67
68 external bool containsKey(Object key);
69
70 external bool containsValue(Object value);
71
72 external void addAll(Map<K, V> other);
73
74 external V operator [](Object key);
75
76 external void operator []=(K key, V value);
77
78 external V putIfAbsent(K key, V ifAbsent());
79
80 external V remove(Object key);
81
82 external void clear();
83
84 external void forEach(void action (K key, V value));
85
86 /** The keys of the map, in insertion order. */
87 external Iterable<K> get keys;
88 /** The values of the map, in the order of their corresponding [keys].*/
89 external Iterable<V> get values;
90
91 external int get length;
92
93 external bool get isEmpty;
94
95 external bool get isNotEmpty;
96
97 String toString() => Maps.mapToString(this);
98 } 68 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698