| 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 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 int get hashCode => hashCodeFor(_map); | 48 int get hashCode => hashCodeFor(_map); |
| 49 | 49 |
| 50 bool operator ==(other) { | 50 bool operator ==(other) { |
| 51 if (other is! YamlMap) return false; | 51 if (other is! YamlMap) return false; |
| 52 return deepEquals(this, other); | 52 return deepEquals(this, other); |
| 53 } | 53 } |
| 54 | 54 |
| 55 /// Wraps an object for use as a key in the map. | 55 /// Wraps an object for use as a key in the map. |
| 56 _wrapKey(obj) { | 56 _wrapKey(obj) { |
| 57 if (obj != null && obj is! bool && obj is! List && | 57 if (obj != null && obj is! bool && obj is! List && |
| 58 (obj is! double || !obj.isNan()) && | 58 (obj is! double || !obj.isNan) && |
| 59 (obj is! Map || obj is YamlMap)) { | 59 (obj is! Map || obj is YamlMap)) { |
| 60 return obj; | 60 return obj; |
| 61 } else if (obj is Map) { | 61 } else if (obj is Map) { |
| 62 return new YamlMap._wrap(obj); | 62 return new YamlMap._wrap(obj); |
| 63 } | 63 } |
| 64 return new _WrappedHashKey(obj); | 64 return new _WrappedHashKey(obj); |
| 65 } | 65 } |
| 66 | 66 |
| 67 /// Unwraps an object that was used as a key in the map. | 67 /// Unwraps an object that was used as a key in the map. |
| 68 _unwrapKey(obj) => obj is _WrappedHashKey ? obj.value : obj; | 68 _unwrapKey(obj) => obj is _WrappedHashKey ? obj.value : obj; |
| 69 } | 69 } |
| 70 | 70 |
| 71 /// A class for wrapping normally-unhashable objects that are being used as keys | 71 /// A class for wrapping normally-unhashable objects that are being used as keys |
| 72 /// in a YamlMap. | 72 /// in a YamlMap. |
| 73 class _WrappedHashKey { | 73 class _WrappedHashKey { |
| 74 final value; | 74 final value; |
| 75 | 75 |
| 76 _WrappedHashKey(this.value); | 76 _WrappedHashKey(this.value); |
| 77 | 77 |
| 78 int get hashCode => hashCodeFor(value); | 78 int get hashCode => hashCodeFor(value); |
| 79 | 79 |
| 80 String toString() => value.toString(); | 80 String toString() => value.toString(); |
| 81 | 81 |
| 82 /// This is defined as both values being structurally equal. | 82 /// This is defined as both values being structurally equal. |
| 83 bool operator ==(other) { | 83 bool operator ==(other) { |
| 84 if (other is! _WrappedHashKey) return false; | 84 if (other is! _WrappedHashKey) return false; |
| 85 return deepEquals(this.value, other.value); | 85 return deepEquals(this.value, other.value); |
| 86 } | 86 } |
| 87 } | 87 } |
| OLD | NEW |