| 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 Collection<E> implements Set<E> { |
| 9 // Set. | 9 // Set. |
| 10 bool isSubsetOf(Collection<E> other) { | 10 bool isSubsetOf(Collection<E> other) { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 } | 44 } |
| 45 | 45 |
| 46 Set<E> difference(Set<E> other) { | 46 Set<E> difference(Set<E> other) { |
| 47 HashSet<E> result = _newSet(); | 47 HashSet<E> result = _newSet(); |
| 48 for (E element in this) { | 48 for (E element in this) { |
| 49 if (!other.contains(element)) result.add(element); | 49 if (!other.contains(element)) result.add(element); |
| 50 } | 50 } |
| 51 return result; | 51 return result; |
| 52 } | 52 } |
| 53 | 53 |
| 54 void retainAll(Iterable objectsToRetain) { |
| 55 Set retainSet; |
| 56 if (objectsToRetain is Set) { |
| 57 retainSet = objectsToRetain; |
| 58 } else { |
| 59 retainSet = objectsToRetain.toSet(); |
| 60 } |
| 61 retainWhere(retainSet.contains); |
| 62 } |
| 63 |
| 54 String toString() => Collections.collectionToString(this); | 64 String toString() => Collections.collectionToString(this); |
| 55 } | 65 } |
| 56 | 66 |
| 57 class HashSet<E> extends _HashSetBase<E> { | 67 class HashSet<E> extends _HashSetBase<E> { |
| 58 external HashSet(); | 68 external HashSet(); |
| 59 | 69 |
| 60 factory HashSet.from(Iterable<E> iterable) { | 70 factory HashSet.from(Iterable<E> iterable) { |
| 61 return new HashSet<E>()..addAll(iterable); | 71 return new HashSet<E>()..addAll(iterable); |
| 62 } | 72 } |
| 63 | 73 |
| 64 // Iterable. | 74 // Iterable. |
| 65 external Iterator<E> get iterator; | 75 external Iterator<E> get iterator; |
| 66 | 76 |
| 67 external int get length; | 77 external int get length; |
| 68 | 78 |
| 69 external bool get isEmpty; | 79 external bool get isEmpty; |
| 70 | 80 |
| 71 external bool contains(Object object); | 81 external bool contains(Object object); |
| 72 | 82 |
| 73 // Collection. | 83 // Collection. |
| 74 external void add(E element); | 84 external void add(E element); |
| 75 | 85 |
| 76 external void addAll(Iterable<E> objects); | 86 external void addAll(Iterable<E> objects); |
| 77 | 87 |
| 78 external bool remove(Object object); | 88 external bool remove(Object object); |
| 79 | 89 |
| 80 external void removeAll(Iterable objectsToRemove); | 90 external void removeAll(Iterable objectsToRemove); |
| 81 | 91 |
| 82 void retainAll(Iterable objectsToRetain) { | |
| 83 Set retainSet; | |
| 84 if (objectsToRetain is Set) { | |
| 85 retainSet = objectsToRetain; | |
| 86 } else { | |
| 87 retainSet = objectsToRetain.toSet(); | |
| 88 } | |
| 89 retainWhere(retainSet.contains); | |
| 90 } | |
| 91 | |
| 92 external void removeWhere(bool test(E element)); | 92 external void removeWhere(bool test(E element)); |
| 93 | 93 |
| 94 external void retainWhere(bool test(E element)); | 94 external void retainWhere(bool test(E element)); |
| 95 | 95 |
| 96 external void clear(); | 96 external void clear(); |
| 97 | 97 |
| 98 // Set. | 98 // Set. |
| 99 Set<E> _newSet() => new HashSet<E>(); | 99 Set<E> _newSet() => new HashSet<E>(); |
| 100 } | 100 } |
| OLD | NEW |