dartfmt -w --fix dart:collection
Change-Id: Ia643bb49fe22150f794a187a71c19ad4c61b5694
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/96663
Reviewed-by: Lasse R.H. Nielsen <lrn@google.com>
Commit-Queue: Kevin Moore <kevmoo@google.com>
diff --git a/runtime/observatory/tests/service/step_through_mixin_from_sdk_test.dart b/runtime/observatory/tests/service/step_through_mixin_from_sdk_test.dart
index a38c966..9f70deb 100644
--- a/runtime/observatory/tests/service/step_through_mixin_from_sdk_test.dart
+++ b/runtime/observatory/tests/service/step_through_mixin_from_sdk_test.dart
@@ -33,23 +33,23 @@
List<String> stops = [];
List<String> expected = [
- "$file:${LINE+0}:17", // on "Foo" (in "new Foo()")
- "$file:${LINE+1}:11", // on "="
- "list.dart:105:24", // on parameter to "contains"
- "list.dart:106:23", // on "length" in "this.length"
- "list.dart:107:16", // on "=" in "i = 0"
- "list.dart:107:23", // on "<" in "i < length"
- "list.dart:108:15", // on "[" in "this[i]"
- "$file:${LINE+13}:23", // on parameter in "operator []"
- "$file:${LINE+14}:5", // on "return"
- "list.dart:108:19", // on "=="
- "list.dart:109:26", // on "length" in "this.length"
- "list.dart:109:18", // on "!="
- "list.dart:107:34", // on "++" in "i++"
- "list.dart:107:23", // on "<" in "i < length"
- "list.dart:113:5", // on "return"
- "$file:${LINE+4}:5", // on "print"
- "$file:${LINE+6}:1" // on ending '}'
+ "$file:${LINE + 0}:17", // on "Foo" (in "new Foo()")
+ "$file:${LINE + 1}:11", // on "="
+ "list.dart:100:24", // on parameter to "contains"
+ "list.dart:101:23", // on "length" in "this.length"
+ "list.dart:102:16", // on "=" in "i = 0"
+ "list.dart:102:23", // on "<" in "i < length"
+ "list.dart:103:15", // on "[" in "this[i]"
+ "$file:${LINE + 13}:23", // on parameter in "operator []"
+ "$file:${LINE + 14}:5", // on "return"
+ "list.dart:103:19", // on "=="
+ "list.dart:104:26", // on "length" in "this.length"
+ "list.dart:104:18", // on "!="
+ "list.dart:102:34", // on "++" in "i++"
+ "list.dart:102:23", // on "<" in "i < length"
+ "list.dart:108:5", // on "return"
+ "$file:${LINE + 4}:5", // on "print"
+ "$file:${LINE + 6}:1" // on ending '}'
];
var tests = <IsolateTest>[
diff --git a/sdk/lib/collection/collection.dart b/sdk/lib/collection/collection.dart
index 7c667ec..b050a48 100644
--- a/sdk/lib/collection/collection.dart
+++ b/sdk/lib/collection/collection.dart
@@ -2,15 +2,13 @@
// 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.
-/**
- * Classes and utilities that supplement the collection support in dart:core.
- *
- * To use this library in your code:
- *
- * import 'dart:collection';
- *
- * {@category Core}
- */
+/// Classes and utilities that supplement the collection support in dart:core.
+///
+/// To use this library in your code:
+///
+/// import 'dart:collection';
+///
+/// {@category Core}
library dart.collection;
import 'dart:_internal' hide Symbol;
diff --git a/sdk/lib/collection/collections.dart b/sdk/lib/collection/collections.dart
index d02257b..9b43996 100644
--- a/sdk/lib/collection/collections.dart
+++ b/sdk/lib/collection/collections.dart
@@ -4,24 +4,20 @@
part of dart.collection;
-/**
- * An unmodifiable [List] view of another List.
- *
- * The source of the elements may be a [List] or any [Iterable] with
- * efficient [Iterable.length] and [Iterable.elementAt].
- */
+/// An unmodifiable [List] view of another List.
+///
+/// The source of the elements may be a [List] or any [Iterable] with
+/// efficient [Iterable.length] and [Iterable.elementAt].
class UnmodifiableListView<E> extends UnmodifiableListBase<E> {
final Iterable<E> _source;
- /**
- * Creates an unmodifiable list backed by [source].
- *
- * The [source] of the elements may be a [List] or any [Iterable] with
- * efficient [Iterable.length] and [Iterable.elementAt].
- */
+ /// Creates an unmodifiable list backed by [source].
+ ///
+ /// The [source] of the elements may be a [List] or any [Iterable] with
+ /// efficient [Iterable.length] and [Iterable.elementAt].
UnmodifiableListView(Iterable<E> source) : _source = source;
- List<R> cast<R>() => new UnmodifiableListView(_source.cast<R>());
+ List<R> cast<R>() => UnmodifiableListView(_source.cast<R>());
int get length => _source.length;
E operator [](int index) => _source.elementAt(index);
diff --git a/sdk/lib/collection/hash_map.dart b/sdk/lib/collection/hash_map.dart
index 728ff9e6..525f43a 100644
--- a/sdk/lib/collection/hash_map.dart
+++ b/sdk/lib/collection/hash_map.dart
@@ -4,165 +4,152 @@
part of dart.collection;
-/** Default function for equality comparison in customized HashMaps */
+/// Default function for equality comparison in customized HashMaps
bool _defaultEquals(a, b) => a == b;
-/** Default function for hash-code computation in customized HashMaps */
+
+/// Default function for hash-code computation in customized HashMaps
int _defaultHashCode(a) => a.hashCode;
-/** Type of custom equality function */
-typedef bool _Equality<K>(K a, K b);
-/** Type of custom hash code function. */
-typedef int _Hasher<K>(K object);
+/// Type of custom equality function
+typedef _Equality<K> = bool Function(K a, K b);
-/**
- * A hash-table based implementation of [Map].
- *
- * The keys of a `HashMap` must have consistent [Object.==]
- * and [Object.hashCode] implementations. This means that the `==` operator
- * must define a stable equivalence relation on the keys (reflexive,
- * symmetric, transitive, and consistent over time), and that `hashCode`
- * must be the same for objects that are considered equal by `==`.
- *
- * The map allows `null` as a key.
- *
- * Iterating the map's keys, values or entries (through [forEach])
- * may happen in any order.
- * The iteration order only changes when the map is modified.
- * Values are iterated in the same order as their associated keys,
- * so iterating the [keys] and [values] in parallel
- * will give matching key and value pairs.
- */
+/// Type of custom hash code function.
+typedef _Hasher<K> = int Function(K object);
+
+/// A hash-table based implementation of [Map].
+///
+/// The keys of a `HashMap` must have consistent [Object.==]
+/// and [Object.hashCode] implementations. This means that the `==` operator
+/// must define a stable equivalence relation on the keys (reflexive,
+/// symmetric, transitive, and consistent over time), and that `hashCode`
+/// must be the same for objects that are considered equal by `==`.
+///
+/// The map allows `null` as a key.
+///
+/// Iterating the map's keys, values or entries (through [forEach])
+/// may happen in any order.
+/// The iteration order only changes when the map is modified.
+/// Values are iterated in the same order as their associated keys,
+/// so iterating the [keys] and [values] in parallel
+/// will give matching key and value pairs.
abstract class HashMap<K, V> implements Map<K, V> {
- /**
- * Creates an unordered hash-table based [Map].
- *
- * The created map is not ordered in any way. When iterating the keys or
- * values, the iteration order is unspecified except that it will stay the
- * same as long as the map isn't changed.
- *
- * If [equals] is provided, it is used to compare the keys in the table with
- * new keys. If [equals] is omitted, the key's own [Object.==] is used
- * instead.
- *
- * Similar, if [hashCode] is provided, it is used to produce a hash value
- * for keys in order to place them in the hash table. If it is omitted, the
- * key's own [Object.hashCode] is used.
- *
- * If using methods like [operator []], [remove] and [containsKey] together
- * with a custom equality and hashcode, an extra `isValidKey` function
- * can be supplied. This function is called before calling [equals] or
- * [hashCode] with an argument that may not be a [K] instance, and if the
- * call returns false, the key is assumed to not be in the set.
- * The [isValidKey] function defaults to just testing if the object is a
- * [K] instance.
- *
- * Example:
- *
- * new HashMap<int,int>(equals: (int a, int b) => (b - a) % 5 == 0,
- * hashCode: (int e) => e % 5)
- *
- * This example map does not need an `isValidKey` function to be passed.
- * The default function accepts only `int` values, which can safely be
- * passed to both the `equals` and `hashCode` functions.
- *
- * If neither `equals`, `hashCode`, nor `isValidKey` is provided,
- * the default `isValidKey` instead accepts all keys.
- * The default equality and hashcode operations are assumed to work on all
- * objects.
- *
- * Likewise, if `equals` is [identical], `hashCode` is [identityHashCode]
- * and `isValidKey` is omitted, the resulting map is identity based,
- * and the `isValidKey` defaults to accepting all keys.
- * Such a map can be created directly using [HashMap.identity].
- *
- * The used `equals` and `hashCode` method should always be consistent,
- * so that if `equals(a, b)` then `hashCode(a) == hashCode(b)`. The hash
- * of an object, or what it compares equal to, should not change while the
- * object is a key in the map. If it does change, the result is unpredictable.
- *
- * If you supply one of [equals] and [hashCode],
- * you should generally also to supply the other.
- */
+ /// Creates an unordered hash-table based [Map].
+ ///
+ /// The created map is not ordered in any way. When iterating the keys or
+ /// values, the iteration order is unspecified except that it will stay the
+ /// same as long as the map isn't changed.
+ ///
+ /// If [equals] is provided, it is used to compare the keys in the table with
+ /// new keys. If [equals] is omitted, the key's own [Object.==] is used
+ /// instead.
+ ///
+ /// Similar, if [hashCode] is provided, it is used to produce a hash value
+ /// for keys in order to place them in the hash table. If it is omitted, the
+ /// key's own [Object.hashCode] is used.
+ ///
+ /// If using methods like [operator []], [remove] and [containsKey] together
+ /// with a custom equality and hashcode, an extra `isValidKey` function
+ /// can be supplied. This function is called before calling [equals] or
+ /// [hashCode] with an argument that may not be a [K] instance, and if the
+ /// call returns false, the key is assumed to not be in the set.
+ /// The [isValidKey] function defaults to just testing if the object is a
+ /// [K] instance.
+ ///
+ /// Example:
+ ///
+ /// new HashMap<int,int>(equals: (int a, int b) => (b - a) % 5 == 0,
+ /// hashCode: (int e) => e % 5)
+ ///
+ /// This example map does not need an `isValidKey` function to be passed.
+ /// The default function accepts only `int` values, which can safely be
+ /// passed to both the `equals` and `hashCode` functions.
+ ///
+ /// If neither `equals`, `hashCode`, nor `isValidKey` is provided,
+ /// the default `isValidKey` instead accepts all keys.
+ /// The default equality and hashcode operations are assumed to work on all
+ /// objects.
+ ///
+ /// Likewise, if `equals` is [identical], `hashCode` is [identityHashCode]
+ /// and `isValidKey` is omitted, the resulting map is identity based,
+ /// and the `isValidKey` defaults to accepting all keys.
+ /// Such a map can be created directly using [HashMap.identity].
+ ///
+ /// The used `equals` and `hashCode` method should always be consistent,
+ /// so that if `equals(a, b)` then `hashCode(a) == hashCode(b)`. The hash
+ /// of an object, or what it compares equal to, should not change while the
+ /// object is a key in the map. If it does change, the result is
+ /// unpredictable.
+ ///
+ /// If you supply one of [equals] and [hashCode],
+ /// you should generally also to supply the other.
external factory HashMap(
{bool equals(K key1, K key2),
int hashCode(K key),
bool isValidKey(potentialKey)});
- /**
- * Creates an unordered identity-based map.
- *
- * Effectively a shorthand for:
- *
- * new HashMap<K, V>(equals: identical,
- * hashCode: identityHashCode)
- */
+ /// Creates an unordered identity-based map.
+ ///
+ /// Effectively a shorthand for:
+ ///
+ /// new HashMap<K, V>(equals: identical,
+ /// hashCode: identityHashCode)
external factory HashMap.identity();
- /**
- * Creates a [HashMap] that contains all key/value pairs of [other].
- *
- * The keys must all be instances of [K] and the values of [V].
- * The [other] map itself can have any type.
- */
+ /// Creates a [HashMap] that contains all key/value pairs of [other].
+ ///
+ /// The keys must all be instances of [K] and the values of [V].
+ /// The [other] map itself can have any type.
factory HashMap.from(Map other) {
- Map<K, V> result = new HashMap<K, V>();
+ Map<K, V> result = HashMap<K, V>();
other.forEach((k, v) {
result[k] = v;
});
return result;
}
- /**
- * Creates a [HashMap] that contains all key/value pairs of [other].
- */
- factory HashMap.of(Map<K, V> other) => new HashMap<K, V>()..addAll(other);
+ /// Creates a [HashMap] that contains all key/value pairs of [other].
+ factory HashMap.of(Map<K, V> other) => HashMap<K, V>()..addAll(other);
- /**
- * Creates a [HashMap] where the keys and values are computed from the
- * [iterable].
- *
- * For each element of the [iterable] this constructor computes a key/value
- * pair, by applying [key] and [value] respectively.
- *
- * The keys of the key/value pairs do not need to be unique. The last
- * occurrence of a key will simply overwrite any previous value.
- *
- * If no values are specified for [key] and [value] the default is the
- * identity function.
- */
+ /// Creates a [HashMap] where the keys and values are computed from the
+ /// [iterable].
+ ///
+ /// For each element of the [iterable] this constructor computes a key/value
+ /// pair, by applying [key] and [value] respectively.
+ ///
+ /// The keys of the key/value pairs do not need to be unique. The last
+ /// occurrence of a key will simply overwrite any previous value.
+ ///
+ /// If no values are specified for [key] and [value] the default is the
+ /// identity function.
factory HashMap.fromIterable(Iterable iterable,
{K key(element), V value(element)}) {
- Map<K, V> map = new HashMap<K, V>();
+ Map<K, V> map = HashMap<K, V>();
MapBase._fillMapWithMappedIterable(map, iterable, key, value);
return map;
}
- /**
- * Creates a [HashMap] associating the given [keys] to [values].
- *
- * This constructor iterates over [keys] and [values] and maps each element of
- * [keys] to the corresponding element of [values].
- *
- * If [keys] contains the same object multiple times, the last occurrence
- * overwrites the previous value.
- *
- * It is an error if the two [Iterable]s don't have the same length.
- */
+ /// Creates a [HashMap] associating the given [keys] to [values].
+ ///
+ /// This constructor iterates over [keys] and [values] and maps each element
+ /// of [keys] to the corresponding element of [values].
+ ///
+ /// If [keys] contains the same object multiple times, the last occurrence
+ /// overwrites the previous value.
+ ///
+ /// It is an error if the two [Iterable]s don't have the same length.
factory HashMap.fromIterables(Iterable<K> keys, Iterable<V> values) {
- Map<K, V> map = new HashMap<K, V>();
+ Map<K, V> map = HashMap<K, V>();
MapBase._fillMapWithIterables(map, keys, values);
return map;
}
- /**
- * Creates a [HashMap] containing the entries of [entries].
- *
- * Returns a new `HashMap<K, V>` where all entries of [entries]
- * have been added in iteration order.
- *
- * If multiple [entries] have the same key,
- * later occurrences overwrite the earlier ones.
- */
+ /// Creates a [HashMap] containing the entries of [entries].
+ ///
+ /// Returns a new `HashMap<K, V>` where all entries of [entries]
+ /// have been added in iteration order.
+ ///
+ /// If multiple [entries] have the same key,
+ /// later occurrences overwrite the earlier ones.
@Since("2.1")
factory HashMap.fromEntries(Iterable<MapEntry<K, V>> entries) =>
HashMap<K, V>()..addEntries(entries);
diff --git a/sdk/lib/collection/hash_set.dart b/sdk/lib/collection/hash_set.dart
index d93e550..3fd00fe 100644
--- a/sdk/lib/collection/hash_set.dart
+++ b/sdk/lib/collection/hash_set.dart
@@ -4,125 +4,112 @@
part of dart.collection;
-/**
- * An unordered hash-table based [Set] implementation.
- *
- * The elements of a `HashSet` must have consistent equality
- * and hashCode implementations. This means that the equals operation
- * must define a stable equivalence relation on the elements (reflexive,
- * symmetric, transitive, and consistent over time), and that the hashCode
- * must consistent with equality, so that the same for objects that are
- * considered equal.
- *
- * The set allows `null` as an element.
- *
- * Most simple operations on `HashSet` are done in (potentially amortized)
- * constant time: [add], [contains], [remove], and [length], provided the hash
- * codes of objects are well distributed.
- *
- * The iteration order of the set is not specified and depends on
- * the hashcodes of the provided elements. However, the order is stable:
- * multiple iterations over the same set produce the same order, as long as
- * the set is not modified.
- */
+/// An unordered hash-table based [Set] implementation.
+///
+/// The elements of a `HashSet` must have consistent equality
+/// and hashCode implementations. This means that the equals operation
+/// must define a stable equivalence relation on the elements (reflexive,
+/// symmetric, transitive, and consistent over time), and that the hashCode
+/// must consistent with equality, so that the same for objects that are
+/// considered equal.
+///
+/// The set allows `null` as an element.
+///
+/// Most simple operations on `HashSet` are done in (potentially amortized)
+/// constant time: [add], [contains], [remove], and [length], provided the hash
+/// codes of objects are well distributed.
+///
+/// The iteration order of the set is not specified and depends on
+/// the hashcodes of the provided elements. However, the order is stable:
+/// multiple iterations over the same set produce the same order, as long as
+/// the set is not modified.
abstract class HashSet<E> implements Set<E> {
- /**
- * Create a hash set using the provided [equals] as equality.
- *
- * The provided [equals] must define a stable equivalence relation, and
- * [hashCode] must be consistent with [equals]. If the [equals] or [hashCode]
- * methods won't work on all objects, but only on some instances of E, the
- * [isValidKey] predicate can be used to restrict the keys that the functions
- * are applied to.
- * Any key for which [isValidKey] returns false is automatically assumed
- * to not be in the set when asking `contains`.
- *
- * If [equals] or [hashCode] are omitted, the set uses
- * the elements' intrinsic [Object.==] and [Object.hashCode].
- *
- * If you supply one of [equals] and [hashCode],
- * you should generally also to supply the other.
- *
- * If the supplied `equals` or `hashCode` functions won't work on all [E]
- * objects, and the map will be used in a setting where a non-`E` object
- * is passed to, e.g., `contains`, then the [isValidKey] function should
- * also be supplied.
- *
- * If [isValidKey] is omitted, it defaults to testing if the object is an
- * [E] instance. That means that:
- *
- * new HashSet<int>(equals: (int e1, int e2) => (e1 - e2) % 5 == 0,
- * hashCode: (int e) => e % 5)
- *
- * does not need an `isValidKey` argument, because it defaults to only
- * accepting `int` values which are accepted by both `equals` and `hashCode`.
- *
- * If neither `equals`, `hashCode`, nor `isValidKey` is provided,
- * the default `isValidKey` instead accepts all values.
- * The default equality and hashcode operations are assumed to work on all
- * objects.
- *
- * Likewise, if `equals` is [identical], `hashCode` is [identityHashCode]
- * and `isValidKey` is omitted, the resulting set is identity based,
- * and the `isValidKey` defaults to accepting all keys.
- * Such a map can be created directly using [HashSet.identity].
- */
+ /// Create a hash set using the provided [equals] as equality.
+ ///
+ /// The provided [equals] must define a stable equivalence relation, and
+ /// [hashCode] must be consistent with [equals]. If the [equals] or [hashCode]
+ /// methods won't work on all objects, but only on some instances of E, the
+ /// [isValidKey] predicate can be used to restrict the keys that the functions
+ /// are applied to.
+ /// Any key for which [isValidKey] returns false is automatically assumed
+ /// to not be in the set when asking `contains`.
+ ///
+ /// If [equals] or [hashCode] are omitted, the set uses
+ /// the elements' intrinsic [Object.==] and [Object.hashCode].
+ ///
+ /// If you supply one of [equals] and [hashCode],
+ /// you should generally also to supply the other.
+ ///
+ /// If the supplied `equals` or `hashCode` functions won't work on all [E]
+ /// objects, and the map will be used in a setting where a non-`E` object
+ /// is passed to, e.g., `contains`, then the [isValidKey] function should
+ /// also be supplied.
+ ///
+ /// If [isValidKey] is omitted, it defaults to testing if the object is an
+ /// [E] instance. That means that:
+ ///
+ /// new HashSet<int>(equals: (int e1, int e2) => (e1 - e2) % 5 == 0,
+ /// hashCode: (int e) => e % 5)
+ ///
+ /// does not need an `isValidKey` argument, because it defaults to only
+ /// accepting `int` values which are accepted by both `equals` and `hashCode`.
+ ///
+ /// If neither `equals`, `hashCode`, nor `isValidKey` is provided,
+ /// the default `isValidKey` instead accepts all values.
+ /// The default equality and hashcode operations are assumed to work on all
+ /// objects.
+ ///
+ /// Likewise, if `equals` is [identical], `hashCode` is [identityHashCode]
+ /// and `isValidKey` is omitted, the resulting set is identity based,
+ /// and the `isValidKey` defaults to accepting all keys.
+ /// Such a map can be created directly using [HashSet.identity].
external factory HashSet(
{bool equals(E e1, E e2),
int hashCode(E e),
bool isValidKey(potentialKey)});
- /**
- * Creates an unordered identity-based set.
- *
- * Effectively a shorthand for:
- *
- * new HashSet<E>(equals: identical,
- * hashCode: identityHashCode)
- */
+ /// Creates an unordered identity-based set.
+ ///
+ /// Effectively a shorthand for:
+ ///
+ /// new HashSet<E>(equals: identical,
+ /// hashCode: identityHashCode)
external factory HashSet.identity();
- /**
- * Create a hash set containing all [elements].
- *
- * Creates a hash set as by `new HashSet<E>()` and adds all given [elements]
- * to the set. The elements are added in order. If [elements] contains
- * two entries that are equal, but not identical, then the first one is
- * the one in the resulting set.
- *
- * All the [elements] should be instances of [E].
- * The `elements` iterable itself may have any element type, so this
- * constructor can be used to down-cast a `Set`, for example as:
- * ```dart
- * Set<SuperType> superSet = ...;
- * Set<SubType> subSet =
- * new HashSet<SubType>.from(superSet.whereType<SubType>());
- * ```
- */
+ /// Create a hash set containing all [elements].
+ ///
+ /// Creates a hash set as by `new HashSet<E>()` and adds all given [elements]
+ /// to the set. The elements are added in order. If [elements] contains
+ /// two entries that are equal, but not identical, then the first one is
+ /// the one in the resulting set.
+ ///
+ /// All the [elements] should be instances of [E].
+ /// The `elements` iterable itself may have any element type, so this
+ /// constructor can be used to down-cast a `Set`, for example as:
+ /// ```dart
+ /// Set<SuperType> superSet = ...;
+ /// Set<SubType> subSet =
+ /// new HashSet<SubType>.from(superSet.whereType<SubType>());
+ /// ```
factory HashSet.from(Iterable elements) {
- HashSet<E> result = new HashSet<E>();
+ HashSet<E> result = HashSet<E>();
for (final e in elements) {
result.add(e);
}
return result;
}
- /**
- * Create a hash set containing all [elements].
- *
- * Creates a hash set as by `new HashSet<E>()` and adds all given [elements]
- * to the set. The elements are added in order. If [elements] contains
- * two entries that are equal, but not identical, then the first one is
- * the one in the resulting set.
- */
- factory HashSet.of(Iterable<E> elements) =>
- new HashSet<E>()..addAll(elements);
+ /// Create a hash set containing all [elements].
+ ///
+ /// Creates a hash set as by `new HashSet<E>()` and adds all given [elements]
+ /// to the set. The elements are added in order. If [elements] contains
+ /// two entries that are equal, but not identical, then the first one is
+ /// the one in the resulting set.
+ factory HashSet.of(Iterable<E> elements) => HashSet<E>()..addAll(elements);
- /**
- * Provides an iterator that iterates over the elements of this set.
- *
- * The order of iteration is unspecified,
- * but consistent between changes to the set.
- */
+ /// Provides an iterator that iterates over the elements of this set.
+ ///
+ /// The order of iteration is unspecified,
+ /// but consistent between changes to the set.
Iterator<E> get iterator;
}
diff --git a/sdk/lib/collection/iterable.dart b/sdk/lib/collection/iterable.dart
index b7b5497..14e7226 100644
--- a/sdk/lib/collection/iterable.dart
+++ b/sdk/lib/collection/iterable.dart
@@ -4,11 +4,9 @@
part of dart.collection;
-/**
- * This [Iterable] mixin implements all [Iterable] members except `iterator`.
- *
- * All other methods are implemented in terms of `iterator`.
- */
+/// This [Iterable] mixin implements all [Iterable] members except `iterator`.
+///
+/// All other methods are implemented in terms of `iterator`.
abstract class IterableMixin<E> implements Iterable<E> {
// This class has methods copied verbatim into:
// - IterableBase
@@ -16,23 +14,23 @@
// If changing a method here, also change the other copies.
Iterable<R> cast<R>() => Iterable.castFrom<E, R>(this);
- Iterable<T> map<T>(T f(E element)) => new MappedIterable<E, T>(this, f);
+ Iterable<T> map<T>(T f(E element)) => MappedIterable<E, T>(this, f);
- Iterable<E> where(bool f(E element)) => new WhereIterable<E>(this, f);
+ Iterable<E> where(bool f(E element)) => WhereIterable<E>(this, f);
- Iterable<T> whereType<T>() => new WhereTypeIterable<T>(this);
+ Iterable<T> whereType<T>() => WhereTypeIterable<T>(this);
Iterable<T> expand<T>(Iterable<T> f(E element)) =>
- new ExpandIterable<E, T>(this, f);
+ ExpandIterable<E, T>(this, f);
Iterable<E> followedBy(Iterable<E> other) {
// Type workaround because IterableMixin<E> doesn't promote
// to EfficientLengthIterable<E>.
Iterable<E> self = this;
if (self is EfficientLengthIterable<E>) {
- return new FollowedByIterable<E>.firstEfficient(self, other);
+ return FollowedByIterable<E>.firstEfficient(self, other);
}
- return new FollowedByIterable<E>(this, other);
+ return FollowedByIterable<E>(this, other);
}
bool contains(Object element) {
@@ -74,7 +72,7 @@
String join([String separator = ""]) {
Iterator<E> iterator = this.iterator;
if (!iterator.moveNext()) return "";
- StringBuffer buffer = new StringBuffer();
+ StringBuffer buffer = StringBuffer();
if (separator == null || separator == "") {
do {
buffer.write("${iterator.current}");
@@ -96,10 +94,10 @@
return false;
}
- List<E> toList({bool growable: true}) =>
- new List<E>.from(this, growable: growable);
+ List<E> toList({bool growable = true}) =>
+ List<E>.from(this, growable: growable);
- Set<E> toSet() => new Set<E>.from(this);
+ Set<E> toSet() => Set<E>.from(this);
int get length {
assert(this is! EfficientLengthIterable);
@@ -116,19 +114,19 @@
bool get isNotEmpty => !isEmpty;
Iterable<E> take(int count) {
- return new TakeIterable<E>(this, count);
+ return TakeIterable<E>(this, count);
}
Iterable<E> takeWhile(bool test(E value)) {
- return new TakeWhileIterable<E>(this, test);
+ return TakeWhileIterable<E>(this, test);
}
Iterable<E> skip(int count) {
- return new SkipIterable<E>(this, count);
+ return SkipIterable<E>(this, count);
}
Iterable<E> skipWhile(bool test(E value)) {
- return new SkipWhileIterable<E>(this, test);
+ return SkipWhileIterable<E>(this, test);
}
E get first {
@@ -206,29 +204,25 @@
if (index == elementIndex) return element;
elementIndex++;
}
- throw new RangeError.index(index, this, "index", null, elementIndex);
+ throw RangeError.index(index, this, "index", null, elementIndex);
}
String toString() => IterableBase.iterableToShortString(this, '(', ')');
}
-/**
- * Base class for implementing [Iterable].
- *
- * This class implements all methods of [Iterable], except [Iterable.iterator],
- * in terms of `iterator`.
- */
+/// Base class for implementing [Iterable].
+///
+/// This class implements all methods of [Iterable], except [Iterable.iterator],
+/// in terms of `iterator`.
abstract class IterableBase<E> extends Iterable<E> {
const IterableBase();
- /**
- * Convert an `Iterable` to a string like [IterableBase.toString].
- *
- * Allows using other delimiters than '(' and ')'.
- *
- * Handles circular references where converting one of the elements
- * to a string ends up converting [iterable] to a string again.
- */
+ /// Convert an `Iterable` to a string like [IterableBase.toString].
+ ///
+ /// Allows using other delimiters than '(' and ')'.
+ ///
+ /// Handles circular references where converting one of the elements
+ /// to a string ends up converting [iterable] to a string again.
static String iterableToShortString(Iterable iterable,
[String leftDelimiter = '(', String rightDelimiter = ')']) {
if (_isToStringVisiting(iterable)) {
@@ -246,30 +240,28 @@
assert(identical(_toStringVisiting.last, iterable));
_toStringVisiting.removeLast();
}
- return (new StringBuffer(leftDelimiter)
+ return (StringBuffer(leftDelimiter)
..writeAll(parts, ", ")
..write(rightDelimiter))
.toString();
}
- /**
- * Converts an `Iterable` to a string.
- *
- * Converts each elements to a string, and separates the results by ", ".
- * Then wraps the result in [leftDelimiter] and [rightDelimiter].
- *
- * Unlike [iterableToShortString], this conversion doesn't omit any
- * elements or puts any limit on the size of the result.
- *
- * Handles circular references where converting one of the elements
- * to a string ends up converting [iterable] to a string again.
- */
+ /// Converts an `Iterable` to a string.
+ ///
+ /// Converts each elements to a string, and separates the results by ", ".
+ /// Then wraps the result in [leftDelimiter] and [rightDelimiter].
+ ///
+ /// Unlike [iterableToShortString], this conversion doesn't omit any
+ /// elements or puts any limit on the size of the result.
+ ///
+ /// Handles circular references where converting one of the elements
+ /// to a string ends up converting [iterable] to a string again.
static String iterableToFullString(Iterable iterable,
[String leftDelimiter = '(', String rightDelimiter = ')']) {
if (_isToStringVisiting(iterable)) {
return "$leftDelimiter...$rightDelimiter";
}
- StringBuffer buffer = new StringBuffer(leftDelimiter);
+ StringBuffer buffer = StringBuffer(leftDelimiter);
_toStringVisiting.add(iterable);
try {
buffer.writeAll(iterable, ", ");
@@ -282,10 +274,10 @@
}
}
-/** A collection used to identify cyclic lists during toString() calls. */
+/// A collection used to identify cyclic lists during toString() calls.
final List _toStringVisiting = [];
-/** Check if we are currently visiting `o` in a toString call. */
+/// Check if we are currently visiting `o` in a toString call.
bool _isToStringVisiting(Object o) {
for (int i = 0; i < _toStringVisiting.length; i++) {
if (identical(o, _toStringVisiting[i])) return true;
@@ -293,9 +285,7 @@
return false;
}
-/**
- * Convert elements of [iterable] to strings and store them in [parts].
- */
+/// Convert elements of [iterable] to strings and store them in [parts].
void _iterablePartsToStrings(Iterable iterable, List<String> parts) {
/*
* This is the complicated part of [iterableToShortString].
diff --git a/sdk/lib/collection/iterator.dart b/sdk/lib/collection/iterator.dart
index f870711..671f0ee 100644
--- a/sdk/lib/collection/iterator.dart
+++ b/sdk/lib/collection/iterator.dart
@@ -4,12 +4,10 @@
part of dart.collection;
-/**
- * The [HasNextIterator] class wraps an [Iterator] and provides methods to
- * iterate over an object using `hasNext` and `next`.
- *
- * An [HasNextIterator] does not implement the [Iterator] interface.
- */
+/// The [HasNextIterator] class wraps an [Iterator] and provides methods to
+/// iterate over an object using `hasNext` and `next`.
+///
+/// An [HasNextIterator] does not implement the [Iterator] interface.
class HasNextIterator<E> {
static const int _HAS_NEXT_AND_NEXT_IN_CURRENT = 0;
static const int _NO_NEXT = 1;
@@ -28,7 +26,7 @@
E next() {
// Call to hasNext is necessary to make sure we are positioned at the first
// element when we start iterating.
- if (!hasNext) throw new StateError("No more elements");
+ if (!hasNext) throw StateError("No more elements");
assert(_state == _HAS_NEXT_AND_NEXT_IN_CURRENT);
E result = _iterator.current;
_move();
diff --git a/sdk/lib/collection/linked_hash_map.dart b/sdk/lib/collection/linked_hash_map.dart
index 91f95ad..e3a650d 100644
--- a/sdk/lib/collection/linked_hash_map.dart
+++ b/sdk/lib/collection/linked_hash_map.dart
@@ -4,153 +4,137 @@
part of dart.collection;
-/**
- * A hash-table based implementation of [Map].
- *
- * The insertion order of keys is remembered,
- * and keys are iterated in the order they were inserted into the map.
- * Values are iterated in their corresponding key's order.
- * Changing a key's value, when the key is already in the map,
- * does not change the iteration order,
- * but removing the key and adding it again
- * will make it be last in the iteration order.
- *
- * The keys of a `LinkedHashMap` must have consistent [Object.==]
- * and [Object.hashCode] implementations. This means that the `==` operator
- * must define a stable equivalence relation on the keys (reflexive,
- * symmetric, transitive, and consistent over time), and that `hashCode`
- * must be the same for objects that are considered equal by `==`.
- *
- * The map allows `null` as a key.
- */
+/// A hash-table based implementation of [Map].
+///
+/// The insertion order of keys is remembered,
+/// and keys are iterated in the order they were inserted into the map.
+/// Values are iterated in their corresponding key's order.
+/// Changing a key's value, when the key is already in the map,
+/// does not change the iteration order,
+/// but removing the key and adding it again
+/// will make it be last in the iteration order.
+///
+/// The keys of a `LinkedHashMap` must have consistent [Object.==]
+/// and [Object.hashCode] implementations. This means that the `==` operator
+/// must define a stable equivalence relation on the keys (reflexive,
+/// symmetric, transitive, and consistent over time), and that `hashCode`
+/// must be the same for objects that are considered equal by `==`.
+///
+/// The map allows `null` as a key.
abstract class LinkedHashMap<K, V> implements Map<K, V> {
- /**
- * Creates an insertion-ordered hash-table based [Map].
- *
- * If [equals] is provided, it is used to compare the keys in the table with
- * new keys. If [equals] is omitted, the key's own [Object.==] is used
- * instead.
- *
- * Similar, if [hashCode] is provided, it is used to produce a hash value
- * for keys in order to place them in the hash table. If it is omitted, the
- * key's own [Object.hashCode] is used.
- *
- * If using methods like [operator []], [remove] and [containsKey] together
- * with a custom equality and hashcode, an extra `isValidKey` function
- * can be supplied. This function is called before calling [equals] or
- * [hashCode] with an argument that may not be a [K] instance, and if the
- * call returns false, the key is assumed to not be in the set.
- * The [isValidKey] function defaults to just testing if the object is a
- * [K] instance.
- *
- * Example:
- *
- * new LinkedHashMap<int,int>(equals: (int a, int b) => (b - a) % 5 == 0,
- * hashCode: (int e) => e % 5)
- *
- * This example map does not need an `isValidKey` function to be passed.
- * The default function accepts only `int` values, which can safely be
- * passed to both the `equals` and `hashCode` functions.
- *
- * If neither `equals`, `hashCode`, nor `isValidKey` is provided,
- * the default `isValidKey` instead accepts all keys.
- * The default equality and hashcode operations are assumed to work on all
- * objects.
- *
- * Likewise, if `equals` is [identical], `hashCode` is [identityHashCode]
- * and `isValidKey` is omitted, the resulting map is identity based,
- * and the `isValidKey` defaults to accepting all keys.
- * Such a map can be created directly using [LinkedHashMap.identity].
- *
- * The used `equals` and `hashCode` method should always be consistent,
- * so that if `equals(a, b)` then `hashCode(a) == hashCode(b)`. The hash
- * of an object, or what it compares equal to, should not change while the
- * object is in the table. If it does change, the result is unpredictable.
- *
- * If you supply one of [equals] and [hashCode],
- * you should generally also to supply the other.
- */
+ /// Creates an insertion-ordered hash-table based [Map].
+ ///
+ /// If [equals] is provided, it is used to compare the keys in the table with
+ /// new keys. If [equals] is omitted, the key's own [Object.==] is used
+ /// instead.
+ ///
+ /// Similar, if [hashCode] is provided, it is used to produce a hash value
+ /// for keys in order to place them in the hash table. If it is omitted, the
+ /// key's own [Object.hashCode] is used.
+ ///
+ /// If using methods like [operator []], [remove] and [containsKey] together
+ /// with a custom equality and hashcode, an extra `isValidKey` function
+ /// can be supplied. This function is called before calling [equals] or
+ /// [hashCode] with an argument that may not be a [K] instance, and if the
+ /// call returns false, the key is assumed to not be in the set.
+ /// The [isValidKey] function defaults to just testing if the object is a
+ /// [K] instance.
+ ///
+ /// Example:
+ ///
+ /// new LinkedHashMap<int,int>(equals: (int a, int b) => (b - a) % 5 == 0,
+ /// hashCode: (int e) => e % 5)
+ ///
+ /// This example map does not need an `isValidKey` function to be passed.
+ /// The default function accepts only `int` values, which can safely be
+ /// passed to both the `equals` and `hashCode` functions.
+ ///
+ /// If neither `equals`, `hashCode`, nor `isValidKey` is provided,
+ /// the default `isValidKey` instead accepts all keys.
+ /// The default equality and hashcode operations are assumed to work on all
+ /// objects.
+ ///
+ /// Likewise, if `equals` is [identical], `hashCode` is [identityHashCode]
+ /// and `isValidKey` is omitted, the resulting map is identity based,
+ /// and the `isValidKey` defaults to accepting all keys.
+ /// Such a map can be created directly using [LinkedHashMap.identity].
+ ///
+ /// The used `equals` and `hashCode` method should always be consistent,
+ /// so that if `equals(a, b)` then `hashCode(a) == hashCode(b)`. The hash
+ /// of an object, or what it compares equal to, should not change while the
+ /// object is in the table. If it does change, the result is unpredictable.
+ ///
+ /// If you supply one of [equals] and [hashCode],
+ /// you should generally also to supply the other.
external factory LinkedHashMap(
{bool equals(K key1, K key2),
int hashCode(K key),
bool isValidKey(potentialKey)});
- /**
- * Creates an insertion-ordered identity-based map.
- *
- * Effectively a shorthand for:
- *
- * new LinkedHashMap<K, V>(equals: identical,
- * hashCode: identityHashCode)
- */
+ /// Creates an insertion-ordered identity-based map.
+ ///
+ /// Effectively a shorthand for:
+ ///
+ /// new LinkedHashMap<K, V>(equals: identical,
+ /// hashCode: identityHashCode)
external factory LinkedHashMap.identity();
- /**
- * Creates a [LinkedHashMap] that contains all key value pairs of [other].
- *
- * The keys must all be instances of [K] and the values to [V].
- * The [other] map itself can have any type.
- */
+ /// Creates a [LinkedHashMap] that contains all key value pairs of [other].
+ ///
+ /// The keys must all be instances of [K] and the values to [V].
+ /// The [other] map itself can have any type.
factory LinkedHashMap.from(Map other) {
- LinkedHashMap<K, V> result = new LinkedHashMap<K, V>();
+ LinkedHashMap<K, V> result = LinkedHashMap<K, V>();
other.forEach((k, v) {
result[k] = v;
});
return result;
}
- /**
- * Creates a [LinkedHashMap] that contains all key value pairs of [other].
- */
+ /// Creates a [LinkedHashMap] that contains all key value pairs of [other].
factory LinkedHashMap.of(Map<K, V> other) =>
- new LinkedHashMap<K, V>()..addAll(other);
+ LinkedHashMap<K, V>()..addAll(other);
- /**
- * Creates a [LinkedHashMap] where the keys and values are computed from the
- * [iterable].
- *
- * For each element of the [iterable] this constructor computes a key/value
- * pair, by applying [key] and [value] respectively.
- *
- * The keys of the key/value pairs do not need to be unique. The last
- * occurrence of a key will simply overwrite any previous value.
- *
- * If no values are specified for [key] and [value] the default is the
- * identity function.
- */
+ /// Creates a [LinkedHashMap] where the keys and values are computed from the
+ /// [iterable].
+ ///
+ /// For each element of the [iterable] this constructor computes a key/value
+ /// pair, by applying [key] and [value] respectively.
+ ///
+ /// The keys of the key/value pairs do not need to be unique. The last
+ /// occurrence of a key will simply overwrite any previous value.
+ ///
+ /// If no values are specified for [key] and [value] the default is the
+ /// identity function.
factory LinkedHashMap.fromIterable(Iterable iterable,
{K key(element), V value(element)}) {
- LinkedHashMap<K, V> map = new LinkedHashMap<K, V>();
+ LinkedHashMap<K, V> map = LinkedHashMap<K, V>();
MapBase._fillMapWithMappedIterable(map, iterable, key, value);
return map;
}
- /**
- * Creates a [LinkedHashMap] associating the given [keys] to [values].
- *
- * This constructor iterates over [keys] and [values] and maps each element of
- * [keys] to the corresponding element of [values].
- *
- * If [keys] contains the same object multiple times, the last occurrence
- * overwrites the previous value.
- *
- * It is an error if the two [Iterable]s don't have the same length.
- */
+ /// Creates a [LinkedHashMap] associating the given [keys] to [values].
+ ///
+ /// This constructor iterates over [keys] and [values] and maps each element of
+ /// [keys] to the corresponding element of [values].
+ ///
+ /// If [keys] contains the same object multiple times, the last occurrence
+ /// overwrites the previous value.
+ ///
+ /// It is an error if the two [Iterable]s don't have the same length.
factory LinkedHashMap.fromIterables(Iterable<K> keys, Iterable<V> values) {
- LinkedHashMap<K, V> map = new LinkedHashMap<K, V>();
+ LinkedHashMap<K, V> map = LinkedHashMap<K, V>();
MapBase._fillMapWithIterables(map, keys, values);
return map;
}
- /**
- * Creates a [LinkedHashMap] containing the entries of [entries].
- *
- * Returns a new `LinkedHashMap<K, V>` where all entries of [entries]
- * have been added in iteration order.
- *
- * If multiple [entries] have the same key,
- * later occurrences overwrite the earlier ones.
- */
+ /// Creates a [LinkedHashMap] containing the entries of [entries].
+ ///
+ /// Returns a new `LinkedHashMap<K, V>` where all entries of [entries]
+ /// have been added in iteration order.
+ ///
+ /// If multiple [entries] have the same key,
+ /// later occurrences overwrite the earlier ones.
@Since("2.1")
factory LinkedHashMap.fromEntries(Iterable<MapEntry<K, V>> entries) =>
<K, V>{}..addEntries(entries);
diff --git a/sdk/lib/collection/linked_hash_set.dart b/sdk/lib/collection/linked_hash_set.dart
index 2fff2ec..a058b5e 100644
--- a/sdk/lib/collection/linked_hash_set.dart
+++ b/sdk/lib/collection/linked_hash_set.dart
@@ -4,131 +4,117 @@
part of dart.collection;
-/**
- * A [LinkedHashSet] is a hash-table based [Set] implementation.
- *
- * The `LinkedHashSet` also keep track of the order that elements were inserted
- * in, and iteration happens in first-to-last insertion order.
- *
- * The elements of a `LinkedHashSet` must have consistent [Object.==]
- * and [Object.hashCode] implementations. This means that the `==` operator
- * must define a stable equivalence relation on the elements (reflexive,
- * symmetric, transitive, and consistent over time), and that `hashCode`
- * must be the same for objects that are considered equal by `==`.
- *
- * The set allows `null` as an element.
- *
- * Iteration of elements is done in element insertion order.
- * An element that was added after another will occur later in the iteration.
- * Adding an element that is already in the set
- * does not change its position in the iteration order,
- * but removing an element and adding it again,
- * will make it the last element of an iteration.
- *
- * Most simple operations on `HashSet` are done in (potentially amortized)
- * constant time: [add], [contains], [remove], and [length], provided the hash
- * codes of objects are well distributed..
- */
+/// A [LinkedHashSet] is a hash-table based [Set] implementation.
+///
+/// The `LinkedHashSet` also keep track of the order that elements were inserted
+/// in, and iteration happens in first-to-last insertion order.
+///
+/// The elements of a `LinkedHashSet` must have consistent [Object.==]
+/// and [Object.hashCode] implementations. This means that the `==` operator
+/// must define a stable equivalence relation on the elements (reflexive,
+/// symmetric, transitive, and consistent over time), and that `hashCode`
+/// must be the same for objects that are considered equal by `==`.
+///
+/// The set allows `null` as an element.
+///
+/// Iteration of elements is done in element insertion order.
+/// An element that was added after another will occur later in the iteration.
+/// Adding an element that is already in the set
+/// does not change its position in the iteration order,
+/// but removing an element and adding it again,
+/// will make it the last element of an iteration.
+///
+/// Most simple operations on `HashSet` are done in (potentially amortized)
+/// constant time: [add], [contains], [remove], and [length], provided the hash
+/// codes of objects are well distributed..
abstract class LinkedHashSet<E> implements Set<E> {
- /**
- * Create an insertion-ordered hash set using the provided
- * [equals] and [hashCode].
- *
- * The provided [equals] must define a stable equivalence relation, and
- * [hashCode] must be consistent with [equals]. If the [equals] or [hashCode]
- * methods won't work on all objects, but only on some instances of E, the
- * [isValidKey] predicate can be used to restrict the keys that the functions
- * are applied to.
- * Any key for which [isValidKey] returns false is automatically assumed
- * to not be in the set when asking `contains`.
- *
- * If [equals] or [hashCode] are omitted, the set uses
- * the elements' intrinsic [Object.==] and [Object.hashCode],
- * and [isValidKey] is ignored since these operations are assumed
- * to work on all objects.
- *
- * If you supply one of [equals] and [hashCode],
- * you should generally also to supply the other.
- *
- * If the supplied `equals` or `hashCode` functions won't work on all [E]
- * objects, and the map will be used in a setting where a non-`E` object
- * is passed to, e.g., `contains`, then the [isValidKey] function should
- * also be supplied.
- *
- * If [isValidKey] is omitted, it defaults to testing if the object is an
- * [E] instance. That means that:
- *
- * new LinkedHashSet<int>(equals: (int e1, int e2) => (e1 - e2) % 5 == 0,
- * hashCode: (int e) => e % 5)
- *
- * does not need an `isValidKey` argument, because it defaults to only
- * accepting `int` values which are accepted by both `equals` and `hashCode`.
- *
- * If neither `equals`, `hashCode`, nor `isValidKey` is provided,
- * the default `isValidKey` instead accepts all values.
- * The default equality and hashcode operations are assumed to work on all
- * objects.
- *
- * Likewise, if `equals` is [identical], `hashCode` is [identityHashCode]
- * and `isValidKey` is omitted, the resulting set is identity based,
- * and the `isValidKey` defaults to accepting all keys.
- * Such a map can be created directly using [LinkedHashSet.identity].
- */
+ /// Create an insertion-ordered hash set using the provided
+ /// [equals] and [hashCode].
+ ///
+ /// The provided [equals] must define a stable equivalence relation, and
+ /// [hashCode] must be consistent with [equals]. If the [equals] or [hashCode]
+ /// methods won't work on all objects, but only on some instances of E, the
+ /// [isValidKey] predicate can be used to restrict the keys that the functions
+ /// are applied to.
+ /// Any key for which [isValidKey] returns false is automatically assumed
+ /// to not be in the set when asking `contains`.
+ ///
+ /// If [equals] or [hashCode] are omitted, the set uses
+ /// the elements' intrinsic [Object.==] and [Object.hashCode],
+ /// and [isValidKey] is ignored since these operations are assumed
+ /// to work on all objects.
+ ///
+ /// If you supply one of [equals] and [hashCode],
+ /// you should generally also to supply the other.
+ ///
+ /// If the supplied `equals` or `hashCode` functions won't work on all [E]
+ /// objects, and the map will be used in a setting where a non-`E` object
+ /// is passed to, e.g., `contains`, then the [isValidKey] function should
+ /// also be supplied.
+ ///
+ /// If [isValidKey] is omitted, it defaults to testing if the object is an
+ /// [E] instance. That means that:
+ ///
+ /// new LinkedHashSet<int>(equals: (int e1, int e2) => (e1 - e2) % 5 == 0,
+ /// hashCode: (int e) => e % 5)
+ ///
+ /// does not need an `isValidKey` argument, because it defaults to only
+ /// accepting `int` values which are accepted by both `equals` and `hashCode`.
+ ///
+ /// If neither `equals`, `hashCode`, nor `isValidKey` is provided,
+ /// the default `isValidKey` instead accepts all values.
+ /// The default equality and hashcode operations are assumed to work on all
+ /// objects.
+ ///
+ /// Likewise, if `equals` is [identical], `hashCode` is [identityHashCode]
+ /// and `isValidKey` is omitted, the resulting set is identity based,
+ /// and the `isValidKey` defaults to accepting all keys.
+ /// Such a map can be created directly using [LinkedHashSet.identity].
external factory LinkedHashSet(
{bool equals(E e1, E e2),
int hashCode(E e),
bool isValidKey(potentialKey)});
- /**
- * Creates an insertion-ordered identity-based set.
- *
- * Effectively a shorthand for:
- *
- * new LinkedHashSet<E>(equals: identical,
- * hashCode: identityHashCode)
- */
+ /// Creates an insertion-ordered identity-based set.
+ ///
+ /// Effectively a shorthand for:
+ ///
+ /// new LinkedHashSet<E>(equals: identical,
+ /// hashCode: identityHashCode)
external factory LinkedHashSet.identity();
- /**
- * Create a linked hash set containing all [elements].
- *
- * Creates a linked hash set as by `new LinkedHashSet<E>()` and adds each
- * element of `elements` to this set in the order they are iterated.
- *
- * All the [elements] should be instances of [E].
- * The `elements` iterable itself may have any element type,
- * so this constructor can be used to down-cast a `Set`, for example as:
- *
- * Set<SuperType> superSet = ...;
- * Iterable<SuperType> tmp = superSet.where((e) => e is SubType);
- * Set<SubType> subSet = new LinkedHashSet<SubType>.from(tmp);
- */
+ /// Create a linked hash set containing all [elements].
+ ///
+ /// Creates a linked hash set as by `new LinkedHashSet<E>()` and adds each
+ /// element of `elements` to this set in the order they are iterated.
+ ///
+ /// All the [elements] should be instances of [E].
+ /// The `elements` iterable itself may have any element type,
+ /// so this constructor can be used to down-cast a `Set`, for example as:
+ ///
+ /// Set<SuperType> superSet = ...;
+ /// Iterable<SuperType> tmp = superSet.where((e) => e is SubType);
+ /// Set<SubType> subSet = new LinkedHashSet<SubType>.from(tmp);
factory LinkedHashSet.from(Iterable elements) {
- LinkedHashSet<E> result = new LinkedHashSet<E>();
+ LinkedHashSet<E> result = LinkedHashSet<E>();
for (final element in elements) {
result.add(element);
}
return result;
}
- /**
- * Create a linked hash set from [elements].
- *
- * Creates a linked hash set as by `new LinkedHashSet<E>()` and adds each
- * element of `elements` to this set in the order they are iterated.
- */
+ /// Create a linked hash set from [elements].
+ ///
+ /// Creates a linked hash set as by `new LinkedHashSet<E>()` and adds each
+ /// element of `elements` to this set in the order they are iterated.
factory LinkedHashSet.of(Iterable<E> elements) =>
- new LinkedHashSet<E>()..addAll(elements);
+ LinkedHashSet<E>()..addAll(elements);
- /**
- * Executes a function on each element of the set.
- *
- * The elements are iterated in insertion order.
- */
+ /// Executes a function on each element of the set.
+ ///
+ /// The elements are iterated in insertion order.
void forEach(void action(E element));
- /**
- * Provides an iterator that iterates over the elements in insertion order.
- */
+ /// Provides an iterator that iterates over the elements in insertion order.
Iterator<E> get iterator;
}
diff --git a/sdk/lib/collection/linked_list.dart b/sdk/lib/collection/linked_list.dart
index 4ba329c..91461cb 100644
--- a/sdk/lib/collection/linked_list.dart
+++ b/sdk/lib/collection/linked_list.dart
@@ -4,82 +4,68 @@
part of dart.collection;
-/**
- * A specialized double-linked list of elements that extends [LinkedListEntry].
- *
- * This is not a generic data structure. It only accepts elements that extend
- * the [LinkedListEntry] class. See the [Queue] implementations for
- * generic collections that allow constant time adding and removing at the ends.
- *
- * This is not a [List] implementation. Despite its name, this class does not
- * implement the [List] interface. It does not allow constant time lookup by
- * index.
- *
- * Because the elements themselves contain the links of this linked list,
- * each element can be in only one list at a time. To add an element to another
- * list, it must first be removed from its current list (if any).
- *
- * In return, each element knows its own place in the linked list, as well as
- * which list it is in. This allows constant time [LinkedListEntry.insertAfter],
- * [LinkedListEntry.insertBefore] and [LinkedListEntry.unlink] operations
- * when all you have is the element.
- *
- * A `LinkedList` also allows constant time adding and removing at either end,
- * and a constant time length getter.
- */
+/// A specialized double-linked list of elements that extends [LinkedListEntry].
+///
+/// This is not a generic data structure. It only accepts elements that extend
+/// the [LinkedListEntry] class. See the [Queue] implementations for generic
+/// collections that allow constant time adding and removing at the ends.
+///
+/// This is not a [List] implementation. Despite its name, this class does not
+/// implement the [List] interface. It does not allow constant time lookup by
+/// index.
+///
+/// Because the elements themselves contain the links of this linked list,
+/// each element can be in only one list at a time. To add an element to another
+/// list, it must first be removed from its current list (if any).
+///
+/// In return, each element knows its own place in the linked list, as well as
+/// which list it is in. This allows constant time
+/// [LinkedListEntry.insertAfter], [LinkedListEntry.insertBefore] and
+/// [LinkedListEntry.unlink] operations when all you have is the element.
+///
+/// A `LinkedList` also allows constant time adding and removing at either end,
+/// and a constant time length getter.
class LinkedList<E extends LinkedListEntry<E>> extends Iterable<E> {
int _modificationCount = 0;
int _length = 0;
E _first;
- /**
- * Construct a new empty linked list.
- */
+ /// Construct a new empty linked list.
LinkedList();
- /**
- * Add [entry] to the beginning of the linked list.
- */
+ /// Add [entry] to the beginning of the linked list.
void addFirst(E entry) {
_insertBefore(_first, entry, updateFirst: true);
_first = entry;
}
- /**
- * Add [entry] to the end of the linked list.
- */
+ /// Add [entry] to the end of the linked list.
void add(E entry) {
_insertBefore(_first, entry, updateFirst: false);
}
- /**
- * Add [entries] to the end of the linked list.
- */
+ /// Add [entries] to the end of the linked list.
void addAll(Iterable<E> entries) {
entries.forEach(add);
}
- /**
- * Remove [entry] from the linked list.
- *
- * Returns false and does nothing if [entry] is not in this linked list.
- *
- * This is equivalent to calling `entry.unlink()` if the entry is in this
- * list.
- */
+ /// Remove [entry] from the linked list.
+ ///
+ /// Returns false and does nothing if [entry] is not in this linked list.
+ ///
+ /// This is equivalent to calling `entry.unlink()` if the entry is in this
+ /// list.
bool remove(E entry) {
if (entry._list != this) return false;
_unlink(entry); // Unlink will decrement length.
return true;
}
- Iterator<E> get iterator => new _LinkedListIterator<E>(this);
+ Iterator<E> get iterator => _LinkedListIterator<E>(this);
int get length => _length;
- /**
- * Remove all elements from this linked list.
- */
+ /// Remove all elements from this linked list.
void clear() {
_modificationCount++;
if (isEmpty) return;
@@ -97,33 +83,31 @@
E get first {
if (isEmpty) {
- throw new StateError('No such element');
+ throw StateError('No such element');
}
return _first;
}
E get last {
if (isEmpty) {
- throw new StateError('No such element');
+ throw StateError('No such element');
}
return _first._previous;
}
E get single {
if (isEmpty) {
- throw new StateError('No such element');
+ throw StateError('No such element');
}
if (_length > 1) {
- throw new StateError('Too many elements');
+ throw StateError('Too many elements');
}
return _first;
}
- /**
- * Call [action] with each entry in this linked list.
- *
- * It's an error if [action] modify the linked list.
- */
+ /// Call [action] with each entry in this linked list.
+ ///
+ /// It's an error if [action] modify the linked list.
void forEach(void action(E entry)) {
int modificationCount = _modificationCount;
if (isEmpty) return;
@@ -132,7 +116,7 @@
do {
action(current);
if (modificationCount != _modificationCount) {
- throw new ConcurrentModificationError(this);
+ throw ConcurrentModificationError(this);
}
current = current._next;
} while (!identical(current, _first));
@@ -146,7 +130,7 @@
/// updates the [_first] field to point to the [newEntry] as first entry.
void _insertBefore(E entry, E newEntry, {bool updateFirst}) {
if (newEntry.list != null) {
- throw new StateError('LinkedListEntry is already in a LinkedList');
+ throw StateError('LinkedListEntry is already in a LinkedList');
}
_modificationCount++;
@@ -201,7 +185,7 @@
bool moveNext() {
if (_modificationCount != _list._modificationCount) {
- throw new ConcurrentModificationError(this);
+ throw ConcurrentModificationError(this);
}
if (_list.isEmpty || (_visitedFirst && identical(_next, _list.first))) {
_current = null;
@@ -214,79 +198,65 @@
}
}
-/**
- * An object that can be an element in a [LinkedList].
- *
- * All elements of a `LinkedList` must extend this class.
- * The class provides the internal links that link elements together
- * in the `LinkedList`, and a reference to the linked list itself
- * that an element is currently part of.
- *
- * An entry can be in at most one linked list at a time.
- * While an entry is in a linked list, the [list] property points to that
- * linked list, and otherwise the `list` property is `null`.
- *
- * When created, an entry is not in any linked list.
- */
+/// An object that can be an element in a [LinkedList].
+///
+/// All elements of a `LinkedList` must extend this class.
+/// The class provides the internal links that link elements together
+/// in the `LinkedList`, and a reference to the linked list itself
+/// that an element is currently part of.
+///
+/// An entry can be in at most one linked list at a time.
+/// While an entry is in a linked list, the [list] property points to that
+/// linked list, and otherwise the `list` property is `null`.
+///
+/// When created, an entry is not in any linked list.
abstract class LinkedListEntry<E extends LinkedListEntry<E>> {
LinkedList<E> _list;
E _next;
E _previous;
- /**
- * Get the linked list containing this element.
- *
- * Returns `null` if this entry is not currently in any list.
- */
+ /// Get the linked list containing this element.
+ ///
+ /// Returns `null` if this entry is not currently in any list.
LinkedList<E> get list => _list;
- /**
- * Unlink the element from its linked list.
- *
- * The entry must currently be in a linked list when this method is called.
- */
+ /// Unlink the element from its linked list.
+ ///
+ /// The entry must currently be in a linked list when this method is called.
void unlink() {
_list._unlink(this);
}
- /**
- * Return the successor of this element in its linked list.
- *
- * Returns `null` if there is no successor in the linked list, or if this
- * entry is not currently in any list.
- */
+ /// Return the successor of this element in its linked list.
+ ///
+ /// Returns `null` if there is no successor in the linked list, or if this
+ /// entry is not currently in any list.
E get next {
if (_list == null || identical(_list.first, _next)) return null;
return _next;
}
- /**
- * Return the predecessor of this element in its linked list.
- *
- * Returns `null` if there is no predecessor in the linked list, or if this
- * entry is not currently in any list.
- */
+ /// Return the predecessor of this element in its linked list.
+ ///
+ /// Returns `null` if there is no predecessor in the linked list, or if this
+ /// entry is not currently in any list.
E get previous {
if (_list == null || identical(this, _list.first)) return null;
return _previous;
}
- /**
- * Insert an element after this element in this element's linked list.
- *
- * This entry must be in a linked list when this method is called.
- * The [entry] must not be in a linked list.
- */
+ /// Insert an element after this element in this element's linked list.
+ ///
+ /// This entry must be in a linked list when this method is called.
+ /// The [entry] must not be in a linked list.
void insertAfter(E entry) {
_list._insertBefore(_next, entry, updateFirst: false);
}
- /**
- * Insert an element before this element in this element's linked list.
- *
- * This entry must be in a linked list when this method is called.
- * The [entry] must not be in a linked list.
- */
+ /// Insert an element before this element in this element's linked list.
+ ///
+ /// This entry must be in a linked list when this method is called.
+ /// The [entry] must not be in a linked list.
void insertBefore(E entry) {
_list._insertBefore(this, entry, updateFirst: true);
}
diff --git a/sdk/lib/collection/list.dart b/sdk/lib/collection/list.dart
index 0c01350..77ce66a 100644
--- a/sdk/lib/collection/list.dart
+++ b/sdk/lib/collection/list.dart
@@ -4,70 +4,65 @@
part of dart.collection;
-/**
- * Abstract implementation of a list.
- *
- * `ListBase` can be used as a base class for implementing the `List` interface.
- *
- * All operations are defined in terms of `length`, `operator[]`,
- * `operator[]=` and `length=`, which need to be implemented.
- *
- * *NOTICE*: Forwarding just these four operations to a normal growable [List]
- * (as created by `new List()`) will give very bad performance for `add` and
- * `addAll` operations of `ListBase`. These operations are implemented by
- * increasing the length of the list by one for each `add` operation, and
- * repeatedly increasing the length of a growable list is not efficient.
- * To avoid this, either override 'add' and 'addAll' to also forward directly
- * to the growable list, or, preferably, use `DelegatingList` from
- * "package:collection/wrappers.dart" instead.
- */
+/// Abstract implementation of a list.
+///
+/// `ListBase` can be used as a base class for implementing the `List`
+/// interface.
+///
+/// All operations are defined in terms of `length`, `operator[]`,
+/// `operator[]=` and `length=`, which need to be implemented.
+///
+/// *NOTICE*: Forwarding just these four operations to a normal growable [List]
+/// (as created by `new List()`) will give very bad performance for `add` and
+/// `addAll` operations of `ListBase`. These operations are implemented by
+/// increasing the length of the list by one for each `add` operation, and
+/// repeatedly increasing the length of a growable list is not efficient.
+/// To avoid this, either override 'add' and 'addAll' to also forward directly
+/// to the growable list, or, preferably, use `DelegatingList` from
+/// "package:collection/wrappers.dart" instead.
abstract class ListBase<E> extends Object with ListMixin<E> {
- /**
- * Convert a `List` to a string as `[each, element, as, string]`.
- *
- * Handles circular references where converting one of the elements
- * to a string ends up converting [list] to a string again.
- */
+ /// Convert a `List` to a string as `[each, element, as, string]`.
+ ///
+ /// Handles circular references where converting one of the elements
+ /// to a string ends up converting [list] to a string again.
static String listToString(List list) =>
IterableBase.iterableToFullString(list, '[', ']');
}
-/**
- * Base implementation of a [List] class.
- *
- * `ListMixin` can be used as a mixin to make a class implement
- * the `List` interface.
- *
- * This implements all read operations using only the `length` and
- * `operator[]` members. It implements write operations using those and
- * `length=` and `operator[]=`
- *
- * *NOTICE*: Forwarding just these four operations to a normal growable [List]
- * (as created by `new List()`) will give very bad performance for `add` and
- * `addAll` operations of `ListBase`. These operations are implemented by
- * increasing the length of the list by one for each `add` operation, and
- * repeatedly increasing the length of a growable list is not efficient.
- * To avoid this, either override 'add' and 'addAll' to also forward directly
- * to the growable list, or, if possible, use `DelegatingList` from
- * "package:collection/wrappers.dart" instead.
- */
+/// Base implementation of a [List] class.
+///
+/// `ListMixin` can be used as a mixin to make a class implement
+/// the `List` interface.
+///
+/// This implements all read operations using only the `length` and
+/// `operator[]` members. It implements write operations using those and
+/// `length=` and `operator[]=`
+///
+/// *NOTICE*: Forwarding just these four operations to a normal growable [List]
+/// (as created by `new List()`) will give very bad performance for `add` and
+/// `addAll` operations of `ListBase`. These operations are implemented by
+/// increasing the length of the list by one for each `add` operation, and
+/// repeatedly increasing the length of a growable list is not efficient.
+/// To avoid this, either override 'add' and 'addAll' to also forward directly
+/// to the growable list, or, if possible, use `DelegatingList` from
+/// "package:collection/wrappers.dart" instead.
abstract class ListMixin<E> implements List<E> {
// Iterable interface.
// TODO(lrn): When we get composable mixins, reuse IterableMixin instead
// of redaclating everything.
- Iterator<E> get iterator => new ListIterator<E>(this);
+ Iterator<E> get iterator => ListIterator<E>(this);
E elementAt(int index) => this[index];
Iterable<E> followedBy(Iterable<E> other) =>
- new FollowedByIterable<E>.firstEfficient(this, other);
+ FollowedByIterable<E>.firstEfficient(this, other);
void forEach(void action(E element)) {
int length = this.length;
for (int i = 0; i < length; i++) {
action(this[i]);
if (length != this.length) {
- throw new ConcurrentModificationError(this);
+ throw ConcurrentModificationError(this);
}
}
}
@@ -107,7 +102,7 @@
for (int i = 0; i < length; i++) {
if (this[i] == element) return true;
if (length != this.length) {
- throw new ConcurrentModificationError(this);
+ throw ConcurrentModificationError(this);
}
}
return false;
@@ -118,7 +113,7 @@
for (int i = 0; i < length; i++) {
if (!test(this[i])) return false;
if (length != this.length) {
- throw new ConcurrentModificationError(this);
+ throw ConcurrentModificationError(this);
}
}
return true;
@@ -129,7 +124,7 @@
for (int i = 0; i < length; i++) {
if (test(this[i])) return true;
if (length != this.length) {
- throw new ConcurrentModificationError(this);
+ throw ConcurrentModificationError(this);
}
}
return false;
@@ -141,7 +136,7 @@
E element = this[i];
if (test(element)) return element;
if (length != this.length) {
- throw new ConcurrentModificationError(this);
+ throw ConcurrentModificationError(this);
}
}
if (orElse != null) return orElse();
@@ -154,7 +149,7 @@
E element = this[i];
if (test(element)) return element;
if (length != this.length) {
- throw new ConcurrentModificationError(this);
+ throw ConcurrentModificationError(this);
}
}
if (orElse != null) return orElse();
@@ -175,7 +170,7 @@
match = element;
}
if (length != this.length) {
- throw new ConcurrentModificationError(this);
+ throw ConcurrentModificationError(this);
}
}
if (matchFound) return match;
@@ -185,18 +180,18 @@
String join([String separator = ""]) {
if (length == 0) return "";
- StringBuffer buffer = new StringBuffer()..writeAll(this, separator);
+ StringBuffer buffer = StringBuffer()..writeAll(this, separator);
return buffer.toString();
}
- Iterable<E> where(bool test(E element)) => new WhereIterable<E>(this, test);
+ Iterable<E> where(bool test(E element)) => WhereIterable<E>(this, test);
- Iterable<T> whereType<T>() => new WhereTypeIterable<T>(this);
+ Iterable<T> whereType<T>() => WhereTypeIterable<T>(this);
- Iterable<T> map<T>(T f(E element)) => new MappedListIterable<E, T>(this, f);
+ Iterable<T> map<T>(T f(E element)) => MappedListIterable<E, T>(this, f);
Iterable<T> expand<T>(Iterable<T> f(E element)) =>
- new ExpandIterable<E, T>(this, f);
+ ExpandIterable<E, T>(this, f);
E reduce(E combine(E previousValue, E element)) {
int length = this.length;
@@ -205,7 +200,7 @@
for (int i = 1; i < length; i++) {
value = combine(value, this[i]);
if (length != this.length) {
- throw new ConcurrentModificationError(this);
+ throw ConcurrentModificationError(this);
}
}
return value;
@@ -217,30 +212,30 @@
for (int i = 0; i < length; i++) {
value = combine(value, this[i]);
if (length != this.length) {
- throw new ConcurrentModificationError(this);
+ throw ConcurrentModificationError(this);
}
}
return value;
}
- Iterable<E> skip(int count) => new SubListIterable<E>(this, count, null);
+ Iterable<E> skip(int count) => SubListIterable<E>(this, count, null);
Iterable<E> skipWhile(bool test(E element)) {
- return new SkipWhileIterable<E>(this, test);
+ return SkipWhileIterable<E>(this, test);
}
- Iterable<E> take(int count) => new SubListIterable<E>(this, 0, count);
+ Iterable<E> take(int count) => SubListIterable<E>(this, 0, count);
Iterable<E> takeWhile(bool test(E element)) {
- return new TakeWhileIterable<E>(this, test);
+ return TakeWhileIterable<E>(this, test);
}
- List<E> toList({bool growable: true}) {
+ List<E> toList({bool growable = true}) {
List<E> result;
if (growable) {
result = <E>[]..length = length;
} else {
- result = new List<E>(length);
+ result = List<E>(length);
}
for (int i = 0; i < length; i++) {
result[i] = this[i];
@@ -249,7 +244,7 @@
}
Set<E> toSet() {
- Set<E> result = new Set<E>();
+ Set<E> result = Set<E>();
for (int i = 0; i < length; i++) {
result.add(this[i]);
}
@@ -264,7 +259,7 @@
void addAll(Iterable<E> iterable) {
int i = this.length;
for (E element in iterable) {
- assert(this.length == i || (throw new ConcurrentModificationError(this)));
+ assert(this.length == i || (throw ConcurrentModificationError(this)));
this.length = i + 1;
this[i] = element;
i++;
@@ -312,7 +307,7 @@
retained.add(element);
}
if (length != this.length) {
- throw new ConcurrentModificationError(this);
+ throw ConcurrentModificationError(this);
}
}
if (retained.length != this.length) {
@@ -346,7 +341,7 @@
}
void shuffle([Random random]) {
- random ??= new Random();
+ random ??= Random();
int length = this.length;
while (length > 1) {
int pos = random.nextInt(length);
@@ -358,7 +353,7 @@
}
Map<int, E> asMap() {
- return new ListMapView<E>(this);
+ return ListMapView<E>(this);
}
List<E> operator +(List<E> other) {
@@ -382,7 +377,7 @@
Iterable<E> getRange(int start, int end) {
RangeError.checkValidRange(start, end, this.length);
- return new SubListIterable<E>(this, start, end);
+ return SubListIterable<E>(this, start, end);
}
void removeRange(int start, int end) {
@@ -517,7 +512,7 @@
// If the iterable's length is linked to this list's length somehow,
// we can't insert one in the other.
this.length -= insertionLength;
- throw new ConcurrentModificationError(iterable);
+ throw ConcurrentModificationError(iterable);
}
setRange(index + insertionLength, this.length, this, index);
setAll(index, iterable);
@@ -533,7 +528,7 @@
}
}
- Iterable<E> get reversed => new ReversedListIterable<E>(this);
+ Iterable<E> get reversed => ReversedListIterable<E>(this);
String toString() => IterableBase.iterableToFullString(this, '[', ']');
}
diff --git a/sdk/lib/collection/maps.dart b/sdk/lib/collection/maps.dart
index f54404f..8159342 100644
--- a/sdk/lib/collection/maps.dart
+++ b/sdk/lib/collection/maps.dart
@@ -4,22 +4,20 @@
part of dart.collection;
-/**
- * Base class for implementing a [Map].
- *
- * This class has a basic implementation of all but five of the members of
- * [Map].
- * A basic `Map` class can be implemented by extending this class and
- * implementing `keys`, `operator[]`, `operator[]=`, `remove` and `clear`.
- * The remaining operations are implemented in terms of these five.
- *
- * The `keys` iterable should have efficient [Iterable.length] and
- * [Iterable.contains] operations, and it should catch concurrent modifications
- * of the keys while iterating.
- *
- * A more efficient implementation is usually possible by overriding
- * some of the other members as well.
- */
+/// Base class for implementing a [Map].
+///
+/// This class has a basic implementation of all but five of the members of
+/// [Map].
+/// A basic `Map` class can be implemented by extending this class and
+/// implementing `keys`, `operator[]`, `operator[]=`, `remove` and `clear`.
+/// The remaining operations are implemented in terms of these five.
+///
+/// The `keys` iterable should have efficient [Iterable.length] and
+/// [Iterable.contains] operations, and it should catch concurrent modifications
+/// of the keys while iterating.
+///
+/// A more efficient implementation is usually possible by overriding
+/// some of the other members as well.
abstract class MapBase<K, V> extends MapMixin<K, V> {
static String mapToString(Map m) {
// Reuses the list in IterableBase for detecting toString cycles.
@@ -27,7 +25,7 @@
return '{...}';
}
- var result = new StringBuffer();
+ var result = StringBuffer();
try {
_toStringVisiting.add(m);
result.write('{');
@@ -52,12 +50,10 @@
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`.
- */
+ /// 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)) {
key ??= _id;
@@ -68,12 +64,10 @@
}
}
- /**
- * Fills a map by associating the [keys] to [values].
- *
- * This method is used by [Map] classes in the named constructor
- * `fromIterables`.
- */
+ /// 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;
@@ -88,27 +82,25 @@
}
if (hasNextKey || hasNextValue) {
- throw new ArgumentError("Iterables do not have same length.");
+ throw ArgumentError("Iterables do not have same length.");
}
}
}
-/**
- * Mixin implementing a [Map].
- *
- * This mixin has a basic implementation of all but five of the members of
- * [Map].
- * A basic `Map` class can be implemented by mixin in this class and
- * implementing `keys`, `operator[]`, `operator[]=`, `remove` and `clear`.
- * The remaining operations are implemented in terms of these five.
- *
- * The `keys` iterable should have efficient [Iterable.length] and
- * [Iterable.contains] operations, and it should catch concurrent modifications
- * of the keys while iterating.
- *
- * A more efficient implementation is usually possible by overriding
- * some of the other members as well.
- */
+/// Mixin implementing a [Map].
+///
+/// This mixin has a basic implementation of all but five of the members of
+/// [Map].
+/// A basic `Map` class can be implemented by mixin in this class and
+/// implementing `keys`, `operator[]`, `operator[]=`, `remove` and `clear`.
+/// The remaining operations are implemented in terms of these five.
+///
+/// The `keys` iterable should have efficient [Iterable.length] and
+/// [Iterable.contains] operations, and it should catch concurrent modifications
+/// of the keys while iterating.
+///
+/// A more efficient implementation is usually possible by overriding
+/// some of the other members as well.
abstract class MapMixin<K, V> implements Map<K, V> {
Iterable<K> get keys;
V operator [](Object key);
@@ -152,7 +144,7 @@
if (ifAbsent != null) {
return this[key] = ifAbsent();
}
- throw new ArgumentError.value(key, "key", "Key not in map.");
+ throw ArgumentError.value(key, "key", "Key not in map.");
}
void updateAll(V update(K key, V value)) {
@@ -162,7 +154,7 @@
}
Iterable<MapEntry<K, V>> get entries {
- return keys.map((K key) => new MapEntry<K, V>(key, this[key]));
+ return keys.map((K key) => MapEntry<K, V>(key, this[key]));
}
Map<K2, V2> map<K2, V2>(MapEntry<K2, V2> transform(K key, V value)) {
@@ -194,39 +186,35 @@
int get length => keys.length;
bool get isEmpty => keys.isEmpty;
bool get isNotEmpty => keys.isNotEmpty;
- Iterable<V> get values => new _MapBaseValueIterable<K, V>(this);
+ Iterable<V> get values => _MapBaseValueIterable<K, V>(this);
String toString() => MapBase.mapToString(this);
}
-/**
- * Basic implementation of an unmodifiable [Map].
- *
- * This class has a basic implementation of all but two of the members of
- * an umodifiable [Map].
- * A simple unmodifiable `Map` class can be implemented by extending this
- * class and implementing `keys` and `operator[]`.
- *
- * Modifying operations throw when used.
- * The remaining non-modifying operations are implemented in terms of `keys`
- * and `operator[]`.
- *
- * The `keys` iterable should have efficient [Iterable.length] and
- * [Iterable.contains] operations, and it should catch concurrent modifications
- * of the keys while iterating.
- *
- * A more efficient implementation is usually possible by overriding
- * some of the other members as well.
- */
+/// Basic implementation of an unmodifiable [Map].
+///
+/// This class has a basic implementation of all but two of the members of
+/// an umodifiable [Map].
+/// A simple unmodifiable `Map` class can be implemented by extending this
+/// class and implementing `keys` and `operator[]`.
+///
+/// Modifying operations throw when used.
+/// The remaining non-modifying operations are implemented in terms of `keys`
+/// and `operator[]`.
+///
+/// The `keys` iterable should have efficient [Iterable.length] and
+/// [Iterable.contains] operations, and it should catch concurrent modifications
+/// of the keys while iterating.
+///
+/// A more efficient implementation is usually possible by overriding
+/// some of the other members as well.
abstract class UnmodifiableMapBase<K, V> = MapBase<K, V>
with _UnmodifiableMapMixin<K, V>;
-/**
- * Implementation of [Map.values] based on the map and its [Map.keys] iterable.
- *
- * Iterable that iterates over the values of a `Map`.
- * It accesses the values by iterating over the keys of the map, and using the
- * map's `operator[]` to lookup the keys.
- */
+/// Implementation of [Map.values] based on the map and its [Map.keys] iterable.
+///
+/// Iterable that iterates over the values of a `Map`.
+/// It accesses the values by iterating over the keys of the map, and using the
+/// map's `operator[]` to lookup the keys.
class _MapBaseValueIterable<K, V> extends EfficientLengthIterable<V> {
final Map<K, V> _map;
_MapBaseValueIterable(this._map);
@@ -238,15 +226,13 @@
V get single => _map[_map.keys.single];
V get last => _map[_map.keys.last];
- Iterator<V> get iterator => new _MapBaseValueIterator<K, V>(_map);
+ Iterator<V> get iterator => _MapBaseValueIterator<K, V>(_map);
}
-/**
- * Iterator created by [_MapBaseValueIterable].
- *
- * Iterates over the values of a map by iterating its keys and lookup up the
- * values.
- */
+/// Iterator created by [_MapBaseValueIterable].
+///
+/// Iterates over the values of a map by iterating its keys and lookup up the
+/// values.
class _MapBaseValueIterator<K, V> implements Iterator<V> {
final Iterator<K> _keys;
final Map<K, V> _map;
@@ -268,64 +254,62 @@
V get current => _current;
}
-/**
- * Mixin that overrides mutating map operations with implementations that throw.
- */
+/// Mixin that overrides mutating map operations with implementations that
+/// throw.
abstract class _UnmodifiableMapMixin<K, V> implements Map<K, V> {
- /** This operation is not supported by an unmodifiable map. */
+ /// This operation is not supported by an unmodifiable map.
void operator []=(K key, V value) {
- throw new UnsupportedError("Cannot modify unmodifiable map");
+ throw UnsupportedError("Cannot modify unmodifiable map");
}
- /** This operation is not supported by an unmodifiable map. */
+ /// This operation is not supported by an unmodifiable map.
void addAll(Map<K, V> other) {
- throw new UnsupportedError("Cannot modify unmodifiable map");
+ throw UnsupportedError("Cannot modify unmodifiable map");
}
- /** This operation is not supported by an unmodifiable map. */
+ /// This operation is not supported by an unmodifiable map.
void addEntries(Iterable<MapEntry<K, V>> entries) {
- throw new UnsupportedError("Cannot modify unmodifiable map");
+ throw UnsupportedError("Cannot modify unmodifiable map");
}
- /** This operation is not supported by an unmodifiable map. */
+ /// This operation is not supported by an unmodifiable map.
void clear() {
- throw new UnsupportedError("Cannot modify unmodifiable map");
+ throw UnsupportedError("Cannot modify unmodifiable map");
}
- /** This operation is not supported by an unmodifiable map. */
+ /// This operation is not supported by an unmodifiable map.
V remove(Object key) {
- throw new UnsupportedError("Cannot modify unmodifiable map");
+ throw UnsupportedError("Cannot modify unmodifiable map");
}
- /** This operation is not supported by an unmodifiable map. */
+ /// This operation is not supported by an unmodifiable map.
void removeWhere(bool test(K key, V value)) {
- throw new UnsupportedError("Cannot modify unmodifiable map");
+ throw UnsupportedError("Cannot modify unmodifiable map");
}
- /** This operation is not supported by an unmodifiable map. */
+ /// This operation is not supported by an unmodifiable map.
V putIfAbsent(K key, V ifAbsent()) {
- throw new UnsupportedError("Cannot modify unmodifiable map");
+ throw UnsupportedError("Cannot modify unmodifiable map");
}
- /** This operation is not supported by an unmodifiable map. */
+ /// This operation is not supported by an unmodifiable map.
V update(K key, V update(V value), {V ifAbsent()}) {
- throw new UnsupportedError("Cannot modify unmodifiable map");
+ throw UnsupportedError("Cannot modify unmodifiable map");
}
- /** This operation is not supported by an unmodifiable map. */
+ /// This operation is not supported by an unmodifiable map.
void updateAll(V update(K key, V value)) {
- throw new UnsupportedError("Cannot modify unmodifiable map");
+ throw UnsupportedError("Cannot modify unmodifiable map");
}
}
-/**
- * Wrapper around a class that implements [Map] that only exposes `Map` members.
- *
- * A simple wrapper that delegates all `Map` members to the map provided in the
- * constructor.
- *
- * Base for delegating map implementations like [UnmodifiableMapView].
- */
+/// Wrapper around a class that implements [Map] that only exposes `Map`
+/// members.
+///
+/// A simple wrapper that delegates all `Map` members to the map provided in the
+/// constructor.
+///
+/// Base for delegating map implementations like [UnmodifiableMapView].
class MapView<K, V> implements Map<K, V> {
final Map<K, V> _map;
const MapView(Map<K, V> map) : _map = map;
@@ -380,17 +364,15 @@
}
}
-/**
- * View of a [Map] that disallow modifying the map.
- *
- * A wrapper around a `Map` that forwards all members to the map provided in
- * the constructor, except for operations that modify the map.
- * Modifying operations throw instead.
- */
+/// View of a [Map] that disallow modifying the map.
+///
+/// A wrapper around a `Map` that forwards all members to the map provided in
+/// the constructor, except for operations that modify the map.
+/// Modifying operations throw instead.
class UnmodifiableMapView<K, V> extends MapView<K, V>
with _UnmodifiableMapMixin<K, V> {
UnmodifiableMapView(Map<K, V> map) : super(map);
Map<RK, RV> cast<RK, RV>() =>
- new UnmodifiableMapView<RK, RV>(_map.cast<RK, RV>());
+ UnmodifiableMapView<RK, RV>(_map.cast<RK, RV>());
}
diff --git a/sdk/lib/collection/queue.dart b/sdk/lib/collection/queue.dart
index 7f82357..62994b9 100644
--- a/sdk/lib/collection/queue.dart
+++ b/sdk/lib/collection/queue.dart
@@ -4,140 +4,108 @@
part of dart.collection;
-/**
- * A [Queue] is a collection that can be manipulated at both ends. One
- * can iterate over the elements of a queue through [forEach] or with
- * an [Iterator].
- *
- * It is generally not allowed to modify the queue (add or remove entries) while
- * an operation on the queue is being performed, for example during a call to
- * [forEach].
- * Modifying the queue while it is being iterated will most likely break the
- * iteration.
- * This goes both for using the [iterator] directly, or for iterating an
- * `Iterable` returned by a method like [map] or [where].
- */
+/// A [Queue] is a collection that can be manipulated at both ends. One
+/// can iterate over the elements of a queue through [forEach] or with
+/// an [Iterator].
+///
+/// It is generally not allowed to modify the queue (add or remove entries)
+/// while an operation on the queue is being performed, for example during a
+/// call to [forEach].
+/// Modifying the queue while it is being iterated will most likely break the
+/// iteration.
+/// This goes both for using the [iterator] directly, or for iterating an
+/// `Iterable` returned by a method like [map] or [where].
abstract class Queue<E> implements EfficientLengthIterable<E> {
- /**
- * Creates a queue.
- */
+ /// Creates a queue.
factory Queue() = ListQueue<E>;
- /**
- * Creates a queue containing all [elements].
- *
- * The element order in the queue is as if the elements were added using
- * [addLast] in the order provided by [elements.iterator].
- *
- * All the [elements] should be instances of [E].
- * The `elements` iterable itself may have any element type, so this
- * constructor can be used to down-cast a `Queue`, for example as:
- * ```dart
- * Queue<SuperType> superQueue = ...;
- * Queue<SubType> subQueue =
- * new Queue<SubType>.from(superSet.whereType<SubType>());
- * ```
- */
+ /// Creates a queue containing all [elements].
+ ///
+ /// The element order in the queue is as if the elements were added using
+ /// [addLast] in the order provided by [elements.iterator].
+ ///
+ /// All the [elements] should be instances of [E].
+ /// The `elements` iterable itself may have any element type, so this
+ /// constructor can be used to down-cast a `Queue`, for example as:
+ /// ```dart
+ /// Queue<SuperType> superQueue = ...;
+ /// Queue<SubType> subQueue =
+ /// new Queue<SubType>.from(superSet.whereType<SubType>());
+ /// ```
factory Queue.from(Iterable elements) = ListQueue<E>.from;
- /**
- * Creates a queue from [elements].
- *
- * The element order in the queue is as if the elements were added using
- * [addLast] in the order provided by [elements.iterator].
- */
+ /// Creates a queue from [elements].
+ ///
+ /// The element order in the queue is as if the elements were added using
+ /// [addLast] in the order provided by [elements.iterator].
factory Queue.of(Iterable<E> elements) = ListQueue<E>.of;
- /**
- * Adapts [source] to be a `Queue<T>`.
- *
- * Any time the queue would produce an element that is not a [T],
- * the element access will throw.
- *
- * Any time a [T] value is attempted stored into the adapted queue,
- * the store will throw unless the value is also an instance of [S].
- *
- * If all accessed elements of [source] are actually instances of [T],
- * and if all elements stored into the returned queue are actually instance
- * of [S],
- * then the returned queue can be used as a `Queue<T>`.
- */
- static Queue<T> castFrom<S, T>(Queue<S> source) =>
- new CastQueue<S, T>(source);
+ /// Adapts [source] to be a `Queue<T>`.
+ ///
+ /// Any time the queue would produce an element that is not a [T],
+ /// the element access will throw.
+ ///
+ /// Any time a [T] value is attempted stored into the adapted queue,
+ /// the store will throw unless the value is also an instance of [S].
+ ///
+ /// If all accessed elements of [source] are actually instances of [T],
+ /// and if all elements stored into the returned queue are actually instance
+ /// of [S],
+ /// then the returned queue can be used as a `Queue<T>`.
+ static Queue<T> castFrom<S, T>(Queue<S> source) => CastQueue<S, T>(source);
- /**
- * Provides a view of this queue as a queue of [R] instances, if necessary.
- *
- * If this queue contains only instances of [R], all read operations
- * will work correctly. If any operation tries to access an element
- * that is not an instance of [R], the access will throw instead.
- *
- * Elements added to the queue (e.g., by using [addFirst] or [addAll])
- * must be instance of [R] to be valid arguments to the adding function,
- * and they must be instances of [E] as well to be accepted by
- * this queue as well.
- */
+ /// Provides a view of this queue as a queue of [R] instances, if necessary.
+ ///
+ /// If this queue contains only instances of [R], all read operations
+ /// will work correctly. If any operation tries to access an element
+ /// that is not an instance of [R], the access will throw instead.
+ ///
+ /// Elements added to the queue (e.g., by using [addFirst] or [addAll])
+ /// must be instance of [R] to be valid arguments to the adding function,
+ /// and they must be instances of [E] as well to be accepted by
+ /// this queue as well.
Queue<R> cast<R>();
- /**
- * Removes and returns the first element of this queue.
- *
- * The queue must not be empty when this method is called.
- */
+
+ /// Removes and returns the first element of this queue.
+ ///
+ /// The queue must not be empty when this method is called.
E removeFirst();
- /**
- * Removes and returns the last element of the queue.
- *
- * The queue must not be empty when this method is called.
- */
+ /// Removes and returns the last element of the queue.
+ ///
+ /// The queue must not be empty when this method is called.
E removeLast();
- /**
- * Adds [value] at the beginning of the queue.
- */
+ /// Adds [value] at the beginning of the queue.
void addFirst(E value);
- /**
- * Adds [value] at the end of the queue.
- */
+ /// Adds [value] at the end of the queue.
void addLast(E value);
- /**
- * Adds [value] at the end of the queue.
- */
+ /// Adds [value] at the end of the queue.
void add(E value);
- /**
- * Remove a single instance of [value] from the queue.
- *
- * Returns `true` if a value was removed, or `false` if the queue
- * contained no element equal to [value].
- */
+ /// Remove a single instance of [value] from the queue.
+ ///
+ /// Returns `true` if a value was removed, or `false` if the queue
+ /// contained no element equal to [value].
bool remove(Object value);
- /**
- * Adds all elements of [iterable] at the end of the queue. The
- * length of the queue is extended by the length of [iterable].
- */
+ /// Adds all elements of [iterable] at the end of the queue. The
+ /// length of the queue is extended by the length of [iterable].
void addAll(Iterable<E> iterable);
- /**
- * Removes all elements matched by [test] from the queue.
- *
- * The `test` function must not throw or modify the queue.
- */
+ /// Removes all elements matched by [test] from the queue.
+ ///
+ /// The `test` function must not throw or modify the queue.
void removeWhere(bool test(E element));
- /**
- * Removes all elements not matched by [test] from the queue.
- *
- * The `test` function must not throw or modify the queue.
- */
+ /// Removes all elements not matched by [test] from the queue.
+ ///
+ /// The `test` function must not throw or modify the queue.
void retainWhere(bool test(E element));
- /**
- * Removes all elements in the queue. The size of the queue becomes zero.
- */
+ /// Removes all elements in the queue. The size of the queue becomes zero.
void clear();
}
@@ -160,10 +128,8 @@
}
}
-/**
- * An entry in a doubly linked list. It contains a pointer to the next
- * entry, the previous entry, and the boxed element.
- */
+/// An entry in a doubly linked list. It contains a pointer to the next
+/// entry, the previous entry, and the boxed element.
class DoubleLinkedQueueEntry<E> extends _DoubleLink<DoubleLinkedQueueEntry<E>> {
/// The element in the queue.
E element;
@@ -172,12 +138,12 @@
/// Appends the given [e] as entry just after this entry.
void append(E e) {
- new DoubleLinkedQueueEntry<E>(e)._link(this, _nextLink);
+ DoubleLinkedQueueEntry<E>(e)._link(this, _nextLink);
}
/// Prepends the given [e] as entry just before this entry.
void prepend(E e) {
- new DoubleLinkedQueueEntry<E>(e)._link(_previousLink, this);
+ DoubleLinkedQueueEntry<E>(e)._link(_previousLink, this);
}
E remove() {
@@ -192,14 +158,12 @@
DoubleLinkedQueueEntry<E> nextEntry() => _nextLink;
}
-/**
- * Interface for the link classes used by [DoubleLinkedQueue].
- *
- * Both the [_DoubleLinkedQueueElement] and [_DoubleLinkedQueueSentinel]
- * implement this interface.
- * The entry contains a link back to the queue, so calling `append`
- * or `prepend` can correctly update the element count.
- */
+/// Interface for the link classes used by [DoubleLinkedQueue].
+///
+/// Both the [_DoubleLinkedQueueElement] and [_DoubleLinkedQueueSentinel]
+/// implement this interface.
+/// The entry contains a link back to the queue, so calling `append`
+/// or `prepend` can correctly update the element count.
abstract class _DoubleLinkedQueueEntry<E> extends DoubleLinkedQueueEntry<E> {
DoubleLinkedQueue<E> _queue;
_DoubleLinkedQueueEntry(E element, this._queue) : super(element);
@@ -207,11 +171,11 @@
DoubleLinkedQueueEntry<E> _asNonSentinelEntry();
void _append(E e) {
- new _DoubleLinkedQueueElement<E>(e, _queue)._link(this, _nextLink);
+ _DoubleLinkedQueueElement<E>(e, _queue)._link(this, _nextLink);
}
void _prepend(E e) {
- new _DoubleLinkedQueueElement<E>(e, _queue)._link(_previousLink, this);
+ _DoubleLinkedQueueElement<E>(e, _queue)._link(_previousLink, this);
}
E _remove();
@@ -229,12 +193,10 @@
}
}
-/**
- * The actual entry type used by the [DoubleLinkedQueue].
- *
- * The entry contains a reference to the queue, allowing
- * [append]/[prepend] to update the list length.
- */
+/// The actual entry type used by the [DoubleLinkedQueue].
+///
+/// The entry contains a reference to the queue, allowing
+/// [append]/[prepend] to update the list length.
class _DoubleLinkedQueueElement<E> extends _DoubleLinkedQueueEntry<E> {
_DoubleLinkedQueueElement(E element, DoubleLinkedQueue<E> queue)
: super(element, queue);
@@ -265,14 +227,12 @@
}
}
-/**
- * A sentinel in a double linked list is used to manipulate the list
- * at both ends.
- * A double linked list has exactly one sentinel,
- * which is the only entry when the list is constructed.
- * Initially, a sentinel has its next and previous entry point to itself.
- * A sentinel does not box any user element.
- */
+/// A sentinel in a double linked list is used to manipulate the list
+/// at both ends.
+/// A double linked list has exactly one sentinel,
+/// which is the only entry when the list is constructed.
+/// Initially, a sentinel has its next and previous entry point to itself.
+/// A sentinel does not box any user element.
class _DoubleLinkedQueueSentinel<E> extends _DoubleLinkedQueueEntry<E> {
_DoubleLinkedQueueSentinel(DoubleLinkedQueue<E> queue) : super(null, queue) {
_previousLink = this;
@@ -283,61 +243,55 @@
return null;
}
- /** Hit by, e.g., [DoubleLinkedQueue.removeFirst] if the queue is empty. */
+ /// Hit by, e.g., [DoubleLinkedQueue.removeFirst] if the queue is empty.
E _remove() {
throw IterableElementError.noElement();
}
- /** Hit by, e.g., [DoubleLinkedQueue.first] if the queue is empty. */
+ /// Hit by, e.g., [DoubleLinkedQueue.first] if the queue is empty.
E get _element {
throw IterableElementError.noElement();
}
}
-/**
- * A [Queue] implementation based on a double-linked list.
- *
- * Allows constant time add, remove-at-ends and peek operations.
- */
+/// A [Queue] implementation based on a double-linked list.
+///
+/// Allows constant time add, remove-at-ends and peek operations.
class DoubleLinkedQueue<E> extends Iterable<E> implements Queue<E> {
_DoubleLinkedQueueSentinel<E> _sentinel;
int _elementCount = 0;
DoubleLinkedQueue() {
- _sentinel = new _DoubleLinkedQueueSentinel<E>(this);
+ _sentinel = _DoubleLinkedQueueSentinel<E>(this);
}
- /**
- * Creates a double-linked queue containing all [elements].
- *
- * The element order in the queue is as if the elements were added using
- * [addLast] in the order provided by [elements.iterator].
- *
- * All the [elements] should be instances of [E].
- * The `elements` iterable itself may have any element type, so this
- * constructor can be used to down-cast a `Queue`, for example as:
- * ```dart
- * Queue<SuperType> superQueue = ...;
- * Queue<SubType> subQueue =
- * new DoubleLinkedQueue<SubType>.from(superQueue.whereType<SubType>());
- * ```
- */
+ /// Creates a double-linked queue containing all [elements].
+ ///
+ /// The element order in the queue is as if the elements were added using
+ /// [addLast] in the order provided by [elements.iterator].
+ ///
+ /// All the [elements] should be instances of [E].
+ /// The `elements` iterable itself may have any element type, so this
+ /// constructor can be used to down-cast a `Queue`, for example as:
+ /// ```dart
+ /// Queue<SuperType> superQueue = ...;
+ /// Queue<SubType> subQueue =
+ /// new DoubleLinkedQueue<SubType>.from(superQueue.whereType<SubType>());
+ /// ```
factory DoubleLinkedQueue.from(Iterable elements) {
- Queue<E> list = new DoubleLinkedQueue<E>();
+ Queue<E> list = DoubleLinkedQueue<E>();
for (final e in elements) {
list.addLast(e);
}
return list;
}
- /**
- * Creates a double-linked queue from [elements].
- *
- * The element order in the queue is as if the elements were added using
- * [addLast] in the order provided by [elements.iterator].
- */
+ /// Creates a double-linked queue from [elements].
+ ///
+ /// The element order in the queue is as if the elements were added using
+ /// [addLast] in the order provided by [elements.iterator].
factory DoubleLinkedQueue.of(Iterable<E> elements) =>
- new DoubleLinkedQueue<E>()..addAll(elements);
+ DoubleLinkedQueue<E>()..addAll(elements);
Queue<R> cast<R>() => Queue.castFrom<E, R>(this);
int get length => _elementCount;
@@ -384,7 +338,7 @@
bool equals = (entry._element == o);
if (!identical(this, entry._queue)) {
// Entry must still be in the queue.
- throw new ConcurrentModificationError(this);
+ throw ConcurrentModificationError(this);
}
if (equals) {
entry._remove();
@@ -402,7 +356,7 @@
bool matches = test(entry._element);
if (!identical(this, entry._queue)) {
// Entry must still be in the queue.
- throw new ConcurrentModificationError(this);
+ throw ConcurrentModificationError(this);
}
_DoubleLinkedQueueEntry<E> next = entry._nextLink; // Cannot be null.
if (identical(removeMatching, matches)) {
@@ -441,30 +395,26 @@
throw IterableElementError.tooMany();
}
- /**
- * The entry object of the first element in the queue.
- *
- * Each element of the queue has an associated [DoubleLinkedQueueEntry].
- * Returns the entry object corresponding to the first element of the queue.
- *
- * The entry objects can also be accessed using [lastEntry],
- * and they can be iterated using [DoubleLinkedQueueEntry.nextEntry()] and
- * [DoubleLinkedQueueEntry.previousEntry()].
- */
+ /// The entry object of the first element in the queue.
+ ///
+ /// Each element of the queue has an associated [DoubleLinkedQueueEntry].
+ /// Returns the entry object corresponding to the first element of the queue.
+ ///
+ /// The entry objects can also be accessed using [lastEntry],
+ /// and they can be iterated using [DoubleLinkedQueueEntry.nextEntry()] and
+ /// [DoubleLinkedQueueEntry.previousEntry()].
DoubleLinkedQueueEntry<E> firstEntry() {
return _sentinel.nextEntry();
}
- /**
- * The entry object of the last element in the queue.
- *
- * Each element of the queue has an associated [DoubleLinkedQueueEntry].
- * Returns the entry object corresponding to the last element of the queue.
- *
- * The entry objects can also be accessed using [firstEntry],
- * and they can be iterated using [DoubleLinkedQueueEntry.nextEntry()] and
- * [DoubleLinkedQueueEntry.previousEntry()].
- */
+ /// The entry object of the last element in the queue.
+ ///
+ /// Each element of the queue has an associated [DoubleLinkedQueueEntry].
+ /// Returns the entry object corresponding to the last element of the queue.
+ ///
+ /// The entry objects can also be accessed using [firstEntry],
+ /// and they can be iterated using [DoubleLinkedQueueEntry.nextEntry()] and
+ /// [DoubleLinkedQueueEntry.previousEntry()].
DoubleLinkedQueueEntry<E> lastEntry() {
return _sentinel.previousEntry();
}
@@ -479,24 +429,22 @@
_elementCount = 0;
}
- /**
- * Calls [action] for each entry object of this double-linked queue.
- *
- * Each element of the queue has an associated [DoubleLinkedQueueEntry].
- * This method iterates the entry objects from first to last and calls
- * [action] with each object in turn.
- *
- * The entry objects can also be accessed using [firstEntry] and [lastEntry],
- * and iterated using [DoubleLinkedQueueEntry.nextEntry()] and
- * [DoubleLinkedQueueEntry.previousEntry()].
- *
- * The [action] function can use methods on [DoubleLinkedQueueEntry] to remove
- * the entry or it can insert elements before or after then entry.
- * If the current entry is removed, iteration continues with the entry that
- * was following the current entry when [action] was called. Any elements
- * inserted after the current element before it is removed will not be
- * visited by the iteration.
- */
+ /// Calls [action] for each entry object of this double-linked queue.
+ ///
+ /// Each element of the queue has an associated [DoubleLinkedQueueEntry].
+ /// This method iterates the entry objects from first to last and calls
+ /// [action] with each object in turn.
+ ///
+ /// The entry objects can also be accessed using [firstEntry] and [lastEntry],
+ /// and iterated using [DoubleLinkedQueueEntry.nextEntry()] and
+ /// [DoubleLinkedQueueEntry.previousEntry()].
+ ///
+ /// The [action] function can use methods on [DoubleLinkedQueueEntry] to
+ /// remove the entry or it can insert elements before or after then entry.
+ /// If the current entry is removed, iteration continues with the entry that
+ /// was following the current entry when [action] was called. Any elements
+ /// inserted after the current element before it is removed will not be
+ /// visited by the iteration.
void forEachEntry(void action(DoubleLinkedQueueEntry<E> element)) {
_DoubleLinkedQueueEntry<E> entry = _sentinel._nextLink;
while (!identical(entry, _sentinel)) {
@@ -510,14 +458,14 @@
if (identical(this, entry._queue)) {
next = entry._nextLink;
} else if (!identical(this, next._queue)) {
- throw new ConcurrentModificationError(this);
+ throw ConcurrentModificationError(this);
}
entry = next;
}
}
_DoubleLinkedQueueIterator<E> get iterator {
- return new _DoubleLinkedQueueIterator<E>(_sentinel);
+ return _DoubleLinkedQueueIterator<E>(_sentinel);
}
String toString() => IterableBase.iterableToFullString(this, '{', '}');
@@ -541,7 +489,7 @@
}
_DoubleLinkedQueueElement<E> elementEntry = _nextEntry;
if (!identical(_sentinel._queue, elementEntry._queue)) {
- throw new ConcurrentModificationError(_sentinel._queue);
+ throw ConcurrentModificationError(_sentinel._queue);
}
_current = elementEntry._element;
_nextEntry = elementEntry._nextLink;
@@ -551,15 +499,13 @@
E get current => _current;
}
-/**
- * List based [Queue].
- *
- * Keeps a cyclic buffer of elements, and grows to a larger buffer when
- * it fills up. This guarantees constant time peek and remove operations, and
- * amortized constant time add operations.
- *
- * The structure is efficient for any queue or stack usage.
- */
+/// List based [Queue].
+///
+/// Keeps a cyclic buffer of elements, and grows to a larger buffer when
+/// it fills up. This guarantees constant time peek and remove operations, and
+/// amortized constant time add operations.
+///
+/// The structure is efficient for any queue or stack usage.
class ListQueue<E> extends ListIterable<E> implements Queue<E> {
static const int _INITIAL_CAPACITY = 8;
List<E> _table;
@@ -567,12 +513,10 @@
int _tail;
int _modificationCount = 0;
- /**
- * Create an empty queue.
- *
- * If [initialCapacity] is given, prepare the queue for at least that many
- * elements.
- */
+ /// Create an empty queue.
+ ///
+ /// If [initialCapacity] is given, prepare the queue for at least that many
+ /// elements.
ListQueue([int initialCapacity])
: _head = 0,
_tail = 0 {
@@ -582,28 +526,26 @@
initialCapacity = _nextPowerOf2(initialCapacity);
}
assert(_isPowerOf2(initialCapacity));
- _table = new List<E>(initialCapacity);
+ _table = List<E>(initialCapacity);
}
- /**
- * Create a `ListQueue` containing all [elements].
- *
- * The elements are added to the queue, as by [addLast], in the order given by
- * `elements.iterator`.
- *
- * All the [elements] should be instances of [E].
- * The `elements` iterable itself may have any element type, so this
- * constructor can be used to down-cast a `Queue`, for example as:
- * ```dart
- * Queue<SuperType> superQueue = ...;
- * Queue<SubType> subQueue =
- * new ListQueue<SubType>.from(superQueue.whereType<SubType>());
- * ```
- */
+ /// Create a `ListQueue` containing all [elements].
+ ///
+ /// The elements are added to the queue, as by [addLast], in the order given
+ /// by `elements.iterator`.
+ ///
+ /// All the [elements] should be instances of [E].
+ /// The `elements` iterable itself may have any element type, so this
+ /// constructor can be used to down-cast a `Queue`, for example as:
+ /// ```dart
+ /// Queue<SuperType> superQueue = ...;
+ /// Queue<SubType> subQueue =
+ /// new ListQueue<SubType>.from(superQueue.whereType<SubType>());
+ /// ```
factory ListQueue.from(Iterable elements) {
if (elements is List) {
int length = elements.length;
- ListQueue<E> queue = new ListQueue<E>(length + 1);
+ ListQueue<E> queue = ListQueue<E>(length + 1);
assert(queue._table.length > length);
for (int i = 0; i < length; i++) {
queue._table[i] = elements[i];
@@ -615,7 +557,7 @@
if (elements is EfficientLengthIterable) {
capacity = elements.length;
}
- ListQueue<E> result = new ListQueue<E>(capacity);
+ ListQueue<E> result = ListQueue<E>(capacity);
for (final element in elements) {
result.addLast(element);
}
@@ -623,19 +565,17 @@
}
}
- /**
- * Create a `ListQueue` from [elements].
- *
- * The elements are added to the queue, as by [addLast], in the order given by
- * `elements.iterator`.
- */
+ /// Create a `ListQueue` from [elements].
+ ///
+ /// The elements are added to the queue, as by [addLast], in the order given
+ /// by `elements.iterator`.
factory ListQueue.of(Iterable<E> elements) =>
- new ListQueue<E>()..addAll(elements);
+ ListQueue<E>()..addAll(elements);
// Iterable interface.
Queue<R> cast<R>() => Queue.castFrom<E, R>(this);
- Iterator<E> get iterator => new _ListQueueIterator<E>(this);
+ Iterator<E> get iterator => _ListQueueIterator<E>(this);
void forEach(void f(E element)) {
int modificationCount = _modificationCount;
@@ -670,12 +610,12 @@
return _table[(_head + index) & (_table.length - 1)];
}
- List<E> toList({bool growable: true}) {
+ List<E> toList({bool growable = true}) {
List<E> list;
if (growable) {
list = <E>[]..length = length;
} else {
- list = new List<E>(length);
+ list = List<E>(length);
}
_writeToList(list);
return list;
@@ -744,22 +684,18 @@
}
}
- /**
- * Remove all elements matched by [test].
- *
- * This method is inefficient since it works by repeatedly removing single
- * elements, each of which can take linear time.
- */
+ /// Remove all elements matched by [test].
+ ///
+ /// This method is inefficient since it works by repeatedly removing single
+ /// elements, each of which can take linear time.
void removeWhere(bool test(E element)) {
_filterWhere(test, true);
}
- /**
- * Remove all elements not matched by [test].
- *
- * This method is inefficient since it works by repeatedly removing single
- * elements, each of which can take linear time.
- */
+ /// Remove all elements not matched by [test].
+ ///
+ /// This method is inefficient since it works by repeatedly removing single
+ /// elements, each of which can take linear time.
void retainWhere(bool test(E element)) {
_filterWhere(test, false);
}
@@ -809,20 +745,16 @@
// Internal helper functions.
- /**
- * Whether [number] is a power of two.
- *
- * Only works for positive numbers.
- */
+ /// Whether [number] is a power of two.
+ ///
+ /// Only works for positive numbers.
static bool _isPowerOf2(int number) => (number & (number - 1)) == 0;
- /**
- * Rounds [number] up to the nearest power of 2.
- *
- * If [number] is a power of 2 already, it is returned.
- *
- * Only works for positive numbers.
- */
+ /// Rounds [number] up to the nearest power of 2.
+ ///
+ /// If [number] is a power of 2 already, it is returned.
+ ///
+ /// Only works for positive numbers.
static int _nextPowerOf2(int number) {
assert(number > 0);
number = (number << 1) - 1;
@@ -833,14 +765,14 @@
}
}
- /** Check if the queue has been modified during iteration. */
+ /// Check if the queue has been modified during iteration.
void _checkModification(int expectedModificationCount) {
if (expectedModificationCount != _modificationCount) {
- throw new ConcurrentModificationError(this);
+ throw ConcurrentModificationError(this);
}
}
- /** Adds element at end of queue. Used by both [add] and [addAll]. */
+ /// Adds element at end of queue. Used by both [add] and [addAll].
void _add(E element) {
_table[_tail] = element;
_tail = (_tail + 1) & (_table.length - 1);
@@ -848,16 +780,14 @@
_modificationCount++;
}
- /**
- * Removes the element at [offset] into [_table].
- *
- * Removal is performed by linearly moving elements either before or after
- * [offset] by one position.
- *
- * Returns the new offset of the following element. This may be the same
- * offset or the following offset depending on how elements are moved
- * to fill the hole.
- */
+ /// Removes the element at [offset] into [_table].
+ ///
+ /// Removal is performed by linearly moving elements either before or after
+ /// [offset] by one position.
+ ///
+ /// Returns the new offset of the following element. This may be the same
+ /// offset or the following offset depending on how elements are moved
+ /// to fill the hole.
int _remove(int offset) {
int mask = _table.length - 1;
int startDistance = (offset - _head) & mask;
@@ -886,11 +816,9 @@
}
}
- /**
- * Grow the table when full.
- */
+ /// Grow the table when full.
void _grow() {
- List<E> newTable = new List<E>(_table.length * 2);
+ List<E> newTable = List<E>(_table.length * 2);
int split = _table.length - _head;
newTable.setRange(0, split, _table, _head);
newTable.setRange(split, split + _head, _table, 0);
@@ -913,7 +841,7 @@
}
}
- /** Grows the table even if it is not full. */
+ /// Grows the table even if it is not full.
void _preGrow(int newElementCount) {
assert(newElementCount >= length);
@@ -921,18 +849,16 @@
// expansion.
newElementCount += newElementCount >> 1;
int newCapacity = _nextPowerOf2(newElementCount);
- List<E> newTable = new List<E>(newCapacity);
+ List<E> newTable = List<E>(newCapacity);
_tail = _writeToList(newTable);
_table = newTable;
_head = 0;
}
}
-/**
- * Iterator for a [ListQueue].
- *
- * Considers any add or remove operation a concurrent modification.
- */
+/// Iterator for a [ListQueue].
+///
+/// Considers any add or remove operation a concurrent modification.
class _ListQueueIterator<E> implements Iterator<E> {
final ListQueue<E> _queue;
final int _end;
diff --git a/sdk/lib/collection/set.dart b/sdk/lib/collection/set.dart
index 4f21b77..7508b23 100644
--- a/sdk/lib/collection/set.dart
+++ b/sdk/lib/collection/set.dart
@@ -2,28 +2,24 @@
// 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.
-/**
- * Base implementations of [Set].
- */
+/// Base implementations of [Set].
part of dart.collection;
-/**
- * Mixin implementation of [Set].
- *
- * This class provides a base implementation of a `Set` that depends only
- * on the abstract members: [add], [contains], [lookup], [remove],
- * [iterator], [length] and [toSet].
- *
- * Some of the methods assume that `toSet` creates a modifiable set.
- * If using this mixin for an unmodifiable set,
- * where `toSet` should return an unmodifiable set,
- * it's necessary to reimplement
- * [retainAll], [union], [intersection] and [difference].
- *
- * Implementations of `Set` using this mixin should consider also implementing
- * `clear` in constant time. The default implementation works by removing every
- * element.
- */
+/// Mixin implementation of [Set].
+///
+/// This class provides a base implementation of a `Set` that depends only
+/// on the abstract members: [add], [contains], [lookup], [remove],
+/// [iterator], [length] and [toSet].
+///
+/// Some of the methods assume that `toSet` creates a modifiable set.
+/// If using this mixin for an unmodifiable set,
+/// where `toSet` should return an unmodifiable set,
+/// it's necessary to reimplement
+/// [retainAll], [union], [intersection] and [difference].
+///
+/// Implementations of `Set` using this mixin should consider also implementing
+/// `clear` in constant time. The default implementation works by removing every
+/// element.
abstract class SetMixin<E> implements Set<E> {
// This class reimplements all of [IterableMixin].
// If/when Dart mixins get more powerful, we should just create a single
@@ -49,9 +45,9 @@
Set<R> cast<R>() => Set.castFrom<E, R>(this);
Iterable<E> followedBy(Iterable<E> other) =>
- new FollowedByIterable<E>.firstEfficient(this, other);
+ FollowedByIterable<E>.firstEfficient(this, other);
- Iterable<T> whereType<T>() => new WhereTypeIterable<T>(this);
+ Iterable<T> whereType<T>() => WhereTypeIterable<T>(this);
void clear() {
removeAll(toList());
@@ -118,15 +114,15 @@
return result;
}
- List<E> toList({bool growable: true}) {
- List<E> result = growable ? (<E>[]..length = length) : new List<E>(length);
+ List<E> toList({bool growable = true}) {
+ List<E> result = growable ? (<E>[]..length = length) : List<E>(length);
int i = 0;
for (E element in this) result[i++] = element;
return result;
}
Iterable<T> map<T>(T f(E element)) =>
- new EfficientLengthMappedIterable<E, T>(this, f);
+ EfficientLengthMappedIterable<E, T>(this, f);
E get single {
if (length > 1) throw IterableElementError.tooMany();
@@ -141,10 +137,10 @@
// Copied from IterableMixin.
// Should be inherited if we had multi-level mixins.
- Iterable<E> where(bool f(E element)) => new WhereIterable<E>(this, f);
+ Iterable<E> where(bool f(E element)) => WhereIterable<E>(this, f);
Iterable<T> expand<T>(Iterable<T> f(E element)) =>
- new ExpandIterable<E, T>(this, f);
+ ExpandIterable<E, T>(this, f);
void forEach(void f(E element)) {
for (E element in this) f(element);
@@ -178,7 +174,7 @@
String join([String separator = ""]) {
Iterator<E> iterator = this.iterator;
if (!iterator.moveNext()) return "";
- StringBuffer buffer = new StringBuffer();
+ StringBuffer buffer = StringBuffer();
if (separator == null || separator == "") {
do {
buffer.write(iterator.current);
@@ -201,19 +197,19 @@
}
Iterable<E> take(int n) {
- return new TakeIterable<E>(this, n);
+ return TakeIterable<E>(this, n);
}
Iterable<E> takeWhile(bool test(E value)) {
- return new TakeWhileIterable<E>(this, test);
+ return TakeWhileIterable<E>(this, test);
}
Iterable<E> skip(int n) {
- return new SkipIterable<E>(this, n);
+ return SkipIterable<E>(this, n);
}
Iterable<E> skipWhile(bool test(E value)) {
- return new SkipWhileIterable<E>(this, test);
+ return SkipWhileIterable<E>(this, test);
}
E get first {
@@ -283,39 +279,35 @@
if (index == elementIndex) return element;
elementIndex++;
}
- throw new RangeError.index(index, this, "index", null, elementIndex);
+ throw RangeError.index(index, this, "index", null, elementIndex);
}
}
-/**
- * Base implementation of [Set].
- *
- * This class provides a base implementation of a `Set` that depends only
- * on the abstract members: [add], [contains], [lookup], [remove],
- * [iterator], [length] and [toSet].
- *
- * Some of the methods assume that `toSet` creates a modifiable set.
- * If using this base class for an unmodifiable set,
- * where `toSet` should return an unmodifiable set,
- * it's necessary to reimplement
- * [retainAll], [union], [intersection] and [difference].
- *
- * Implementations of `Set` using this base should consider also implementing
- * `clear` in constant time. The default implementation works by removing every
- * element.
- */
+/// Base implementation of [Set].
+///
+/// This class provides a base implementation of a `Set` that depends only
+/// on the abstract members: [add], [contains], [lookup], [remove],
+/// [iterator], [length] and [toSet].
+///
+/// Some of the methods assume that `toSet` creates a modifiable set.
+/// If using this base class for an unmodifiable set,
+/// where `toSet` should return an unmodifiable set,
+/// it's necessary to reimplement
+/// [retainAll], [union], [intersection] and [difference].
+///
+/// Implementations of `Set` using this base should consider also implementing
+/// `clear` in constant time. The default implementation works by removing every
+/// element.
abstract class SetBase<E> extends Object with SetMixin<E> {
- /**
- * Convert a `Set` to a string as `{each, element, as, string}`.
- *
- * Handles circular references where converting one of the elements
- * to a string ends up converting [set] to a string again.
- */
+ /// Convert a `Set` to a string as `{each, element, as, string}`.
+ ///
+ /// Handles circular references where converting one of the elements
+ /// to a string ends up converting [set] to a string again.
static String setToString(Set set) =>
IterableBase.iterableToFullString(set, '{', '}');
}
-/** Common internal implementation of some [Set] methods. */
+/// Common internal implementation of some [Set] methods.
// TODO(35548): Make this mix-in SetMixin, by adding `with SetMixin<E>`
// and removing the copied members below,
// when analyzer supports const constructors for mixin applications.
@@ -358,9 +350,9 @@
bool get isNotEmpty => length != 0;
Iterable<E> followedBy(Iterable<E> other) =>
- new FollowedByIterable<E>.firstEfficient(this, other);
+ FollowedByIterable<E>.firstEfficient(this, other);
- Iterable<T> whereType<T>() => new WhereTypeIterable<T>(this);
+ Iterable<T> whereType<T>() => WhereTypeIterable<T>(this);
void clear() {
removeAll(toList());
@@ -411,15 +403,15 @@
return toSet()..addAll(other);
}
- List<E> toList({bool growable: true}) {
- List<E> result = growable ? (<E>[]..length = length) : new List<E>(length);
+ List<E> toList({bool growable = true}) {
+ List<E> result = growable ? (<E>[]..length = length) : List<E>(length);
int i = 0;
for (E element in this) result[i++] = element;
return result;
}
Iterable<T> map<T>(T f(E element)) =>
- new EfficientLengthMappedIterable<E, T>(this, f);
+ EfficientLengthMappedIterable<E, T>(this, f);
E get single {
if (length > 1) throw IterableElementError.tooMany();
@@ -431,10 +423,10 @@
String toString() => IterableBase.iterableToFullString(this, '{', '}');
- Iterable<E> where(bool f(E element)) => new WhereIterable<E>(this, f);
+ Iterable<E> where(bool f(E element)) => WhereIterable<E>(this, f);
Iterable<T> expand<T>(Iterable<T> f(E element)) =>
- new ExpandIterable<E, T>(this, f);
+ ExpandIterable<E, T>(this, f);
void forEach(void f(E element)) {
for (E element in this) f(element);
@@ -468,7 +460,7 @@
String join([String separator = ""]) {
Iterator<E> iterator = this.iterator;
if (!iterator.moveNext()) return "";
- StringBuffer buffer = new StringBuffer();
+ StringBuffer buffer = StringBuffer();
if (separator == null || separator == "") {
do {
buffer.write(iterator.current);
@@ -491,19 +483,19 @@
}
Iterable<E> take(int n) {
- return new TakeIterable<E>(this, n);
+ return TakeIterable<E>(this, n);
}
Iterable<E> takeWhile(bool test(E value)) {
- return new TakeWhileIterable<E>(this, test);
+ return TakeWhileIterable<E>(this, test);
}
Iterable<E> skip(int n) {
- return new SkipIterable<E>(this, n);
+ return SkipIterable<E>(this, n);
}
Iterable<E> skipWhile(bool test(E value)) {
- return new SkipWhileIterable<E>(this, test);
+ return SkipWhileIterable<E>(this, test);
}
E get first {
@@ -573,11 +565,11 @@
if (index == elementIndex) return element;
elementIndex++;
}
- throw new RangeError.index(index, this, "index", null, elementIndex);
+ throw RangeError.index(index, this, "index", null, elementIndex);
}
}
-/** Class used to implement const sets. */
+/// Class used to implement const sets.
class _UnmodifiableSet<E> extends _SetBase<E> {
final Map<E, Null> _map;
diff --git a/sdk/lib/collection/splay_tree.dart b/sdk/lib/collection/splay_tree.dart
index 9856d55..5f71934 100644
--- a/sdk/lib/collection/splay_tree.dart
+++ b/sdk/lib/collection/splay_tree.dart
@@ -4,12 +4,10 @@
part of dart.collection;
-typedef bool _Predicate<T>(T value);
+typedef _Predicate<T> = bool Function(T value);
-/**
- * A node in a splay tree. It holds the sorting key and the left
- * and right children in the tree.
- */
+/// A node in a splay tree. It holds the sorting key and the left
+/// and right children in the tree.
class _SplayTreeNode<K> {
final K key;
_SplayTreeNode<K> left;
@@ -18,24 +16,20 @@
_SplayTreeNode(this.key);
}
-/**
- * A node in a splay tree based map.
- *
- * A [_SplayTreeNode] that also contains a value
- */
+/// A node in a splay tree based map.
+///
+/// A [_SplayTreeNode] that also contains a value
class _SplayTreeMapNode<K, V> extends _SplayTreeNode<K> {
V value;
_SplayTreeMapNode(K key, this.value) : super(key);
}
-/**
- * A splay tree is a self-balancing binary search tree.
- *
- * It has the additional property that recently accessed elements
- * are quick to access again.
- * It performs basic operations such as insertion, look-up and
- * removal, in O(log(n)) amortized time.
- */
+/// A splay tree is a self-balancing binary search tree.
+///
+/// It has the additional property that recently accessed elements
+/// are quick to access again.
+/// It performs basic operations such as insertion, look-up and
+/// removal, in O(log(n)) amortized time.
abstract class _SplayTree<K, Node extends _SplayTreeNode<K>> {
// The root node of the splay tree. It will contain either the last
// element inserted or the last element looked up.
@@ -49,40 +43,34 @@
// Number of elements in the splay tree.
int _count = 0;
- /**
- * Counter incremented whenever the keys in the map changes.
- *
- * Used to detect concurrent modifications.
- */
+ /// Counter incremented whenever the keys in the map changes.
+ ///
+ /// Used to detect concurrent modifications.
int _modificationCount = 0;
- /**
- * Counter incremented whenever the tree structure changes.
- *
- * Used to detect that an in-place traversal cannot use
- * cached information that relies on the tree structure.
- */
+ /// Counter incremented whenever the tree structure changes.
+ ///
+ /// Used to detect that an in-place traversal cannot use
+ /// cached information that relies on the tree structure.
int _splayCount = 0;
- /** The comparator that is used for this splay tree. */
+ /// The comparator that is used for this splay tree.
Comparator<K> get _comparator;
- /** The predicate to determine that a given object is a valid key. */
+ /// The predicate to determine that a given object is a valid key.
_Predicate get _validKey;
- /** Comparison used to compare keys. */
+ /// Comparison used to compare keys.
int _compare(K key1, K key2);
- /**
- * Perform the splay operation for the given key. Moves the node with
- * the given key to the top of the tree. If no node has the given
- * key, the last node on the search path is moved to the top of the
- * tree. This is the simplified top-down splaying algorithm from:
- * "Self-adjusting Binary Search Trees" by Sleator and Tarjan.
- *
- * Returns the result of comparing the new root of the tree to [key].
- * Returns -1 if the table is empty.
- */
+ /// Perform the splay operation for the given key. Moves the node with
+ /// the given key to the top of the tree. If no node has the given
+ /// key, the last node on the search path is moved to the top of the
+ /// tree. This is the simplified top-down splaying algorithm from:
+ /// "Self-adjusting Binary Search Trees" by Sleator and Tarjan.
+ ///
+ /// Returns the result of comparing the new root of the tree to [key].
+ /// Returns -1 if the table is empty.
int _splay(K key) {
if (_root == null) return -1;
@@ -177,12 +165,10 @@
return result;
}
- /**
- * Adds a new root node with the given [key] or [value].
- *
- * The [comp] value is the result of comparing the existing root's key
- * with key.
- */
+ /// Adds a new root node with the given [key] or [value].
+ ///
+ /// The [comp] value is the result of comparing the existing root's key
+ /// with key.
void _addNewRoot(Node node, int comp) {
_count++;
_modificationCount++;
@@ -239,34 +225,31 @@
return _dynamicCompare;
}
-/**
- * A [Map] of objects that can be ordered relative to each other.
- *
- * The map is based on a self-balancing binary tree. It allows most operations
- * in amortized logarithmic time.
- *
- * Keys of the map are compared using the `compare` function passed in
- * the constructor, both for ordering and for equality.
- * If the map contains only the key `a`, then `map.containsKey(b)`
- * will return `true` if and only if `compare(a, b) == 0`,
- * and the value of `a == b` is not even checked.
- * If the compare function is omitted, the objects are assumed to be
- * [Comparable], and are compared using their [Comparable.compareTo] method.
- * Non-comparable objects (including `null`) will not work as keys
- * in that case.
- *
- * To allow calling [operator []], [remove] or [containsKey] with objects
- * that are not supported by the `compare` function, an extra `isValidKey`
- * predicate function can be supplied. This function is tested before
- * using the `compare` function on an argument value that may not be a [K]
- * value. If omitted, the `isValidKey` function defaults to testing if the
- * value is a [K].
- */
+/// A [Map] of objects that can be ordered relative to each other.
+///
+/// The map is based on a self-balancing binary tree. It allows most operations
+/// in amortized logarithmic time.
+///
+/// Keys of the map are compared using the `compare` function passed in
+/// the constructor, both for ordering and for equality.
+/// If the map contains only the key `a`, then `map.containsKey(b)`
+/// will return `true` if and only if `compare(a, b) == 0`,
+/// and the value of `a == b` is not even checked.
+/// If the compare function is omitted, the objects are assumed to be
+/// [Comparable], and are compared using their [Comparable.compareTo] method.
+/// Non-comparable objects (including `null`) will not work as keys
+/// in that case.
+///
+/// To allow calling [operator []], [remove] or [containsKey] with objects
+/// that are not supported by the `compare` function, an extra `isValidKey`
+/// predicate function can be supplied. This function is tested before
+/// using the `compare` function on an argument value that may not be a [K]
+/// value. If omitted, the `isValidKey` function defaults to testing if the
+/// value is a [K].
class SplayTreeMap<K, V> extends _SplayTree<K, _SplayTreeMapNode<K, V>>
with MapMixin<K, V> {
_SplayTreeMapNode<K, V> _root;
- final _SplayTreeMapNode<K, V> _dummy =
- new _SplayTreeMapNode<K, V>(null, null);
+ final _SplayTreeMapNode<K, V> _dummy = _SplayTreeMapNode<K, V>(null, null);
Comparator<K> _comparator;
_Predicate _validKey;
@@ -275,65 +258,57 @@
: _comparator = compare ?? _defaultCompare<K>(),
_validKey = isValidKey ?? ((v) => v is K);
- /**
- * Creates a [SplayTreeMap] that contains all key/value pairs of [other].
- *
- * The keys must all be instances of [K] and the values of [V].
- * The [other] map itself can have any type.
- */
+ /// Creates a [SplayTreeMap] that contains all key/value pairs of [other].
+ ///
+ /// The keys must all be instances of [K] and the values of [V].
+ /// The [other] map itself can have any type.
factory SplayTreeMap.from(Map other,
[int compare(K key1, K key2), bool isValidKey(potentialKey)]) {
- SplayTreeMap<K, V> result = new SplayTreeMap<K, V>(compare, isValidKey);
+ SplayTreeMap<K, V> result = SplayTreeMap<K, V>(compare, isValidKey);
other.forEach((k, v) {
result[k] = v;
});
return result;
}
- /**
- * Creates a [SplayTreeMap] that contains all key/value pairs of [other].
- */
+ /// Creates a [SplayTreeMap] that contains all key/value pairs of [other].
factory SplayTreeMap.of(Map<K, V> other,
[int compare(K key1, K key2), bool isValidKey(potentialKey)]) =>
- new SplayTreeMap<K, V>(compare, isValidKey)..addAll(other);
+ SplayTreeMap<K, V>(compare, isValidKey)..addAll(other);
- /**
- * Creates a [SplayTreeMap] where the keys and values are computed from the
- * [iterable].
- *
- * For each element of the [iterable] this constructor computes a key/value
- * pair, by applying [key] and [value] respectively.
- *
- * The keys of the key/value pairs do not need to be unique. The last
- * occurrence of a key will simply overwrite any previous value.
- *
- * If no functions are specified for [key] and [value] the default is to
- * use the iterable value itself.
- */
+ /// Creates a [SplayTreeMap] where the keys and values are computed from the
+ /// [iterable].
+ ///
+ /// For each element of the [iterable] this constructor computes a key/value
+ /// pair, by applying [key] and [value] respectively.
+ ///
+ /// The keys of the key/value pairs do not need to be unique. The last
+ /// occurrence of a key will simply overwrite any previous value.
+ ///
+ /// If no functions are specified for [key] and [value] the default is to
+ /// use the iterable value itself.
factory SplayTreeMap.fromIterable(Iterable iterable,
{K key(element),
V value(element),
int compare(K key1, K key2),
bool isValidKey(potentialKey)}) {
- SplayTreeMap<K, V> map = new SplayTreeMap<K, V>(compare, isValidKey);
+ SplayTreeMap<K, V> map = SplayTreeMap<K, V>(compare, isValidKey);
MapBase._fillMapWithMappedIterable(map, iterable, key, value);
return map;
}
- /**
- * Creates a [SplayTreeMap] associating the given [keys] to [values].
- *
- * This constructor iterates over [keys] and [values] and maps each element of
- * [keys] to the corresponding element of [values].
- *
- * If [keys] contains the same object multiple times, the last occurrence
- * overwrites the previous value.
- *
- * It is an error if the two [Iterable]s don't have the same length.
- */
+ /// Creates a [SplayTreeMap] associating the given [keys] to [values].
+ ///
+ /// This constructor iterates over [keys] and [values] and maps each element
+ /// of [keys] to the corresponding element of [values].
+ ///
+ /// If [keys] contains the same object multiple times, the last occurrence
+ /// overwrites the previous value.
+ ///
+ /// It is an error if the two [Iterable]s don't have the same length.
factory SplayTreeMap.fromIterables(Iterable<K> keys, Iterable<V> values,
[int compare(K key1, K key2), bool isValidKey(potentialKey)]) {
- SplayTreeMap<K, V> map = new SplayTreeMap<K, V>(compare, isValidKey);
+ SplayTreeMap<K, V> map = SplayTreeMap<K, V>(compare, isValidKey);
MapBase._fillMapWithIterables(map, keys, values);
return map;
}
@@ -361,7 +336,7 @@
}
void operator []=(K key, V value) {
- if (key == null) throw new ArgumentError(key);
+ if (key == null) throw ArgumentError(key);
// Splay on the key to move the last node on the search path for
// the key to the root of the tree.
int comp = _splay(key);
@@ -369,11 +344,11 @@
_root.value = value;
return;
}
- _addNewRoot(new _SplayTreeMapNode(key, value), comp);
+ _addNewRoot(_SplayTreeMapNode(key, value), comp);
}
V putIfAbsent(K key, V ifAbsent()) {
- if (key == null) throw new ArgumentError(key);
+ if (key == null) throw ArgumentError(key);
int comp = _splay(key);
if (comp == 0) {
return _root.value;
@@ -382,14 +357,14 @@
int splayCount = _splayCount;
V value = ifAbsent();
if (modificationCount != _modificationCount) {
- throw new ConcurrentModificationError(this);
+ throw ConcurrentModificationError(this);
}
if (splayCount != _splayCount) {
comp = _splay(key);
// Key is still not there, otherwise _modificationCount would be changed.
assert(comp != 0);
}
- _addNewRoot(new _SplayTreeMapNode(key, value), comp);
+ _addNewRoot(_SplayTreeMapNode(key, value), comp);
return value;
}
@@ -406,7 +381,7 @@
bool get isNotEmpty => !isEmpty;
void forEach(void f(K key, V value)) {
- Iterator<_SplayTreeNode<K>> nodes = new _SplayTreeNodeIterator<K>(this);
+ Iterator<_SplayTreeNode<K>> nodes = _SplayTreeNodeIterator<K>(this);
while (nodes.moveNext()) {
_SplayTreeMapNode<K, V> node = nodes.current;
f(node.key, node.value);
@@ -431,7 +406,7 @@
while (node != null) {
if (node.value == value) return true;
if (initialSplayCount != _splayCount) {
- throw new ConcurrentModificationError(this);
+ throw ConcurrentModificationError(this);
}
if (node.right != null && visit(node.right)) return true;
node = node.left;
@@ -442,32 +417,26 @@
return visit(_root);
}
- Iterable<K> get keys => new _SplayTreeKeyIterable<K>(this);
+ Iterable<K> get keys => _SplayTreeKeyIterable<K>(this);
- Iterable<V> get values => new _SplayTreeValueIterable<K, V>(this);
+ Iterable<V> get values => _SplayTreeValueIterable<K, V>(this);
- /**
- * Get the first key in the map. Returns [:null:] if the map is empty.
- */
+ /// Get the first key in the map. Returns [:null:] if the map is empty.
K firstKey() {
if (_root == null) return null;
return _first.key;
}
- /**
- * Get the last key in the map. Returns [:null:] if the map is empty.
- */
+ /// Get the last key in the map. Returns [:null:] if the map is empty.
K lastKey() {
if (_root == null) return null;
return _last.key;
}
- /**
- * Get the last key in the map that is strictly smaller than [key]. Returns
- * [:null:] if no key was not found.
- */
+ /// Get the last key in the map that is strictly smaller than [key]. Returns
+ /// [:null:] if no key was not found.
K lastKeyBefore(K key) {
- if (key == null) throw new ArgumentError(key);
+ if (key == null) throw ArgumentError(key);
if (_root == null) return null;
int comp = _splay(key);
if (comp < 0) return _root.key;
@@ -479,12 +448,10 @@
return node.key;
}
- /**
- * Get the first key in the map that is strictly larger than [key]. Returns
- * [:null:] if no key was not found.
- */
+ /// Get the first key in the map that is strictly larger than [key]. Returns
+ /// [:null:] if no key was not found.
K firstKeyAfter(K key) {
- if (key == null) throw new ArgumentError(key);
+ if (key == null) throw ArgumentError(key);
if (_root == null) return null;
int comp = _splay(key);
if (comp > 0) return _root.key;
@@ -499,37 +466,32 @@
abstract class _SplayTreeIterator<K, T> implements Iterator<T> {
final _SplayTree<K, _SplayTreeNode<K>> _tree;
- /**
- * Worklist of nodes to visit.
- *
- * These nodes have been passed over on the way down in a
- * depth-first left-to-right traversal. Visiting each node,
- * and their right subtrees will visit the remainder of
- * the nodes of a full traversal.
- *
- * Only valid as long as the original tree isn't reordered.
- */
+
+ /// Worklist of nodes to visit.
+ ///
+ /// These nodes have been passed over on the way down in a
+ /// depth-first left-to-right traversal. Visiting each node,
+ /// and their right subtrees will visit the remainder of
+ /// the nodes of a full traversal.
+ ///
+ /// Only valid as long as the original tree isn't reordered.
final List<_SplayTreeNode<K>> _workList = <_SplayTreeNode<K>>[];
- /**
- * Original modification counter of [_tree].
- *
- * Incremented on [_tree] when a key is added or removed.
- * If it changes, iteration is aborted.
- *
- * Not final because some iterators may modify the tree knowingly,
- * and they update the modification count in that case.
- */
+ /// Original modification counter of [_tree].
+ ///
+ /// Incremented on [_tree] when a key is added or removed.
+ /// If it changes, iteration is aborted.
+ ///
+ /// Not final because some iterators may modify the tree knowingly,
+ /// and they update the modification count in that case.
int _modificationCount;
- /**
- * Count of splay operations on [_tree] when [_workList] was built.
- *
- * If the splay count on [_tree] increases, [_workList] becomes invalid.
- */
+ /// Count of splay operations on [_tree] when [_workList] was built.
+ ///
+ /// If the splay count on [_tree] increases, [_workList] becomes invalid.
int _splayCount;
- /** Current node. */
+ /// Current node.
_SplayTreeNode<K> _currentNode;
_SplayTreeIterator(_SplayTree<K, _SplayTreeNode<K>> tree)
@@ -565,14 +527,12 @@
}
}
- /**
- * Called when the tree structure of the tree has changed.
- *
- * This can be caused by a splay operation.
- * If the key-set changes, iteration is aborted before getting
- * here, so we know that the keys are the same as before, it's
- * only the tree that has been reordered.
- */
+ /// Called when the tree structure of the tree has changed.
+ ///
+ /// This can be caused by a splay operation.
+ /// If the key-set changes, iteration is aborted before getting
+ /// here, so we know that the keys are the same as before, it's
+ /// only the tree that has been reordered.
void _rebuildWorkList(_SplayTreeNode<K> currentNode) {
assert(_workList.isNotEmpty);
_workList.clear();
@@ -587,7 +547,7 @@
bool moveNext() {
if (_modificationCount != _tree._modificationCount) {
- throw new ConcurrentModificationError(_tree);
+ throw ConcurrentModificationError(_tree);
}
// Picks the next element in the worklist as current.
// Updates the worklist with the left-most path of the current node's
@@ -614,11 +574,10 @@
_SplayTreeKeyIterable(this._tree);
int get length => _tree._count;
bool get isEmpty => _tree._count == 0;
- Iterator<K> get iterator => new _SplayTreeKeyIterator<K>(_tree);
+ Iterator<K> get iterator => _SplayTreeKeyIterator<K>(_tree);
Set<K> toSet() {
- SplayTreeSet<K> set =
- new SplayTreeSet<K>(_tree._comparator, _tree._validKey);
+ SplayTreeSet<K> set = SplayTreeSet<K>(_tree._comparator, _tree._validKey);
set._count = _tree._count;
set._root = set._copyNode(_tree._root);
return set;
@@ -630,7 +589,7 @@
_SplayTreeValueIterable(this._map);
int get length => _map._count;
bool get isEmpty => _map._count == 0;
- Iterator<V> get iterator => new _SplayTreeValueIterator<K, V>(_map);
+ Iterator<V> get iterator => _SplayTreeValueIterator<K, V>(_map);
}
class _SplayTreeKeyIterator<K> extends _SplayTreeIterator<K, K> {
@@ -655,76 +614,70 @@
_SplayTreeNode<K> _getValue(_SplayTreeNode<K> node) => node;
}
-/**
- * A [Set] of objects that can be ordered relative to each other.
- *
- * The set is based on a self-balancing binary tree. It allows most operations
- * in amortized logarithmic time.
- *
- * Elements of the set are compared using the `compare` function passed in
- * the constructor, both for ordering and for equality.
- * If the set contains only an object `a`, then `set.contains(b)`
- * will return `true` if and only if `compare(a, b) == 0`,
- * and the value of `a == b` is not even checked.
- * If the compare function is omitted, the objects are assumed to be
- * [Comparable], and are compared using their [Comparable.compareTo] method.
- * Non-comparable objects (including `null`) will not work as an element
- * in that case.
- */
+/// A [Set] of objects that can be ordered relative to each other.
+///
+/// The set is based on a self-balancing binary tree. It allows most operations
+/// in amortized logarithmic time.
+///
+/// Elements of the set are compared using the `compare` function passed in
+/// the constructor, both for ordering and for equality.
+/// If the set contains only an object `a`, then `set.contains(b)`
+/// will return `true` if and only if `compare(a, b) == 0`,
+/// and the value of `a == b` is not even checked.
+/// If the compare function is omitted, the objects are assumed to be
+/// [Comparable], and are compared using their [Comparable.compareTo] method.
+/// Non-comparable objects (including `null`) will not work as an element
+/// in that case.
class SplayTreeSet<E> extends _SplayTree<E, _SplayTreeNode<E>>
with IterableMixin<E>, SetMixin<E> {
_SplayTreeNode<E> _root;
- final _SplayTreeNode<E> _dummy = new _SplayTreeNode<E>(null);
+ final _SplayTreeNode<E> _dummy = _SplayTreeNode<E>(null);
Comparator<E> _comparator;
_Predicate _validKey;
- /**
- * Create a new [SplayTreeSet] with the given compare function.
- *
- * If the [compare] function is omitted, it defaults to [Comparable.compare],
- * and the elements must be comparable.
- *
- * A provided `compare` function may not work on all objects. It may not even
- * work on all `E` instances.
- *
- * For operations that add elements to the set, the user is supposed to not
- * pass in objects that doesn't work with the compare function.
- *
- * The methods [contains], [remove], [lookup], [removeAll] or [retainAll]
- * are typed to accept any object(s), and the [isValidKey] test can used to
- * filter those objects before handing them to the `compare` function.
- *
- * If [isValidKey] is provided, only values satisfying `isValidKey(other)`
- * are compared using the `compare` method in the methods mentioned above.
- * If the `isValidKey` function returns false for an object, it is assumed to
- * not be in the set.
- *
- * If omitted, the `isValidKey` function defaults to checking against the
- * type parameter: `other is E`.
- */
+ /// Create a new [SplayTreeSet] with the given compare function.
+ ///
+ /// If the [compare] function is omitted, it defaults to [Comparable.compare],
+ /// and the elements must be comparable.
+ ///
+ /// A provided `compare` function may not work on all objects. It may not even
+ /// work on all `E` instances.
+ ///
+ /// For operations that add elements to the set, the user is supposed to not
+ /// pass in objects that doesn't work with the compare function.
+ ///
+ /// The methods [contains], [remove], [lookup], [removeAll] or [retainAll]
+ /// are typed to accept any object(s), and the [isValidKey] test can used to
+ /// filter those objects before handing them to the `compare` function.
+ ///
+ /// If [isValidKey] is provided, only values satisfying `isValidKey(other)`
+ /// are compared using the `compare` method in the methods mentioned above.
+ /// If the `isValidKey` function returns false for an object, it is assumed to
+ /// not be in the set.
+ ///
+ /// If omitted, the `isValidKey` function defaults to checking against the
+ /// type parameter: `other is E`.
SplayTreeSet([int compare(E key1, E key2), bool isValidKey(potentialKey)])
: _comparator = compare ?? _defaultCompare<E>(),
_validKey = isValidKey ?? ((v) => v is E);
- /**
- * Creates a [SplayTreeSet] that contains all [elements].
- *
- * The set works as if created by `new SplayTreeSet<E>(compare, isValidKey)`.
- *
- * All the [elements] should be instances of [E] and valid arguments to
- * [compare].
- * The `elements` iterable itself may have any element type, so this
- * constructor can be used to down-cast a `Set`, for example as:
- * ```dart
- * Set<SuperType> superSet = ...;
- * Set<SubType> subSet =
- * new SplayTreeSet<SubType>.from(superSet.whereType<SubType>());
- * ```
- */
+ /// Creates a [SplayTreeSet] that contains all [elements].
+ ///
+ /// The set works as if created by `new SplayTreeSet<E>(compare, isValidKey)`.
+ ///
+ /// All the [elements] should be instances of [E] and valid arguments to
+ /// [compare].
+ /// The `elements` iterable itself may have any element type, so this
+ /// constructor can be used to down-cast a `Set`, for example as:
+ /// ```dart
+ /// Set<SuperType> superSet = ...;
+ /// Set<SubType> subSet =
+ /// new SplayTreeSet<SubType>.from(superSet.whereType<SubType>());
+ /// ```
factory SplayTreeSet.from(Iterable elements,
[int compare(E key1, E key2), bool isValidKey(potentialKey)]) {
- SplayTreeSet<E> result = new SplayTreeSet<E>(compare, isValidKey);
+ SplayTreeSet<E> result = SplayTreeSet<E>(compare, isValidKey);
for (final element in elements) {
E e = element;
result.add(e);
@@ -732,26 +685,24 @@
return result;
}
- /**
- * Creates a [SplayTreeSet] from [elements].
- *
- * The set works as if created by `new SplayTreeSet<E>(compare, isValidKey)`.
- *
- * All the [elements] should be valid as arguments to the [compare] function.
- */
+ /// Creates a [SplayTreeSet] from [elements].
+ ///
+ /// The set works as if created by `new SplayTreeSet<E>(compare, isValidKey)`.
+ ///
+ /// All the [elements] should be valid as arguments to the [compare] function.
factory SplayTreeSet.of(Iterable<E> elements,
[int compare(E key1, E key2), bool isValidKey(potentialKey)]) =>
- new SplayTreeSet(compare, isValidKey)..addAll(elements);
+ SplayTreeSet(compare, isValidKey)..addAll(elements);
Set<T> _newSet<T>() =>
- new SplayTreeSet<T>((T a, T b) => _comparator(a as E, b as E), _validKey);
+ SplayTreeSet<T>((T a, T b) => _comparator(a as E, b as E), _validKey);
Set<R> cast<R>() => Set.castFrom<E, R>(this, newSet: _newSet);
int _compare(E e1, E e2) => _comparator(e1, e2);
// From Iterable.
- Iterator<E> get iterator => new _SplayTreeKeyIterator<E>(this);
+ Iterator<E> get iterator => _SplayTreeKeyIterator<E>(this);
int get length => _count;
bool get isEmpty => _root == null;
@@ -781,7 +732,7 @@
bool add(E element) {
int compare = _splay(element);
if (compare == 0) return false;
- _addNewRoot(new _SplayTreeNode(element), compare);
+ _addNewRoot(_SplayTreeNode(element), compare);
return true;
}
@@ -794,7 +745,7 @@
for (E element in elements) {
int compare = _splay(element);
if (compare != 0) {
- _addNewRoot(new _SplayTreeNode(element), compare);
+ _addNewRoot(_SplayTreeNode(element), compare);
}
}
}
@@ -807,12 +758,12 @@
void retainAll(Iterable<Object> elements) {
// Build a set with the same sense of equality as this set.
- SplayTreeSet<E> retainSet = new SplayTreeSet<E>(_comparator, _validKey);
+ SplayTreeSet<E> retainSet = SplayTreeSet<E>(_comparator, _validKey);
int modificationCount = _modificationCount;
for (Object object in elements) {
if (modificationCount != _modificationCount) {
// The iterator should not have side effects.
- throw new ConcurrentModificationError(this);
+ throw ConcurrentModificationError(this);
}
// Equivalent to this.contains(object).
if (_validKey(object) && _splay(object) == 0) {
@@ -835,7 +786,7 @@
}
Set<E> intersection(Set<Object> other) {
- Set<E> result = new SplayTreeSet<E>(_comparator, _validKey);
+ Set<E> result = SplayTreeSet<E>(_comparator, _validKey);
for (E element in this) {
if (other.contains(element)) result.add(element);
}
@@ -843,7 +794,7 @@
}
Set<E> difference(Set<Object> other) {
- Set<E> result = new SplayTreeSet<E>(_comparator, _validKey);
+ Set<E> result = SplayTreeSet<E>(_comparator, _validKey);
for (E element in this) {
if (!other.contains(element)) result.add(element);
}
@@ -855,7 +806,7 @@
}
SplayTreeSet<E> _clone() {
- var set = new SplayTreeSet<E>(_comparator, _validKey);
+ var set = SplayTreeSet<E>(_comparator, _validKey);
set._count = _count;
set._root = _copyNode(_root);
return set;
@@ -865,7 +816,7 @@
// Works on _SplayTreeMapNode as well, but only copies the keys,
_SplayTreeNode<E> _copyNode(_SplayTreeNode<E> node) {
if (node == null) return null;
- return new _SplayTreeNode<E>(node.key)
+ return _SplayTreeNode<E>(node.key)
..left = _copyNode(node.left)
..right = _copyNode(node.right);
}