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

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: code review 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
« no previous file with comments | « pkg/yaml/lib/src/yaml_exception.dart ('k') | pkg/yaml/lib/yaml.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 5e3e20a6f3cf7d50bc77b7d0e4107f2cfb16f43b..ff3da365498f8edc029a8829a205b5e2184762bb 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 allows NaN, list, and map keys.
/// * 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! num || !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);
- }
}
« no previous file with comments | « pkg/yaml/lib/src/yaml_exception.dart ('k') | pkg/yaml/lib/yaml.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698