| OLD | NEW |
| 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 abstract class LinkedHashMap<K, V> implements HashMap<K, V> { | 21 abstract class LinkedHashMap<K, V> implements HashMap<K, V> { |
| 22 external factory LinkedHashMap({ bool equals(K key1, K key2), | 22 external factory LinkedHashMap({ bool equals(K key1, K key2), |
| 23 int hashCode(K key), | 23 int hashCode(K key), |
| 24 bool isValidKey(potentialKey) }); | 24 bool isValidKey(potentialKey) }); |
| 25 | 25 |
| 26 /** | 26 /** |
| 27 * Creates an insertion-ordered identity-based map. |
| 28 * |
| 29 * Effectively a shorthand for: |
| 30 * new LinkedHashMap(equals: identical, hashCode: identityHashCodeOf) |
| 31 */ |
| 32 external factory LinkedHashMap.identity(); |
| 33 |
| 34 /** |
| 27 * Creates a [LinkedHashMap] that contains all key value pairs of [other]. | 35 * Creates a [LinkedHashMap] that contains all key value pairs of [other]. |
| 28 */ | 36 */ |
| 29 factory LinkedHashMap.from(Map<K, V> other) { | 37 factory LinkedHashMap.from(Map<K, V> other) { |
| 30 return new LinkedHashMap<K, V>()..addAll(other); | 38 return new LinkedHashMap<K, V>()..addAll(other); |
| 31 } | 39 } |
| 32 | 40 |
| 33 /** | 41 /** |
| 34 * Creates a [LinkedHashMap] where the keys and values are computed from the | 42 * Creates a [LinkedHashMap] where the keys and values are computed from the |
| 35 * [iterable]. | 43 * [iterable]. |
| 36 * | 44 * |
| (...skipping 23 matching lines...) Expand all Loading... |
| 60 * overwrites the previous value. | 68 * overwrites the previous value. |
| 61 * | 69 * |
| 62 * It is an error if the two [Iterable]s don't have the same length. | 70 * It is an error if the two [Iterable]s don't have the same length. |
| 63 */ | 71 */ |
| 64 factory LinkedHashMap.fromIterables(Iterable<K> keys, Iterable<V> values) { | 72 factory LinkedHashMap.fromIterables(Iterable<K> keys, Iterable<V> values) { |
| 65 LinkedHashMap<K, V> map = new LinkedHashMap<K, V>(); | 73 LinkedHashMap<K, V> map = new LinkedHashMap<K, V>(); |
| 66 Maps._fillMapWithIterables(map, keys, values); | 74 Maps._fillMapWithIterables(map, keys, values); |
| 67 return map; | 75 return map; |
| 68 } | 76 } |
| 69 } | 77 } |
| OLD | NEW |