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 dart2js.mirrors.util; | 5 library dart2js.mirrors.util; |
6 | 6 |
7 import 'dart:collection' show Maps; | 7 import 'dart:collection' show Maps; |
8 | 8 |
9 /** | 9 /** |
10 * An abstract map implementation. This class can be used as a superclass for | 10 * An abstract map implementation. This class can be used as a superclass for |
11 * implementing maps, requiring only the further implementation of the | 11 * implementing maps, requiring only the further implementation of the |
12 * [:operator []:], [:forEach:] and [:length:] methods to provide a fully | 12 * [:operator []:], [:forEach:] and [:length:] methods to provide a fully |
13 * implemented immutable map. | 13 * implemented immutable map. |
14 */ | 14 */ |
| 15 // TODO(lrn): Consider using UnmodifiableBaseMap/UnmodifiableMapWrapper |
| 16 // for these classes, or just rewrite for a bit more efficiency. |
15 abstract class AbstractMap<K, V> implements Map<K, V> { | 17 abstract class AbstractMap<K, V> implements Map<K, V> { |
16 AbstractMap(); | 18 AbstractMap(); |
17 | 19 |
18 AbstractMap.from(Map<K, V> other) { | 20 AbstractMap.from(Map<K, V> other) { |
19 other.forEach((k,v) => this[k] = v); | 21 other.forEach((k,v) => this[k] = v); |
20 } | 22 } |
21 | 23 |
22 void operator []=(K key, value) { | 24 void operator []=(K key, value) { |
23 throw new UnsupportedError('[]= is not supported'); | 25 throw new UnsupportedError('[]= is not supported'); |
24 } | 26 } |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 | 175 |
174 void forEach(void f(K key, Vout value)) { | 176 void forEach(void f(K key, Vout value)) { |
175 _map.forEach((K k, Vin v) { | 177 _map.forEach((K k, Vin v) { |
176 var value = _filter(v); | 178 var value = _filter(v); |
177 if (value != null) { | 179 if (value != null) { |
178 f(k, value); | 180 f(k, value); |
179 } | 181 } |
180 }); | 182 }); |
181 } | 183 } |
182 } | 184 } |
OLD | NEW |