Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(626)

Unified Diff: sdk/lib/collection/maps.dart

Issue 18072004: Add fromIterable(s) constructors in SplayTreeMap and LinkedHashMap. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Removed long line. Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sdk/lib/collection/linked_hash_map.dart ('k') | sdk/lib/collection/splay_tree.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/collection/maps.dart
diff --git a/sdk/lib/collection/maps.dart b/sdk/lib/collection/maps.dart
index bd7d755a6343139193bc5f673e869717b421a59b..303008cc6950a815089473c7b0f4e181b89cda13 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;
+
+ /**
+ * Fills a map with key/value pairs computed from [iterable].
+ *
+ * This method is used by Map classes in the named constructor fromIterable.
+ */
+ static void _fillMapWithMappedIterable(Map map, Iterable iterable,
+ key(element), value(element)) {
+ if (key == null) key = _id;
+ if (value == null) value = _id;
+
+ for (var element in iterable) {
+ map[key(element)] = value(element);
+ }
+ }
+
+ /**
+ * Fills a map by associating the [keys] to [values].
+ *
+ * This method is used by Map classes in the named constructor fromIterables.
+ */
+ static void _fillMapWithIterables(Map map, Iterable keys,
+ Iterable values) {
+ Iterator keyIterator = keys.iterator;
+ Iterator 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.");
+ }
+ }
}
« no previous file with comments | « sdk/lib/collection/linked_hash_map.dart ('k') | sdk/lib/collection/splay_tree.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698