Deprecate Set.isSubsetOf, make Set.containsAll accept iterable.

Review URL: https://codereview.chromium.org//12838002

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@19985 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
lrn@google.com 2013-03-14 07:12:16 +00:00
parent e0e9db9398
commit 067a55370a
8 changed files with 43 additions and 33 deletions

View file

@ -382,15 +382,13 @@ class IterableMixinWorkaround {
return new ListMapView(l);
}
static bool isSubsetOfSet(Set set, Set other) {
if (set.length > other.length) return false;
for (var element in set) {
if (!other.contains(element)) return false;
static bool setContainsAll(Set set, Iterable other) {
for (var element in other) {
if (!set.contains(element)) return false;
}
return true;
}
static Set setIntersection(Set set, Set other, Set result) {
Set smaller;
Set larger;

View file

@ -86,12 +86,19 @@ class HashSet<E> extends Collection<E> implements Set<E> {
}
// Set.
bool isSubsetOf(Set<E> other) {
return IterableMixinWorkaround.isSubsetOfSet(this, other);
bool isSubsetOf(Collection<E> other) {
// Deprecated, and using old signature.
Set otherSet;
if (other is Set) {
otherSet = other;
} else {
otherSet = other.toSet();
}
return IterableMixinWorkaround.setContainsAll(otherSet, this);
}
bool containsAll(Set<E> other) {
return IterableMixinWorkaround.isSubsetOfSet(other, this);
bool containsAll(Iterable<E> other) {
return IterableMixinWorkaround.setContainsAll(this, other);
}
Set<E> intersection(Set<E> other) {

View file

@ -128,12 +128,19 @@ class LinkedHashSet<E> extends Collection<E> implements Set<E> {
}
// Set.
bool isSubsetOf(Set<E> other) {
return IterableMixinWorkaround.isSubsetOfSet(this, other);
bool isSubsetOf(Collection<E> other) {
// Deprecated, and using old signature.
Set otherSet;
if (other is Set) {
otherSet = other;
} else {
otherSet = other.toSet();
}
return IterableMixinWorkaround.setContainsAll(otherSet, this);
}
bool containsAll(Set<E> other) {
return IterableMixinWorkaround.isSubsetOfSet(other, this);
bool containsAll(Iterable<E> other) {
return IterableMixinWorkaround.setContainsAll(this, other);
}
Set<E> intersection(Set<E> other) {

View file

@ -36,13 +36,17 @@ abstract class Set<E> extends Collection<E> {
/**
* Returns true if [other] contains all the elements of this Set.
*
* *Deprecated*. Use `other.containsAll(thisSet)` instead if [other]
* is a Set, and convert `other` to a Set if it isn't.
*/
bool isSubsetOf(Set<E> other);
@deprecated
bool isSubsetOf(Iterable<E> other);
/**
* Returns true if this Set contains all the elements of [other].
*/
bool containsAll(Set<E> other);
bool containsAll(Iterable<E> other);
/**
* Returns a new set which is the intersection between this set and [other].

View file

@ -35264,6 +35264,7 @@ class _Utils {
static window() native "Utils_window";
static print(String message) native "Utils_print";
static forwardingPrint(String message) native "Utils_forwardingPrint";
static SendPort spawnDomFunctionImpl(Function topLevelFunction) native "Utils_spawnDomFunction";
static int _getNewIsolateId() native "Utils_getNewIsolateId";
static bool shadowRootSupported(Document document) native "Utils_shadowRootSupported";
@ -35343,3 +35344,5 @@ get _printClosure => (s) {
_Utils.print(s);
}
};
final _forwardingPrintClosure = _Utils.forwardingPrint;

View file

@ -114,8 +114,6 @@ LibTest/core/Set/every_A01_t03: Fail # issue 390
LibTest/core/Set/forEach_A01_t05: Fail # issue 390
LibTest/core/Set/intersection_A01_t01: Fail # issue 390
LibTest/core/Set/intersection_A01_t02: Pass # issue 390
LibTest/core/Set/isSubsetOf_A01_t01: Fail # issue 390
LibTest/core/Set/isSubsetOf_A01_t02: Fail # issue 390
LibTest/core/Set/removeAll_A01_t01: Fail # issue 390
LibTest/core/Set/remove_A01_t01: Fail # issue 390
LibTest/core/Set/remove_A01_t03: Fail # issue 390

View file

@ -651,22 +651,21 @@ LibTest/isolate/SendPort/call_A01_t01: Fail # Future is in async library. co19 i
LibTest/core/Set/add_A01_t06: Fail # issue 390
LibTest/core/Set/containsAll_A01_t01: Fail # issue 390
LibTest/core/Set/containsAll_A01_t02: Pass # issue 390
LibTest/core/Set/every_A01_t01: Fail # issue 390
LibTest/core/Set/every_A01_t03: Fail # issue 390
LibTest/core/Set/forEach_A01_t05: Fail # issue 390
LibTest/core/Set/intersection_A01_t01: Fail # issue 390
LibTest/core/Set/intersection_A01_t02: Fail # issue 390
LibTest/core/Set/intersection_A01_t03: Fail # issue 390
LibTest/core/Set/intersection_A03_t01: Pass # issue 390
LibTest/core/Set/isSubsetOf_A01_t01: Fail # issue 390
LibTest/core/Set/isSubsetOf_A01_t02: Pass # issue 390
LibTest/core/Set/removeAll_A01_t01: Fail # issue 390
LibTest/core/Set/remove_A01_t01: Fail # issue 390
LibTest/core/Set/remove_A01_t03: Fail # issue 390
# Issues with co19 test suite in unchecked mode.
[ $compiler == dart2js && $unchecked ]
LibTest/core/Set/containsAll_A01_t02: Fail # Doesn't expect null to be allowed in Set or Map keys (issue 377). Passes in checked mode due to Issue 390.
LibTest/core/Set/intersection_A03_t01: Fail # Doesn't expect null to be allowed in Set or Map keys (issue 377). Passes in checked mode due to Issue 390.
LibTest/core/Future/chain_A02_t05: Fail # Future is in async library. co19 issue 367
LibTest/core/Future/transform_A02_t04: Fail # Future is in async library. co19 issue 367
@ -869,11 +868,9 @@ LibTest/core/Map/remove_A01_t02: Fail # Doesn't expect null to be allowed in Set
LibTest/core/Set/add_A01_t02: Fail # Doesn't expect null to be allowed in Set or Map keys (issue 377).
LibTest/core/Set/addAll_A01_t02: Fail # Doesn't expect null to be allowed in Set or Map keys (issue 377).
LibTest/core/Set/contains_A01_t02: Fail # Doesn't expect null to be allowed in Set or Map keys (issue 377).
LibTest/core/Set/containsAll_A01_t02: Fail # Doesn't expect null to be allowed in Set or Map keys (issue 377).
LibTest/core/Set/intersection_A03_t01: Fail # Doesn't expect null to be allowed in Set or Map keys (issue 377).
LibTest/core/Set/isSubsetOf_A01_t02: Fail # Doesn't expect null to be allowed in Set or Map keys (issue 377).
LibTest/core/Set/remove_A01_t02: Fail # Doesn't expect null to be allowed in Set or Map keys (issue 377).
LibTest/core/Set/removeAll_A01_t02: Fail # Doesn't expect null to be allowed in Set or Map keys (issue 377).
LibTest/core/Set/isSubsetOf_A01_t02: Fail # Doesn't expect null to be allowed in Set or Map keys (issue 377).
LibTest/core/Map/forEach_A01_t07: Fail # Doesn't expect concurrent modification error (issue 376).

View file

@ -525,13 +525,9 @@ LibTest/core/Map/remove_A01_t02: Fail # Doesn't expect null to be allowed in Set
LibTest/core/Set/add_A01_t02: Fail # Doesn't expect null to be allowed in Set or Map keys (issue 377).
LibTest/core/Set/addAll_A01_t02: Fail # Doesn't expect null to be allowed in Set or Map keys (issue 377).
LibTest/core/Set/contains_A01_t02: Fail # Doesn't expect null to be allowed in Set or Map keys (issue 377).
LibTest/core/Set/containsAll_A01_t02: Fail # Doesn't expect null to be allowed in Set or Map keys (issue 377).
LibTest/core/Set/intersection_A03_t01: Fail # Doesn't expect null to be allowed in Set or Map keys (issue 377).
LibTest/core/Set/isSubsetOf_A01_t02: Fail # Doesn't expect null to be allowed in Set or Map keys (issue 377).
LibTest/core/Set/remove_A01_t02: Fail # Doesn't expect null to be allowed in Set or Map keys (issue 377).
LibTest/core/Set/removeAll_A01_t02: Fail # Doesn't expect null to be allowed in Set or Map keys (issue 377).
LibTest/core/Map/forEach_A01_t07: Fail # Doesn't expect concurrent modification error (issue 376).
LibTest/core/Set/isSubsetOf_A01_t02: Fail # Doesn't expect null to be allowed in Set or Map keys (issue 377).
LibTest/core/String/charCodes_A01_t01: Fail # Deprecated string members removed (issue 382).
LibTest/core/String/charCodeAt_A02_t01: Fail # Deprecated string members removed (issue 382).
@ -610,20 +606,20 @@ Language/14_Types/4_Interface_Types_A08_t06: Fail # Moved collection classes fro
LibTest/core/Set/add_A01_t06: Fail # issue 390
LibTest/core/Set/containsAll_A01_t01: Fail # issue 390
LibTest/core/Set/containsAll_A01_t02: Pass # issue 390
LibTest/core/Set/every_A01_t01: Fail # issue 390
LibTest/core/Set/every_A01_t03: Fail # issue 390
LibTest/core/Set/forEach_A01_t05: Fail # issue 390
LibTest/core/Set/intersection_A01_t01: Fail # issue 390
LibTest/core/Set/intersection_A01_t02: Fail # issue 390
LibTest/core/Set/intersection_A01_t03: Fail # issue 390
LibTest/core/Set/intersection_A03_t01: Pass # issue 390
LibTest/core/Set/isSubsetOf_A01_t01: Fail # issue 390
LibTest/core/Set/isSubsetOf_A01_t02: Pass # issue 390
LibTest/core/Set/removeAll_A01_t01: Fail # issue 390
LibTest/core/Set/remove_A01_t01: Fail # issue 390
LibTest/core/Set/remove_A01_t03: Fail # issue 390
[ $compiler == none && $runtime == vm && $unchecked ]
LibTest/core/Set/containsAll_A01_t02: Fail # Doesn't expect null to be allowed in Set or Map keys (issue 377). Succeedes in checked mode due to Issue 390.
LibTest/core/Set/intersection_A03_t01: Fail # Doesn't expect null to be allowed in Set or Map keys (issue 377). Succeedes in checked mode due to Issue 390.
[ $compiler == none && $arch == simarm ]
*: Skip