OLD | NEW |
| (Empty) |
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 | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 // This class has no constructor. This is on purpose since the instantiation | |
6 // is shortcut by the compiler. | |
7 class ConstantMap<V> implements Map<String, V> { | |
8 final int length; | |
9 // A constant map is backed by a JavaScript object. | |
10 final _jsObject; | |
11 final List<String> _keys; | |
12 | |
13 bool containsValue(V needle) { | |
14 return getValues().some((V value) => value == needle); | |
15 } | |
16 | |
17 bool containsKey(String key) { | |
18 if (key == '__proto__') return false; | |
19 return jsHasOwnProperty(_jsObject, key); | |
20 } | |
21 | |
22 V operator [](String key) { | |
23 if (!containsKey(key)) return null; | |
24 return jsPropertyAccess(_jsObject, key); | |
25 } | |
26 | |
27 void forEach(void f(String key, V value)) { | |
28 _keys.forEach((String key) => f(key, this[key])); | |
29 } | |
30 | |
31 Collection<String> getKeys() => _keys; | |
32 | |
33 Collection<V> getValues() { | |
34 List<V> result = <V>[]; | |
35 _keys.forEach((String key) => result.add(this[key])); | |
36 return result; | |
37 } | |
38 | |
39 bool isEmpty() => length == 0; | |
40 | |
41 String toString() => Maps.mapToString(this); | |
42 | |
43 _throwImmutable() { | |
44 throw const IllegalAccessException(); | |
45 } | |
46 void operator []=(String key, V val) => _throwImmutable(); | |
47 V putIfAbsent(String key, V ifAbsent()) => _throwImmutable(); | |
48 V remove(String key) => _throwImmutable(); | |
49 void clear() => _throwImmutable(); | |
50 } | |
OLD | NEW |