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

Unified Diff: pkg/yaml/lib/src/yaml_map.dart

Issue 274953002: Bring the YAML package's style up to modern standards. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: pkg/yaml/lib/src/yaml_map.dart
diff --git a/pkg/yaml/lib/src/yaml_map.dart b/pkg/yaml/lib/src/yaml_map.dart
index ab07c72b48d5aa98823159d954a10e5c8aa4d976..44c999f14e17c5f3aefd5d9cd42f6a2b2e58e8f8 100644
--- a/pkg/yaml/lib/src/yaml_map.dart
+++ b/pkg/yaml/lib/src/yaml_map.dart
@@ -2,86 +2,39 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
-library yaml_map;
+library yaml.map;
+
+import 'dart:collection';
+
+import 'package:collection/collection.dart';
import 'deep_equals.dart';
import 'utils.dart';
-/// This class wraps behaves almost identically to the normal Dart Map
+/// This class behaves almost identically to the normal Dart [Map]
/// implementation, with the following differences:
///
-/// * It allows null, NaN, boolean, list, and map keys.
+/// * It NaN, list, and map keys.
Bob Nystrom 2014/05/09 00:18:56 "It NaN" -> "It allows NaN".
nweiz 2014/05/20 00:15:07 Done.
/// * It defines `==` structurally. That is, `yamlMap1 == yamlMap2` if they
/// have the same contents.
/// * It has a compatible [hashCode] method.
-class YamlMap implements Map {
- final Map _map;
-
- YamlMap() : _map = new Map();
-
- YamlMap.from(Map map) : _map = new Map.from(map);
-
- YamlMap._wrap(this._map);
-
- void addAll(Map other) {
- other.forEach((key, value) {
- this[key] = value;
- });
+///
+/// This class is deprecated. In future releases, this package will use
+/// a [HashMap] with a custom equality operation rather than a custom class.
+@Deprecated('1.0.0')
+class YamlMap extends DelegatingMap {
+ YamlMap()
+ : super(new HashMap(equals: deepEquals, hashCode: hashCodeFor));
+
+ YamlMap.from(Map map)
+ : super(new HashMap(equals: deepEquals, hashCode: hashCodeFor)) {
+ addAll(map);
}
- bool containsValue(value) => _map.containsValue(value);
- bool containsKey(key) => _map.containsKey(_wrapKey(key));
- operator [](key) => _map[_wrapKey(key)];
- operator []=(key, value) { _map[_wrapKey(key)] = value; }
- putIfAbsent(key, ifAbsent()) => _map.putIfAbsent(_wrapKey(key), ifAbsent);
- remove(key) => _map.remove(_wrapKey(key));
- void clear() => _map.clear();
- void forEach(void f(key, value)) =>
- _map.forEach((k, v) => f(_unwrapKey(k), v));
- Iterable get keys => _map.keys.map(_unwrapKey);
- Iterable get values => _map.values;
- int get length => _map.length;
- bool get isEmpty => _map.isEmpty;
- bool get isNotEmpty => _map.isNotEmpty;
- String toString() => _map.toString();
-
- int get hashCode => hashCodeFor(_map);
+ int get hashCode => hashCodeFor(this);
bool operator ==(other) {
if (other is! YamlMap) return false;
return deepEquals(this, other);
}
-
- /// Wraps an object for use as a key in the map.
- _wrapKey(obj) {
- if (obj != null && obj is! bool && obj is! List &&
- (obj is! double || !obj.isNan) &&
- (obj is! Map || obj is YamlMap)) {
- return obj;
- } else if (obj is Map) {
- return new YamlMap._wrap(obj);
- }
- return new _WrappedHashKey(obj);
- }
-
- /// Unwraps an object that was used as a key in the map.
- _unwrapKey(obj) => obj is _WrappedHashKey ? obj.value : obj;
-}
-
-/// A class for wrapping normally-unhashable objects that are being used as keys
-/// in a YamlMap.
-class _WrappedHashKey {
- final value;
-
- _WrappedHashKey(this.value);
-
- int get hashCode => hashCodeFor(value);
-
- String toString() => value.toString();
-
- /// This is defined as both values being structurally equal.
- bool operator ==(other) {
- if (other is! _WrappedHashKey) return false;
- return deepEquals(this.value, other.value);
- }
}

Powered by Google App Engine
This is Rietveld 408576698