mirror of
https://github.com/dart-lang/sdk
synced 2024-10-02 23:59:16 +00:00
Change Set.difference API to accept Set<Object>.
Fixes #27573 BUG= http://dartbug.com/27573 R=lrn@google.com Review URL: https://codereview.chromium.org/2413233002 .
This commit is contained in:
parent
941b0c8c39
commit
6beb1fdd11
|
@ -1,4 +1,7 @@
|
|||
## 1.21.0
|
||||
### Core library changes
|
||||
|
||||
* `dart:core`: `Set.difference` now takes a `Set<Object>` as argument.
|
||||
|
||||
### Language
|
||||
|
||||
|
|
|
@ -261,7 +261,7 @@ class DebugSet<E> extends DebugIterable<E> implements Set<E> {
|
|||
|
||||
Set<E> union(Set<E> other) => set.union(other);
|
||||
|
||||
Set<E> difference(Set<E> other) => set.difference(other);
|
||||
Set<E> difference(Set<Object> other) => set.difference(other);
|
||||
|
||||
void clear() => set.clear();
|
||||
|
||||
|
|
|
@ -101,7 +101,7 @@ class ExpensiveSet<E> extends IterableBase<E> implements Set<E> {
|
|||
return _newSet()..addAll(this)..addAll(other);
|
||||
}
|
||||
|
||||
Set<E> difference(Set<E> other) {
|
||||
Set<E> difference(Set<Object> other) {
|
||||
Set<E> result = _newSet();
|
||||
for (E element in this) {
|
||||
if (!other.contains(element)) result.add(element);
|
||||
|
|
|
@ -32,7 +32,7 @@ class ImmutableEmptySet<E> extends IterableBase<E> implements Set<E> {
|
|||
|
||||
Set<E> union(Set<E> other) => new Set.from(other);
|
||||
Set<E> intersection(Set<E> other) => this;
|
||||
Set<E> difference(Set<E> other) => this;
|
||||
Set<E> difference(Set<Object> other) => this;
|
||||
Set<E> toSet() => new Set();
|
||||
}
|
||||
|
||||
|
|
|
@ -250,7 +250,7 @@ class Setlet<E> extends IterableBase<E> implements Set<E> {
|
|||
Setlet<E> intersection(Set<E> other) =>
|
||||
new Setlet<E>.from(this.where((e) => other.contains(e)));
|
||||
|
||||
Setlet<E> difference(Set<E> other) =>
|
||||
Setlet<E> difference(Set<Object> other) =>
|
||||
new Setlet<E>.from(this.where((e) => !other.contains(e)));
|
||||
|
||||
Setlet<E> toSet() {
|
||||
|
|
|
@ -185,7 +185,7 @@ abstract class Set<E> extends Iterable<E> implements EfficientLength {
|
|||
* That is, the returned set contains all the elements of this [Set] that
|
||||
* are not elements of [other] according to `other.contains`.
|
||||
*/
|
||||
Set<E> difference(Set<E> other);
|
||||
Set<E> difference(Set<Object> other);
|
||||
|
||||
/**
|
||||
* Removes all elements in the set.
|
||||
|
|
|
@ -166,6 +166,17 @@ void testInts(Set create()) {
|
|||
}
|
||||
Expect.isTrue(twice.difference(thrice).difference(twice).isEmpty);
|
||||
|
||||
// Test Set.difference with non-element type.
|
||||
Set diffSet = create()..addAll([0, 1, 2, 499, 999]);
|
||||
Set<Object> objectSet = new Set<Object>();
|
||||
objectSet.add("foo");
|
||||
objectSet.add(499);
|
||||
Set diffResult = diffSet.difference(objectSet);
|
||||
Expect.equals(4, diffResult.length);
|
||||
for (int value in [0, 1, 2, 999]) {
|
||||
Expect.isTrue(diffResult.contains(value));
|
||||
}
|
||||
|
||||
// Test Set.addAll.
|
||||
List list = new List(10);
|
||||
for (int i = 0; i < 10; i++) {
|
||||
|
|
Loading…
Reference in a new issue