Chromium Code Reviews| Index: sdk/lib/collection/maps.dart |
| diff --git a/sdk/lib/collection/maps.dart b/sdk/lib/collection/maps.dart |
| index bd7d755a6343139193bc5f673e869717b421a59b..03448fa54f07aba7cd4477f6ff74cec239a940e6 100644 |
| --- a/sdk/lib/collection/maps.dart |
| +++ b/sdk/lib/collection/maps.dart |
| @@ -77,4 +77,45 @@ class Maps { |
| * simply return the results of this method applied to the collection. |
| */ |
| static String mapToString(Map m) => ToString.mapToString(m); |
| + |
| + static _id(x) => x; |
| + |
| + /** |
| + * Helper to fill a map with key/value pairs computed from [iterable]. |
|
floitsch
2013/06/27 16:04:32
Fills a map ...
Since it's a private method it ca
zarah
2013/06/27 17:00:07
Done.
|
| + * |
| + * This method is used by Map classes in the named constructor fromIterable. |
| + */ |
| + static void _fillMapWithMappedIterable(Map<K,V> map, Iterable<K> iterable, |
|
floitsch
2013/06/27 16:04:32
Don't use named arguments for internal helper meth
zarah
2013/06/27 17:00:07
Done.
|
| + {K key(element), V value(element)}) { |
| + if (key == null) key = _id; |
| + if (value == null) value = _id; |
| + |
| + for (var element in iterable) { |
| + map[key(element)] = value(element); |
| + } |
| + } |
| + |
| + /** |
| + * Helper to fill a map by associating the [keys] to [values]. |
| + * |
| + * This method is used by Map classes in the named constructor fromIterables. |
| + */ |
| + static void _fillMapWithIterables(Map<K,V> map, Iterable<K> keys, |
| + Iterable<V> values) { |
| + Iterator<K> keyIterator = keys.iterator; |
| + Iterator<V> valueIterator = values.iterator; |
| + |
| + bool hasNextKey = keyIterator.moveNext(); |
| + bool hasNextValue = valueIterator.moveNext(); |
| + |
| + while (hasNextKey && hasNextValue) { |
| + map[keyIterator.current] = valueIterator.current; |
| + hasNextKey = keyIterator.moveNext(); |
| + hasNextValue = valueIterator.moveNext(); |
| + } |
| + |
| + if (hasNextKey || hasNextValue) { |
| + throw new ArgumentError("Iterables do not have same length."); |
| + } |
| + } |
| } |