Line data Source code
1 : // Copyright (c) 2016, 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 : import 'dart:collection'; 6 : 7 : import 'equality.dart'; 8 : import 'wrappers.dart'; 9 : 10 : /// A [Map] whose key equality is determined by an [Equality] object. 11 : class EqualityMap<K, V> extends DelegatingMap<K, V> { 12 : /// Creates a map with equality based on [equality]. 13 0 : EqualityMap(Equality<K> equality) 14 0 : : super(LinkedHashMap( 15 0 : equals: equality.equals, 16 0 : hashCode: equality.hash, 17 0 : isValidKey: equality.isValidKey)); 18 : 19 : /// Creates a map with equality based on [equality] that contains all 20 : /// key-value pairs of [other]. 21 : /// 22 : /// If [other] has multiple keys that are equivalent according to [equality], 23 : /// the last one reached during iteration takes precedence. 24 0 : EqualityMap.from(Equality<K> equality, Map<K, V> other) 25 0 : : super(LinkedHashMap( 26 0 : equals: equality.equals, 27 0 : hashCode: equality.hash, 28 0 : isValidKey: equality.isValidKey)) { 29 0 : addAll(other); 30 : } 31 : }