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 part of _js_helper; | 5 part of _js_helper; |
6 | 6 |
7 // This class has no constructor. This is on purpose since the instantiation | 7 // This class has no constructor. This is on purpose since the instantiation |
8 // is shortcut by the compiler. | 8 // is shortcut by the compiler. |
9 class ConstantMap<V> implements Map<String, V> { | 9 class ConstantMap<V> implements Map<String, V> { |
10 final int length; | 10 final int length; |
(...skipping 17 matching lines...) Expand all Loading... |
28 | 28 |
29 void forEach(void f(String key, V value)) { | 29 void forEach(void f(String key, V value)) { |
30 _keys.forEach((String key) => f(key, this[key])); | 30 _keys.forEach((String key) => f(key, this[key])); |
31 } | 31 } |
32 | 32 |
33 Iterable<String> get keys { | 33 Iterable<String> get keys { |
34 return new _ConstantMapKeyIterable(this); | 34 return new _ConstantMapKeyIterable(this); |
35 } | 35 } |
36 | 36 |
37 Iterable<V> get values { | 37 Iterable<V> get values { |
38 // TODO(floitsch): don't wrap the map twice. | 38 return _keys.map((String key) => this[key]); |
39 return keys.mappedBy((String key) => this[key]); | |
40 } | 39 } |
41 | 40 |
42 bool get isEmpty => length == 0; | 41 bool get isEmpty => length == 0; |
43 | 42 |
44 String toString() => Maps.mapToString(this); | 43 String toString() => Maps.mapToString(this); |
45 | 44 |
46 _throwUnmodifiable() { | 45 _throwUnmodifiable() { |
47 throw new UnsupportedError("Cannot modify unmodifiable Map"); | 46 throw new UnsupportedError("Cannot modify unmodifiable Map"); |
48 } | 47 } |
49 void operator []=(String key, V val) => _throwUnmodifiable(); | 48 void operator []=(String key, V val) => _throwUnmodifiable(); |
(...skipping 17 matching lines...) Expand all Loading... |
67 return super[key]; | 66 return super[key]; |
68 } | 67 } |
69 } | 68 } |
70 | 69 |
71 class _ConstantMapKeyIterable extends Iterable<String> { | 70 class _ConstantMapKeyIterable extends Iterable<String> { |
72 ConstantMap _map; | 71 ConstantMap _map; |
73 _ConstantMapKeyIterable(this._map); | 72 _ConstantMapKeyIterable(this._map); |
74 | 73 |
75 Iterator<String> get iterator => _map._keys.iterator; | 74 Iterator<String> get iterator => _map._keys.iterator; |
76 } | 75 } |
OLD | NEW |