OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 shelf.shelf_unmodifiable_map; | 5 library shelf.shelf_unmodifiable_map; |
6 | 6 |
7 import 'dart:collection'; | 7 import 'dart:collection'; |
8 | 8 |
9 // TODO(kevmoo): use UnmodifiableMapView from SDK once 1.4 ships | 9 // TODO(kevmoo): MapView lacks a const ctor, so we have to use DelegatingMap |
| 10 // from pkg/collection - https://codereview.chromium.org/294093003/ |
10 import 'package:collection/wrappers.dart' as pc; | 11 import 'package:collection/wrappers.dart' as pc; |
11 | 12 |
12 /// A simple wrapper over [pc.UnmodifiableMapView] which avoids re-wrapping | 13 /// A simple wrapper over [pc.UnmodifiableMapView] which avoids re-wrapping |
13 /// itself. | 14 /// itself. |
14 class ShelfUnmodifiableMap<V> extends pc.UnmodifiableMapView<String, V> { | 15 class ShelfUnmodifiableMap<V> extends UnmodifiableMapView<String, V> { |
15 /// If [source] is a [ShelfUnmodifiableMap] with matching [ignoreKeyCase], | 16 /// If [source] is a [ShelfUnmodifiableMap] with matching [ignoreKeyCase], |
16 /// then [source] is returned. | 17 /// then [source] is returned. |
17 /// | 18 /// |
18 /// If [source] is `null` it is treated like an empty map. | 19 /// If [source] is `null` it is treated like an empty map. |
19 /// | 20 /// |
20 /// If [ignoreKeyCase] is `true`, the keys will have case-insensitive access. | 21 /// If [ignoreKeyCase] is `true`, the keys will have case-insensitive access. |
21 /// | 22 /// |
22 /// [source] is copied to a new [Map] to ensure changes to the paramater value | 23 /// [source] is copied to a new [Map] to ensure changes to the paramater value |
23 /// after constructions are not reflected. | 24 /// after constructions are not reflected. |
24 factory ShelfUnmodifiableMap(Map<String, V> source, | 25 factory ShelfUnmodifiableMap(Map<String, V> source, |
(...skipping 24 matching lines...) Expand all Loading... |
49 } | 50 } |
50 | 51 |
51 ShelfUnmodifiableMap._(Map<String, V> source) : super(source); | 52 ShelfUnmodifiableMap._(Map<String, V> source) : super(source); |
52 } | 53 } |
53 | 54 |
54 /// An const empty implementation of [ShelfUnmodifiableMap]. | 55 /// An const empty implementation of [ShelfUnmodifiableMap]. |
55 class _EmptyShelfUnmodifiableMap<V> extends pc.DelegatingMap<String, V> | 56 class _EmptyShelfUnmodifiableMap<V> extends pc.DelegatingMap<String, V> |
56 implements ShelfUnmodifiableMap<V> { | 57 implements ShelfUnmodifiableMap<V> { |
57 const _EmptyShelfUnmodifiableMap() : super(const {}); | 58 const _EmptyShelfUnmodifiableMap() : super(const {}); |
58 } | 59 } |
OLD | NEW |