mirror of
https://github.com/dart-lang/sdk
synced 2024-09-06 00:59:09 +00:00
Remove unused MapIterator and implementations.
R=brianwilkerson@google.com Change-Id: If433e5d7065b6635f8b9bfca1c495f16455dc68c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/118883 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
parent
fa879f2b18
commit
bd3792e714
|
@ -81,233 +81,6 @@ class BooleanArray {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The interface `MapIterator` defines the behavior of objects that iterate over the entries
|
||||
* in a map.
|
||||
*
|
||||
* This interface defines the concept of a current entry and provides methods to access the key and
|
||||
* value in the current entry. When an iterator is first created it will be positioned before the
|
||||
* first entry and there is no current entry until [moveNext] is invoked. When all of the
|
||||
* entries have been accessed there will also be no current entry.
|
||||
*
|
||||
* There is no guarantee made about the order in which the entries are accessible.
|
||||
*/
|
||||
abstract class MapIterator<K, V> {
|
||||
/**
|
||||
* Return the key associated with the current element.
|
||||
*
|
||||
* @return the key associated with the current element
|
||||
* @throws NoSuchElementException if there is no current element
|
||||
*/
|
||||
K get key;
|
||||
|
||||
/**
|
||||
* Return the value associated with the current element.
|
||||
*
|
||||
* @return the value associated with the current element
|
||||
* @throws NoSuchElementException if there is no current element
|
||||
*/
|
||||
V get value;
|
||||
|
||||
/**
|
||||
* Set the value associated with the current element to the given value.
|
||||
*
|
||||
* @param newValue the new value to be associated with the current element
|
||||
* @throws NoSuchElementException if there is no current element
|
||||
*/
|
||||
void set value(V newValue);
|
||||
|
||||
/**
|
||||
* Advance to the next entry in the map. Return `true` if there is a current element that
|
||||
* can be accessed after this method returns. It is safe to invoke this method even if the
|
||||
* previous invocation returned `false`.
|
||||
*
|
||||
* @return `true` if there is a current element that can be accessed
|
||||
*/
|
||||
bool moveNext();
|
||||
}
|
||||
|
||||
/**
|
||||
* Instances of the class `MultipleMapIterator` implement an iterator that can be used to
|
||||
* sequentially access the entries in multiple maps.
|
||||
*/
|
||||
class MultipleMapIterator<K, V> implements MapIterator<K, V> {
|
||||
/**
|
||||
* The iterators used to access the entries.
|
||||
*/
|
||||
List<MapIterator<K, V>> _iterators;
|
||||
|
||||
/**
|
||||
* The index of the iterator currently being used to access the entries.
|
||||
*/
|
||||
int _iteratorIndex = -1;
|
||||
|
||||
/**
|
||||
* The current iterator, or `null` if there is no current iterator.
|
||||
*/
|
||||
MapIterator<K, V> _currentIterator;
|
||||
|
||||
/**
|
||||
* Initialize a newly created iterator to return the entries from the given maps.
|
||||
*
|
||||
* @param maps the maps containing the entries to be iterated
|
||||
*/
|
||||
MultipleMapIterator(List<Map<K, V>> maps) {
|
||||
int count = maps.length;
|
||||
_iterators = new List<MapIterator<K, V>>(count);
|
||||
for (int i = 0; i < count; i++) {
|
||||
_iterators[i] = new SingleMapIterator<K, V>(maps[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
K get key {
|
||||
if (_currentIterator == null) {
|
||||
throw new StateError('No element');
|
||||
}
|
||||
return _currentIterator.key;
|
||||
}
|
||||
|
||||
@override
|
||||
V get value {
|
||||
if (_currentIterator == null) {
|
||||
throw new StateError('No element');
|
||||
}
|
||||
return _currentIterator.value;
|
||||
}
|
||||
|
||||
@override
|
||||
void set value(V newValue) {
|
||||
if (_currentIterator == null) {
|
||||
throw new StateError('No element');
|
||||
}
|
||||
_currentIterator.value = newValue;
|
||||
}
|
||||
|
||||
@override
|
||||
bool moveNext() {
|
||||
if (_iteratorIndex < 0) {
|
||||
if (_iterators.isEmpty) {
|
||||
_currentIterator = null;
|
||||
return false;
|
||||
}
|
||||
if (_advanceToNextIterator()) {
|
||||
return true;
|
||||
} else {
|
||||
_currentIterator = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (_currentIterator.moveNext()) {
|
||||
return true;
|
||||
} else if (_advanceToNextIterator()) {
|
||||
return true;
|
||||
} else {
|
||||
_currentIterator = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Under the assumption that there are no more entries that can be returned using the current
|
||||
* iterator, advance to the next iterator that has entries.
|
||||
*
|
||||
* @return `true` if there is a current iterator that has entries
|
||||
*/
|
||||
bool _advanceToNextIterator() {
|
||||
_iteratorIndex++;
|
||||
while (_iteratorIndex < _iterators.length) {
|
||||
MapIterator<K, V> iterator = _iterators[_iteratorIndex];
|
||||
if (iterator.moveNext()) {
|
||||
_currentIterator = iterator;
|
||||
return true;
|
||||
}
|
||||
_iteratorIndex++;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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> {
|
||||
/**
|
||||
* 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 StateError('No element');
|
||||
}
|
||||
return _currentKey;
|
||||
}
|
||||
|
||||
@override
|
||||
V get value {
|
||||
if (_currentKey == null) {
|
||||
throw new StateError('No element');
|
||||
}
|
||||
if (_currentValue == null) {
|
||||
_currentValue = _map[_currentKey];
|
||||
}
|
||||
return _currentValue;
|
||||
}
|
||||
|
||||
@override
|
||||
void set value(V newValue) {
|
||||
if (_currentKey == null) {
|
||||
throw new StateError('No element');
|
||||
}
|
||||
_currentValue = newValue;
|
||||
_map[_currentKey] = newValue;
|
||||
}
|
||||
|
||||
@override
|
||||
bool moveNext() {
|
||||
if (_keyIterator.moveNext()) {
|
||||
_currentKey = _keyIterator.current;
|
||||
_currentValue = null;
|
||||
return true;
|
||||
} else {
|
||||
_currentKey = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new [SingleMapIterator] instance for the given [Map].
|
||||
*/
|
||||
static SingleMapIterator forMap(Map map) => new SingleMapIterator(map);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instances of the class `TokenMap` map one set of tokens to another set of tokens.
|
||||
*/
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'dart:collection';
|
||||
|
||||
import 'package:analyzer/dart/analysis/features.dart';
|
||||
import 'package:analyzer/dart/ast/ast.dart';
|
||||
import 'package:analyzer/dart/ast/standard_ast_factory.dart';
|
||||
|
@ -31,9 +29,7 @@ main() {
|
|||
defineReflectiveTests(BooleanArrayTest);
|
||||
defineReflectiveTests(ExceptionHandlingDelegatingAstVisitorTest);
|
||||
defineReflectiveTests(LineInfoTest);
|
||||
defineReflectiveTests(MultipleMapIteratorTest);
|
||||
defineReflectiveTests(NodeReplacerTest);
|
||||
defineReflectiveTests(SingleMapIteratorTest);
|
||||
defineReflectiveTests(SourceRangeTest);
|
||||
defineReflectiveTests(StringUtilitiesTest);
|
||||
defineReflectiveTests(TokenMapTest);
|
||||
|
@ -2607,112 +2603,6 @@ class ListGetter_NodeReplacerTest_testSwitchMember_2
|
|||
NodeList<Statement> getList(SwitchMember node) => node.statements;
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class MultipleMapIteratorTest {
|
||||
void test_multipleMaps_firstEmpty() {
|
||||
Map<String, String> map1 = new HashMap<String, String>();
|
||||
Map<String, String> map2 = new HashMap<String, String>();
|
||||
map2["k2"] = "v2";
|
||||
Map<String, String> map3 = new HashMap<String, String>();
|
||||
map3["k3"] = "v3";
|
||||
MultipleMapIterator<String, String> iterator =
|
||||
_iterator([map1, map2, map3]);
|
||||
expect(iterator.moveNext(), isTrue);
|
||||
expect(iterator.moveNext(), isTrue);
|
||||
expect(iterator.moveNext(), isFalse);
|
||||
}
|
||||
|
||||
void test_multipleMaps_lastEmpty() {
|
||||
Map<String, String> map1 = new HashMap<String, String>();
|
||||
map1["k1"] = "v1";
|
||||
Map<String, String> map2 = new HashMap<String, String>();
|
||||
map2["k2"] = "v2";
|
||||
Map<String, String> map3 = new HashMap<String, String>();
|
||||
MultipleMapIterator<String, String> iterator =
|
||||
_iterator([map1, map2, map3]);
|
||||
expect(iterator.moveNext(), isTrue);
|
||||
expect(iterator.moveNext(), isTrue);
|
||||
expect(iterator.moveNext(), isFalse);
|
||||
}
|
||||
|
||||
void test_multipleMaps_middleEmpty() {
|
||||
Map<String, String> map1 = new HashMap<String, String>();
|
||||
map1["k1"] = "v1";
|
||||
Map<String, String> map2 = new HashMap<String, String>();
|
||||
Map<String, String> map3 = new HashMap<String, String>();
|
||||
map3["k3"] = "v3";
|
||||
MultipleMapIterator<String, String> iterator =
|
||||
_iterator([map1, map2, map3]);
|
||||
expect(iterator.moveNext(), isTrue);
|
||||
expect(iterator.moveNext(), isTrue);
|
||||
expect(iterator.moveNext(), isFalse);
|
||||
}
|
||||
|
||||
void test_multipleMaps_nonEmpty() {
|
||||
Map<String, String> map1 = new HashMap<String, String>();
|
||||
map1["k1"] = "v1";
|
||||
Map<String, String> map2 = new HashMap<String, String>();
|
||||
map2["k2"] = "v2";
|
||||
Map<String, String> map3 = new HashMap<String, String>();
|
||||
map3["k3"] = "v3";
|
||||
MultipleMapIterator<String, String> iterator =
|
||||
_iterator([map1, map2, map3]);
|
||||
expect(iterator.moveNext(), isTrue);
|
||||
expect(iterator.moveNext(), isTrue);
|
||||
expect(iterator.moveNext(), isTrue);
|
||||
expect(iterator.moveNext(), isFalse);
|
||||
}
|
||||
|
||||
void test_noMap() {
|
||||
MultipleMapIterator<String, String> iterator = _iterator([]);
|
||||
expect(iterator.moveNext(), isFalse);
|
||||
expect(iterator.moveNext(), isFalse);
|
||||
}
|
||||
|
||||
void test_singleMap_empty() {
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
MultipleMapIterator<String, String> iterator = _iterator([map]);
|
||||
expect(iterator.moveNext(), isFalse);
|
||||
expect(() => iterator.key, throwsStateError);
|
||||
expect(() => iterator.value, throwsStateError);
|
||||
expect(() {
|
||||
iterator.value = 'x';
|
||||
}, throwsStateError);
|
||||
}
|
||||
|
||||
void test_singleMap_multiple() {
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
map["k1"] = "v1";
|
||||
map["k2"] = "v2";
|
||||
map["k3"] = "v3";
|
||||
MultipleMapIterator<String, String> iterator = _iterator([map]);
|
||||
expect(iterator.moveNext(), isTrue);
|
||||
expect(iterator.moveNext(), isTrue);
|
||||
expect(iterator.moveNext(), isTrue);
|
||||
expect(iterator.moveNext(), isFalse);
|
||||
}
|
||||
|
||||
void test_singleMap_single() {
|
||||
String key = "key";
|
||||
String value = "value";
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
map[key] = value;
|
||||
MultipleMapIterator<String, String> iterator = _iterator([map]);
|
||||
expect(iterator.moveNext(), isTrue);
|
||||
expect(iterator.key, same(key));
|
||||
expect(iterator.value, same(value));
|
||||
String newValue = "newValue";
|
||||
iterator.value = newValue;
|
||||
expect(iterator.value, same(newValue));
|
||||
expect(iterator.moveNext(), isFalse);
|
||||
}
|
||||
|
||||
MultipleMapIterator<String, String> _iterator(
|
||||
List<Map<String, String>> maps) {
|
||||
return new MultipleMapIterator<String, String>(maps);
|
||||
}
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class NodeReplacerTest {
|
||||
/**
|
||||
|
@ -3699,51 +3589,6 @@ abstract class NodeReplacerTest_ListGetter<P extends AstNode, C extends AstNode>
|
|||
NodeList<C> getList(P parent);
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class SingleMapIteratorTest {
|
||||
void test_empty() {
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
SingleMapIterator<String, String> iterator =
|
||||
new SingleMapIterator<String, String>(map);
|
||||
expect(iterator.moveNext(), isFalse);
|
||||
expect(() => iterator.key, throwsStateError);
|
||||
expect(() => iterator.value, throwsStateError);
|
||||
expect(() {
|
||||
iterator.value = 'x';
|
||||
}, throwsStateError);
|
||||
expect(iterator.moveNext(), isFalse);
|
||||
}
|
||||
|
||||
void test_multiple() {
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
map["k1"] = "v1";
|
||||
map["k2"] = "v2";
|
||||
map["k3"] = "v3";
|
||||
SingleMapIterator<String, String> iterator =
|
||||
new SingleMapIterator<String, String>(map);
|
||||
expect(iterator.moveNext(), isTrue);
|
||||
expect(iterator.moveNext(), isTrue);
|
||||
expect(iterator.moveNext(), isTrue);
|
||||
expect(iterator.moveNext(), isFalse);
|
||||
}
|
||||
|
||||
void test_single() {
|
||||
String key = "key";
|
||||
String value = "value";
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
map[key] = value;
|
||||
SingleMapIterator<String, String> iterator =
|
||||
new SingleMapIterator<String, String>(map);
|
||||
expect(iterator.moveNext(), isTrue);
|
||||
expect(iterator.key, same(key));
|
||||
expect(iterator.value, same(value));
|
||||
String newValue = "newValue";
|
||||
iterator.value = newValue;
|
||||
expect(iterator.value, same(newValue));
|
||||
expect(iterator.moveNext(), isFalse);
|
||||
}
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class SourceRangeTest {
|
||||
void test_access() {
|
||||
|
|
Loading…
Reference in a new issue