| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 library yaml_map; | 5 library yaml_map; |
| 6 | 6 |
| 7 import 'deep_equals.dart'; | 7 import 'deep_equals.dart'; |
| 8 import 'utils.dart'; | 8 import 'utils.dart'; |
| 9 | 9 |
| 10 /// This class wraps behaves almost identically to the normal Dart Map | 10 /// This class wraps behaves almost identically to the normal Dart Map |
| 11 /// implementation, with the following differences: | 11 /// implementation, with the following differences: |
| 12 /// | 12 /// |
| 13 /// * It allows null, NaN, boolean, list, and map keys. | 13 /// * It allows null, NaN, boolean, list, and map keys. |
| 14 /// * It defines `==` structurally. That is, `yamlMap1 == yamlMap2` if they | 14 /// * It defines `==` structurally. That is, `yamlMap1 == yamlMap2` if they |
| 15 /// have the same contents. | 15 /// have the same contents. |
| 16 /// * It has a compatible [hashCode] method. | 16 /// * It has a compatible [hashCode] method. |
| 17 class YamlMap implements Map { | 17 class YamlMap implements Map { |
| 18 final Map _map; | 18 final Map _map; |
| 19 | 19 |
| 20 YamlMap() : _map = new Map(); | 20 YamlMap() : _map = new Map(); |
| 21 | 21 |
| 22 YamlMap.from(Map map) : _map = new Map.from(map); | 22 YamlMap.from(Map map) : _map = new Map.from(map); |
| 23 | 23 |
| 24 YamlMap._wrap(this._map); | 24 YamlMap._wrap(this._map); |
| 25 | 25 |
| 26 void addAll(Map other) { |
| 27 other.forEach((key, value) { |
| 28 this[key] = value; |
| 29 }); |
| 30 } |
| 31 |
| 26 bool containsValue(value) => _map.containsValue(value); | 32 bool containsValue(value) => _map.containsValue(value); |
| 27 bool containsKey(key) => _map.containsKey(_wrapKey(key)); | 33 bool containsKey(key) => _map.containsKey(_wrapKey(key)); |
| 28 operator [](key) => _map[_wrapKey(key)]; | 34 operator [](key) => _map[_wrapKey(key)]; |
| 29 operator []=(key, value) { _map[_wrapKey(key)] = value; } | 35 operator []=(key, value) { _map[_wrapKey(key)] = value; } |
| 30 putIfAbsent(key, ifAbsent()) => _map.putIfAbsent(_wrapKey(key), ifAbsent); | 36 putIfAbsent(key, ifAbsent()) => _map.putIfAbsent(_wrapKey(key), ifAbsent); |
| 31 remove(key) => _map.remove(_wrapKey(key)); | 37 remove(key) => _map.remove(_wrapKey(key)); |
| 32 void clear() => _map.clear(); | 38 void clear() => _map.clear(); |
| 33 void forEach(void f(key, value)) => | 39 void forEach(void f(key, value)) => |
| 34 _map.forEach((k, v) => f(_unwrapKey(k), v)); | 40 _map.forEach((k, v) => f(_unwrapKey(k), v)); |
| 35 Iterable get keys => _map.keys.map(_unwrapKey); | 41 Iterable get keys => _map.keys.map(_unwrapKey); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 int get hashCode => hashCodeFor(value); | 78 int get hashCode => hashCodeFor(value); |
| 73 | 79 |
| 74 String toString() => value.toString(); | 80 String toString() => value.toString(); |
| 75 | 81 |
| 76 /// This is defined as both values being structurally equal. | 82 /// This is defined as both values being structurally equal. |
| 77 bool operator ==(other) { | 83 bool operator ==(other) { |
| 78 if (other is! _WrappedHashKey) return false; | 84 if (other is! _WrappedHashKey) return false; |
| 79 return deepEquals(this.value, other.value); | 85 return deepEquals(this.value, other.value); |
| 80 } | 86 } |
| 81 } | 87 } |
| OLD | NEW |