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

Unified Diff: editor/util/plugins/com.google.dart.java2dart/resources/utilities_collection_include.dart

Issue 243263004: New analyzer snapshot. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 8 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
Index: editor/util/plugins/com.google.dart.java2dart/resources/utilities_collection_include.dart
diff --git a/editor/util/plugins/com.google.dart.java2dart/resources/utilities_collection_include.dart b/editor/util/plugins/com.google.dart.java2dart/resources/utilities_collection_include.dart
new file mode 100644
index 0000000000000000000000000000000000000000..6d68480ca9b48be7e49029f3696d9c8cec10effb
--- /dev/null
+++ b/editor/util/plugins/com.google.dart.java2dart/resources/utilities_collection_include.dart
@@ -0,0 +1,78 @@
+
+
+/**
+ * Instances of the class `SingleMapIterator` implement an iterator that can be used to access
+ * the entries in a single map.
+ */
+class SingleMapIterator<K, V> implements MapIterator<K, V> {
+ /**
+ * Returns a new [SingleMapIterator] instance for the given [Map].
+ */
+ static SingleMapIterator forMap(Map map) => new SingleMapIterator(map);
+
+ /**
+ * The [Map] containing the entries to be iterated over.
+ */
+ final Map<K, V> _map;
+
+ /**
+ * The iterator used to access the entries.
+ */
+ Iterator<K> _keyIterator;
+
+ /**
+ * The current key, or `null` if there is no current key.
+ */
+ K _currentKey;
+
+ /**
+ * The current value.
+ */
+ V _currentValue;
+
+ /**
+ * Initialize a newly created iterator to return the entries from the given map.
+ *
+ * @param map the map containing the entries to be iterated over
+ */
+ SingleMapIterator(this._map) {
+ this._keyIterator = _map.keys.iterator;
+ }
+
+ @override
+ K get key {
+ if (_currentKey == null) {
+ throw new NoSuchElementException();
+ }
+ return _currentKey;
+ }
+
+ @override
+ V get value {
+ if (_currentKey == null) {
+ throw new NoSuchElementException();
+ }
+ return _currentValue;
+ }
+
+ @override
+ bool moveNext() {
+ if (_keyIterator.moveNext()) {
+ _currentKey = _keyIterator.current;
+ _currentValue = _map[_currentKey];
+ return true;
+ } else {
+ _currentKey = null;
+ return false;
+ }
+ }
+
+ @override
+ void set value(V newValue) {
+ if (_currentKey == null) {
+ throw new NoSuchElementException();
+ }
+ _currentValue = newValue;
+ _map[_currentKey] = newValue;
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698