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

Unified Diff: lib/src/wrappers.dart

Issue 1638163002: Modernize the package's style. (Closed) Base URL: git@github.com:dart-lang/collection@master
Patch Set: Code review changes Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/src/utils.dart ('k') | lib/wrappers.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/wrappers.dart
diff --git a/lib/wrappers.dart b/lib/src/wrappers.dart
similarity index 63%
copy from lib/wrappers.dart
copy to lib/src/wrappers.dart
index 30c736edf7e93200c29371089c1eed835d96e224..ee03b5f945d72ce8d0e6b834e80a8f5fcbfd9f38 100644
--- a/lib/wrappers.dart
+++ b/lib/src/wrappers.dart
@@ -2,29 +2,15 @@
// 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.
-/**
- * Delegating wrappers for [Iterable], [List], [Set], [Queue] and [Map].
- *
- * Also adds unmodifiable views for `Set` and `Map`, and a fixed length
- * view for `List`. The unmodifiable list view from `dart:collection` is
- * exported as well, just for completeness.
- */
-library dart.pkg.collection.wrappers;
-
import "dart:collection";
-import "dart:math" show Random;
-
-import "src/unmodifiable_wrappers.dart";
+import "dart:math" as math;
-export "src/canonicalized_map.dart";
-export "src/unmodifiable_wrappers.dart";
+import "unmodifiable_wrappers.dart";
-/**
- * A base class for delegating iterables.
- *
- * Subclasses can provide a [_base] that should be delegated to. Unlike
- * [DelegatingIterable], this allows the base to be created on demand.
- */
+/// A base class for delegating iterables.
+///
+/// Subclasses can provide a [_base] that should be delegated to. Unlike
+/// [DelegatingIterable], this allows the base to be created on demand.
abstract class _DelegatingIterableBase<E> implements Iterable<E> {
Iterable<E> get _base;
@@ -90,30 +76,24 @@ abstract class _DelegatingIterableBase<E> implements Iterable<E> {
String toString() => _base.toString();
}
-/**
- * Creates an [Iterable] that delegates all operations to a base iterable.
- *
- * This class can be used hide non-`Iterable` methods of an iterable object,
- * or it can be extended to add extra functionality on top of an existing
- * iterable object.
- */
+/// Creates an [Iterable] that delegates all operations to a base iterable.
+///
+/// This class can be used hide non-`Iterable` methods of an iterable object,
+/// or it can be extended to add extra functionality on top of an existing
+/// iterable object.
class DelegatingIterable<E> extends _DelegatingIterableBase<E> {
final Iterable<E> _base;
- /**
- * Create a wrapper that forwards operations to [base].
- */
+ /// Create a wrapper that forwards operations to [base].
const DelegatingIterable(Iterable<E> base) : _base = base;
}
-/**
- * Creates a [List] that delegates all operations to a base list.
- *
- * This class can be used hide non-`List` methods of a list object,
- * or it can be extended to add extra functionality on top of an existing
- * list object.
- */
+/// Creates a [List] that delegates all operations to a base list.
+///
+/// This class can be used hide non-`List` methods of a list object,
+/// or it can be extended to add extra functionality on top of an existing
+/// list object.
class DelegatingList<E> extends DelegatingIterable<E> implements List<E> {
const DelegatingList(List<E> base) : super(base);
@@ -194,7 +174,7 @@ class DelegatingList<E> extends DelegatingIterable<E> implements List<E> {
_listBase.setRange(start, end, iterable, skipCount);
}
- void shuffle([Random random]) {
+ void shuffle([math.Random random]) {
_listBase.shuffle(random);
}
@@ -206,13 +186,11 @@ class DelegatingList<E> extends DelegatingIterable<E> implements List<E> {
}
-/**
- * Creates a [Set] that delegates all operations to a base set.
- *
- * This class can be used hide non-`Set` methods of a set object,
- * or it can be extended to add extra functionality on top of an existing
- * set object.
- */
+/// Creates a [Set] that delegates all operations to a base set.
+///
+/// This class can be used hide non-`Set` methods of a set object,
+/// or it can be extended to add extra functionality on top of an existing
+/// set object.
class DelegatingSet<E> extends DelegatingIterable<E> implements Set<E> {
const DelegatingSet(Set<E> base) : super(base);
@@ -259,13 +237,11 @@ class DelegatingSet<E> extends DelegatingIterable<E> implements Set<E> {
Set<E> toSet() => new DelegatingSet<E>(_setBase.toSet());
}
-/**
- * Creates a [Queue] that delegates all operations to a base queue.
- *
- * This class can be used hide non-`Queue` methods of a queue object,
- * or it can be extended to add extra functionality on top of an existing
- * queue object.
- */
+/// Creates a [Queue] that delegates all operations to a base queue.
+///
+/// This class can be used hide non-`Queue` methods of a queue object,
+/// or it can be extended to add extra functionality on top of an existing
+/// queue object.
class DelegatingQueue<E> extends DelegatingIterable<E> implements Queue<E> {
const DelegatingQueue(Queue<E> queue) : super(queue);
@@ -302,13 +278,11 @@ class DelegatingQueue<E> extends DelegatingIterable<E> implements Queue<E> {
E removeLast() => _baseQueue.removeLast();
}
-/**
- * Creates a [Map] that delegates all operations to a base map.
- *
- * This class can be used hide non-`Map` methods of an object that extends
- * `Map`, or it can be extended to add extra functionality on top of an existing
- * map object.
- */
+/// Creates a [Map] that delegates all operations to a base map.
+///
+/// This class can be used hide non-`Map` methods of an object that extends
+/// `Map`, or it can be extended to add extra functionality on top of an
+/// existing map object.
class DelegatingMap<K, V> implements Map<K, V> {
final Map<K, V> _base;
@@ -353,17 +327,15 @@ class DelegatingMap<K, V> implements Map<K, V> {
String toString() => _base.toString();
}
-/**
- * An unmodifiable [Set] view of the keys of a [Map].
- *
- * The set delegates all operations to the underlying map.
- *
- * A `Map` can only contain each key once, so its keys can always
- * be viewed as a `Set` without any loss, even if the [Map.keys]
- * getter only shows an [Iterable] view of the keys.
- *
- * Note that [lookup] is not supported for this set.
- */
+/// An unmodifiable [Set] view of the keys of a [Map].
+///
+/// The set delegates all operations to the underlying map.
+///
+/// A `Map` can only contain each key once, so its keys can always
+/// be viewed as a `Set` without any loss, even if the [Map.keys]
+/// getter only shows an [Iterable] view of the keys.
+///
+/// Note that [lookup] is not supported for this set.
class MapKeySet<E> extends _DelegatingIterableBase<E>
with UnmodifiableSetMixin<E> {
final Map<E, dynamic> _baseMap;
@@ -384,82 +356,70 @@ class MapKeySet<E> extends _DelegatingIterableBase<E>
bool containsAll(Iterable<Object> other) => other.every(contains);
- /**
- * Returns a new set with the the elements of [this] that are not in [other].
- *
- * That is, the returned set contains all the elements of this [Set] that are
- * not elements of [other] according to `other.contains`.
- *
- * Note that the returned set will use the default equality operation, which
- * may be different than the equality operation [this] uses.
- */
+ /// Returns a new set with the the elements of [this] that are not in [other].
+ ///
+ /// That is, the returned set contains all the elements of this [Set] that are
+ /// not elements of [other] according to `other.contains`.
+ ///
+ /// Note that the returned set will use the default equality operation, which
+ /// may be different than the equality operation [this] uses.
Set<E> difference(Set<E> other) =>
where((element) => !other.contains(element)).toSet();
- /**
- * Returns a new set which is the intersection between [this] and [other].
- *
- * That is, the returned set contains all the elements of this [Set] that are
- * also elements of [other] according to `other.contains`.
- *
- * Note that the returned set will use the default equality operation, which
- * may be different than the equality operation [this] uses.
- */
+ /// Returns a new set which is the intersection between [this] and [other].
+ ///
+ /// That is, the returned set contains all the elements of this [Set] that are
+ /// also elements of [other] according to `other.contains`.
+ ///
+ /// Note that the returned set will use the default equality operation, which
+ /// may be different than the equality operation [this] uses.
Set<E> intersection(Set<Object> other) => where(other.contains).toSet();
- /**
- * Throws an [UnsupportedError] since there's no corresponding method for
- * [Map]s.
- */
+ /// Throws an [UnsupportedError] since there's no corresponding method for
+ /// [Map]s.
E lookup(E element) => throw new UnsupportedError(
"MapKeySet doesn't support lookup().");
- /**
- * Returns a new set which contains all the elements of [this] and [other].
- *
- * That is, the returned set contains all the elements of this [Set] and all
- * the elements of [other].
- *
- * Note that the returned set will use the default equality operation, which
- * may be different than the equality operation [this] uses.
- */
+ /// Returns a new set which contains all the elements of [this] and [other].
+ ///
+ /// That is, the returned set contains all the elements of this [Set] and all
+ /// the elements of [other].
+ ///
+ /// Note that the returned set will use the default equality operation, which
+ /// may be different than the equality operation [this] uses.
Set<E> union(Set<E> other) => toSet()..addAll(other);
}
-/**
- * Creates a modifiable [Set] view of the values of a [Map].
- *
- * The `Set` view assumes that the keys of the `Map` can be uniquely determined
- * from the values. The `keyForValue` function passed to the constructor finds
- * the key for a single value. The `keyForValue` function should be consistent
- * with equality. If `value1 == value2` then `keyForValue(value1)` and
- * `keyForValue(value2)` should be considered equal keys by the underlying map,
- * and vice versa.
- *
- * Modifying the set will modify the underlying map based on the key returned by
- * `keyForValue`.
- *
- * If the `Map` contents are not compatible with the `keyForValue` function, the
- * set will not work consistently, and may give meaningless responses or do
- * inconsistent updates.
- *
- * This set can, for example, be used on a map from database record IDs to the
- * records. It exposes the records as a set, and allows for writing both
- * `recordSet.add(databaseRecord)` and `recordMap[id]`.
- *
- * Effectively, the map will act as a kind of index for the set.
- */
+/// Creates a modifiable [Set] view of the values of a [Map].
+///
+/// The `Set` view assumes that the keys of the `Map` can be uniquely determined
+/// from the values. The `keyForValue` function passed to the constructor finds
+/// the key for a single value. The `keyForValue` function should be consistent
+/// with equality. If `value1 == value2` then `keyForValue(value1)` and
+/// `keyForValue(value2)` should be considered equal keys by the underlying map,
+/// and vice versa.
+///
+/// Modifying the set will modify the underlying map based on the key returned
+/// by `keyForValue`.
+///
+/// If the `Map` contents are not compatible with the `keyForValue` function,
+/// the set will not work consistently, and may give meaningless responses or do
+/// inconsistent updates.
+///
+/// This set can, for example, be used on a map from database record IDs to the
+/// records. It exposes the records as a set, and allows for writing both
+/// `recordSet.add(databaseRecord)` and `recordMap[id]`.
+///
+/// Effectively, the map will act as a kind of index for the set.
class MapValueSet<K, V> extends _DelegatingIterableBase<V> implements Set<V> {
final Map<K, V> _baseMap;
final Function _keyForValue;
- /**
- * Creates a new [MapValueSet] based on [base].
- *
- * [keyForValue] returns the key in the map that should be associated with the
- * given value. The set's notion of equality is identical to the equality of
- * the return values of [keyForValue].
- */
+ /// Creates a new [MapValueSet] based on [base].
+ ///
+ /// [keyForValue] returns the key in the map that should be associated with
+ /// the given value. The set's notion of equality is identical to the equality
+ /// of the return values of [keyForValue].
MapValueSet(Map<K, V> base, K keyForValue(V value))
: _baseMap = base,
_keyForValue = keyForValue;
@@ -495,27 +455,23 @@ class MapValueSet<K, V> extends _DelegatingIterableBase<V> implements Set<V> {
bool containsAll(Iterable<Object> other) => other.every(contains);
- /**
- * Returns a new set with the the elements of [this] that are not in [other].
- *
- * That is, the returned set contains all the elements of this [Set] that are
- * not elements of [other] according to `other.contains`.
- *
- * Note that the returned set will use the default equality operation, which
- * may be different than the equality operation [this] uses.
- */
+ /// Returns a new set with the the elements of [this] that are not in [other].
+ ///
+ /// That is, the returned set contains all the elements of this [Set] that are
+ /// not elements of [other] according to `other.contains`.
+ ///
+ /// Note that the returned set will use the default equality operation, which
+ /// may be different than the equality operation [this] uses.
Set<V> difference(Set<V> other) =>
where((element) => !other.contains(element)).toSet();
- /**
- * Returns a new set which is the intersection between [this] and [other].
- *
- * That is, the returned set contains all the elements of this [Set] that are
- * also elements of [other] according to `other.contains`.
- *
- * Note that the returned set will use the default equality operation, which
- * may be different than the equality operation [this] uses.
- */
+ /// Returns a new set which is the intersection between [this] and [other].
+ ///
+ /// That is, the returned set contains all the elements of this [Set] that are
+ /// also elements of [other] according to `other.contains`.
+ ///
+ /// Note that the returned set will use the default equality operation, which
+ /// may be different than the equality operation [this] uses.
Set<V> intersection(Set<Object> other) => where(other.contains).toSet();
V lookup(Object element) => _baseMap[_keyForValue(element)];
@@ -557,14 +513,12 @@ class MapValueSet<K, V> extends _DelegatingIterableBase<V> implements Set<V> {
void retainWhere(bool test(V element)) =>
removeWhere((element) => !test(element));
- /**
- * Returns a new set which contains all the elements of [this] and [other].
- *
- * That is, the returned set contains all the elements of this [Set] and all
- * the elements of [other].
- *
- * Note that the returned set will use the default equality operation, which
- * may be different than the equality operation [this] uses.
- */
+ /// Returns a new set which contains all the elements of [this] and [other].
+ ///
+ /// That is, the returned set contains all the elements of this [Set] and all
+ /// the elements of [other].
+ ///
+ /// Note that the returned set will use the default equality operation, which
+ /// may be different than the equality operation [this] uses.
Set<V> union(Set<V> other) => toSet()..addAll(other);
}
« no previous file with comments | « lib/src/utils.dart ('k') | lib/wrappers.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698