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 22 matching lines...) Expand all Loading... |
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 return _keys.map((String key) => this[key]); | 38 return _keys.map((String key) => this[key]); |
39 } | 39 } |
40 | 40 |
41 bool get isEmpty => length == 0; | 41 bool get isEmpty => length == 0; |
42 | 42 |
| 43 bool get isNotEmpty => !isEmpty; |
| 44 |
43 String toString() => Maps.mapToString(this); | 45 String toString() => Maps.mapToString(this); |
44 | 46 |
45 _throwUnmodifiable() { | 47 _throwUnmodifiable() { |
46 throw new UnsupportedError("Cannot modify unmodifiable Map"); | 48 throw new UnsupportedError("Cannot modify unmodifiable Map"); |
47 } | 49 } |
48 void operator []=(String key, V val) => _throwUnmodifiable(); | 50 void operator []=(String key, V val) => _throwUnmodifiable(); |
49 V putIfAbsent(String key, V ifAbsent()) => _throwUnmodifiable(); | 51 V putIfAbsent(String key, V ifAbsent()) => _throwUnmodifiable(); |
50 V remove(String key) => _throwUnmodifiable(); | 52 V remove(String key) => _throwUnmodifiable(); |
51 void clear() => _throwUnmodifiable(); | 53 void clear() => _throwUnmodifiable(); |
52 } | 54 } |
(...skipping 13 matching lines...) Expand all Loading... |
66 return super[key]; | 68 return super[key]; |
67 } | 69 } |
68 } | 70 } |
69 | 71 |
70 class _ConstantMapKeyIterable extends IterableBase<String> { | 72 class _ConstantMapKeyIterable extends IterableBase<String> { |
71 ConstantMap _map; | 73 ConstantMap _map; |
72 _ConstantMapKeyIterable(this._map); | 74 _ConstantMapKeyIterable(this._map); |
73 | 75 |
74 Iterator<String> get iterator => _map._keys.iterator; | 76 Iterator<String> get iterator => _map._keys.iterator; |
75 } | 77 } |
OLD | NEW |