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

Unified Diff: sdk/lib/collection/maps.dart

Issue 1319783003: Add static ensure() methods to unmodifiable views. Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Code review changes Created 5 years, 4 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 | « sdk/lib/collection/collections.dart ('k') | tests/corelib/map_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/collection/maps.dart
diff --git a/sdk/lib/collection/maps.dart b/sdk/lib/collection/maps.dart
index 7945e7ea643411074c5e65769a5870c0733913c7..06dde937cf4a362483200ce9d54904f9738de074 100644
--- a/sdk/lib/collection/maps.dart
+++ b/sdk/lib/collection/maps.dart
@@ -208,8 +208,21 @@ class MapView<K, V> implements Map<K, V> {
* the constructor, except for operations that modify the map.
* Modifying operations throw instead.
*/
-class UnmodifiableMapView<K, V> =
- MapView<K, V> with _UnmodifiableMapMixin<K, V>;
+class UnmodifiableMapView<K, V> extends MapView<K, V>
+ with _UnmodifiableMapMixin<K, V> {
+ UnmodifiableMapView(Map<K, V> map) : super(map);
+
+ /**
+ * Returns a view of [source] that's guaranteed to be unmodifiable.
+ *
+ * If [source] already extends [UnmodifiableMapBase] or [UnmodifiableMapView],
+ * it is returned without re-wrapping it.
+ */
+ static Map ensure(Map source) =>
+ source is _UnmodifiableMapMixin
+ ? source
+ : new UnmodifiableMapView(source);
+}
/**
* Helper class which implements complex [Map] operations
« no previous file with comments | « sdk/lib/collection/collections.dart ('k') | tests/corelib/map_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698