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 dart.collection; | 5 part of dart.collection; |
6 | 6 |
7 /* | 7 /* |
8 * Helper class which implements complex [Map] operations | 8 * Helper class which implements complex [Map] operations |
9 * in term of basic ones ([Map.keys], [Map.operator []], | 9 * in term of basic ones ([Map.keys], [Map.operator []], |
10 * [Map.operator []=] and [Map.remove].) Not all methods are | 10 * [Map.operator []=] and [Map.remove].) Not all methods are |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 } | 44 } |
45 } | 45 } |
46 | 46 |
47 static forEach(Map map, void f(key, value)) { | 47 static forEach(Map map, void f(key, value)) { |
48 for (final k in map.keys) { | 48 for (final k in map.keys) { |
49 f(k, map[k]); | 49 f(k, map[k]); |
50 } | 50 } |
51 } | 51 } |
52 | 52 |
53 static Iterable getValues(Map map) { | 53 static Iterable getValues(Map map) { |
54 return map.keys.mappedBy((key) => map[key]); | 54 return map.keys.map((key) => map[key]); |
55 } | 55 } |
56 | 56 |
57 static int length(Map map) => map.keys.length; | 57 static int length(Map map) => map.keys.length; |
58 | 58 |
59 static bool isEmpty(Map map) => map.keys.isEmpty; | 59 static bool isEmpty(Map map) => map.keys.isEmpty; |
60 | 60 |
61 /** | 61 /** |
62 * Returns a string representing the specified map. The returned string | 62 * Returns a string representing the specified map. The returned string |
63 * looks like this: [:'{key0: value0, key1: value1, ... keyN: valueN}':]. | 63 * looks like this: [:'{key0: value0, key1: value1, ... keyN: valueN}':]. |
64 * The value returned by its [toString] method is used to represent each | 64 * The value returned by its [toString] method is used to represent each |
65 * key or value. | 65 * key or value. |
66 * | 66 * |
67 * If the map collection contains a reference to itself, either | 67 * If the map collection contains a reference to itself, either |
68 * directly as a key or value, or indirectly through other collections | 68 * directly as a key or value, or indirectly through other collections |
69 * or maps, the contained reference is rendered as [:'{...}':]. This | 69 * or maps, the contained reference is rendered as [:'{...}':]. This |
70 * prevents the infinite regress that would otherwise occur. So, for example, | 70 * prevents the infinite regress that would otherwise occur. So, for example, |
71 * calling this method on a map whose sole entry maps the string key 'me' | 71 * calling this method on a map whose sole entry maps the string key 'me' |
72 * to a reference to the map would return [:'{me: {...}}':]. | 72 * to a reference to the map would return [:'{me: {...}}':]. |
73 * | 73 * |
74 * A typical implementation of a map's [toString] method will | 74 * A typical implementation of a map's [toString] method will |
75 * simply return the results of this method applied to the collection. | 75 * simply return the results of this method applied to the collection. |
76 */ | 76 */ |
77 static String mapToString(Map m) => ToString.mapToString(m); | 77 static String mapToString(Map m) => ToString.mapToString(m); |
78 } | 78 } |
OLD | NEW |