| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 part of dart.collection; | 5 part of dart.collection; |
| 6 | 6 |
| 7 /** Common parts of [HashSet] and [LinkedHashSet] implementations. */ | 7 /** Common parts of [HashSet] and [LinkedHashSet] implementations. */ |
| 8 abstract class _HashSetBase<E> extends Collection<E> implements Set<E> { | 8 abstract class _HashSetBase<E> extends Iterable<E> implements Set<E> { |
| 9 // Set. | 9 // Set. |
| 10 bool isSubsetOf(Collection<E> other) { | |
| 11 // Deprecated, and using old signature. | |
| 12 Set otherSet; | |
| 13 if (other is Set) { | |
| 14 otherSet = other; | |
| 15 } else { | |
| 16 otherSet = other.toSet(); | |
| 17 } | |
| 18 return otherSet.containsAll(this); | |
| 19 } | |
| 20 | |
| 21 bool containsAll(Iterable<E> other) { | 10 bool containsAll(Iterable<E> other) { |
| 22 for (E object in other) { | 11 for (E object in other) { |
| 23 if (!this.contains(object)) return false; | 12 if (!this.contains(object)) return false; |
| 24 } | 13 } |
| 25 return true; | 14 return true; |
| 26 } | 15 } |
| 27 | 16 |
| 28 /** Create a new Set of the same type as this. */ | 17 /** Create a new Set of the same type as this. */ |
| 29 Set _newSet(); | 18 Set _newSet(); |
| 30 | 19 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 57 void retainAll(Iterable objectsToRetain) { | 46 void retainAll(Iterable objectsToRetain) { |
| 58 Set retainSet; | 47 Set retainSet; |
| 59 if (objectsToRetain is Set) { | 48 if (objectsToRetain is Set) { |
| 60 retainSet = objectsToRetain; | 49 retainSet = objectsToRetain; |
| 61 } else { | 50 } else { |
| 62 retainSet = objectsToRetain.toSet(); | 51 retainSet = objectsToRetain.toSet(); |
| 63 } | 52 } |
| 64 retainWhere(retainSet.contains); | 53 retainWhere(retainSet.contains); |
| 65 } | 54 } |
| 66 | 55 |
| 67 String toString() => Collections.collectionToString(this); | 56 String toString() => ToString.iterableToString(this); |
| 68 } | 57 } |
| 69 | 58 |
| 70 class HashSet<E> extends _HashSetBase<E> { | 59 class HashSet<E> extends _HashSetBase<E> { |
| 71 external HashSet(); | 60 external HashSet(); |
| 72 | 61 |
| 73 factory HashSet.from(Iterable<E> iterable) { | 62 factory HashSet.from(Iterable<E> iterable) { |
| 74 return new HashSet<E>()..addAll(iterable); | 63 return new HashSet<E>()..addAll(iterable); |
| 75 } | 64 } |
| 76 | 65 |
| 77 // Iterable. | 66 // Iterable. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 94 | 83 |
| 95 external void removeWhere(bool test(E element)); | 84 external void removeWhere(bool test(E element)); |
| 96 | 85 |
| 97 external void retainWhere(bool test(E element)); | 86 external void retainWhere(bool test(E element)); |
| 98 | 87 |
| 99 external void clear(); | 88 external void clear(); |
| 100 | 89 |
| 101 // Set. | 90 // Set. |
| 102 Set<E> _newSet() => new HashSet<E>(); | 91 Set<E> _newSet() => new HashSet<E>(); |
| 103 } | 92 } |
| OLD | NEW |