| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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.core; | 5 part of dart.core; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * A collection of objects in which each object can occur only once. | 8 * A collection of objects in which each object can occur only once. |
| 9 * | 9 * |
| 10 * That is, for each object of the element type, the object is either considered | 10 * That is, for each object of the element type, the object is either considered |
| 11 * to be in the set, or to _not_ be in the set. | 11 * to be in the set, or to _not_ be in the set. |
| 12 * | 12 * |
| 13 * Set implementations may consider some elements indistinguishable. These | 13 * Set implementations may consider some elements indistinguishable. These |
| 14 * elements are treated as being the same for any operation on the set. | 14 * elements are treated as being the same for any operation on the set. |
| 15 * | 15 * |
| 16 * The default `Set` implementation, [LinkedHashSet], considers objects | 16 * The default [Set] implementation, [LinkedHashSet], considers objects |
| 17 * indistinguishable if they are equal with regard to [Object.operator==]. | 17 * indistinguishable if they are equal with regard to |
| 18 * operator [Object.==]. |
| 18 * | 19 * |
| 19 * Sets may be either ordered or unordered. [HashSet] is unordered and | 20 * Sets may be either ordered or unordered. [HashSet] is unordered and |
| 20 * doesn't guarantee anything about the order that elements are accessed in by | 21 * doesn't guarantee anything about the order that elements are accessed in by |
| 21 * iteration. [LinkedHashSet] iterates in the insertion order of its elements. | 22 * iteration. [LinkedHashSet] iterates in the insertion order of its elements. |
| 22 * | 23 * |
| 23 * It is generally not allowed to modify the set (add or remove elements) while | 24 * It is generally not allowed to modify the set (add or remove elements) while |
| 24 * an operation on the set is being performed, for example during a call to | 25 * an operation on the set is being performed, for example during a call to |
| 25 * [forEach] or [containsAll]. Nor is it allowed to modify the set while | 26 * [forEach] or [containsAll]. Nor is it allowed to modify the set while |
| 26 * iterating either the set itself or any `Iterable` that is backed by the set, | 27 * iterating either the set itself or any [Iterable] that is backed by the set, |
| 27 * such as the ones returned by methods like [where] and [map]. | 28 * such as the ones returned by methods like [where] and [map]. |
| 28 */ | 29 */ |
| 29 abstract class Set<E> extends IterableBase<E> implements EfficientLength { | 30 abstract class Set<E> extends IterableBase<E> implements EfficientLength { |
| 30 /** | 31 /** |
| 31 * Creates an empty [Set]. | 32 * Creates an empty [Set]. |
| 32 * | 33 * |
| 33 * The created `Set` is a [LinkedHashSet]. As such, it considers elements that | 34 * The created [Set] is a [LinkedHashSet]. As such, it considers elements that |
| 34 * are equal (using `==`) to be indistinguishable, and requires them to | 35 * are equal (using [==]) to be indistinguishable, and requires them to |
| 35 * have a compatible [Object.hashCode] implementation. | 36 * have a compatible [Object.hashCode] implementation. |
| 36 */ | 37 */ |
| 37 factory Set() = LinkedHashSet<E>; | 38 factory Set() = LinkedHashSet<E>; |
| 38 | 39 |
| 39 /** | 40 /** |
| 40 * Creates an empty identity [Set]. | 41 * Creates an empty identity [Set]. |
| 41 * | 42 * |
| 42 * The created `Set` is a [LinkedHashSet] that uses identity as equality | 43 * The created [Set] is a [LinkedHashSet] that uses identity as equality |
| 43 * relation. | 44 * relation. |
| 44 */ | 45 */ |
| 45 factory Set.identity() = LinkedHashSet<E>.identity; | 46 factory Set.identity() = LinkedHashSet<E>.identity; |
| 46 | 47 |
| 47 /** | 48 /** |
| 48 * Creates a [Set] that contains all elements of [other]. | 49 * Creates a [Set] that contains all elements of [other]. |
| 49 * | 50 * |
| 50 * The created `Set` is a [LinkedHashSet]. As such, it considers elements that | 51 * The created [Set] is a [LinkedHashSet]. As such, it considers elements that |
| 51 * are equal (using `==`) to be undistinguishable, and requires them to | 52 * are equal (using [==]) to be undistinguishable, and requires them to |
| 52 * have a compatible [Object.hashCode] implementation. | 53 * have a compatible [Object.hashCode] implementation. |
| 53 */ | 54 */ |
| 54 factory Set.from(Iterable<E> other) = LinkedHashSet<E>.from; | 55 factory Set.from(Iterable<E> other) = LinkedHashSet<E>.from; |
| 55 | 56 |
| 56 /** | 57 /** |
| 57 * Returns true if [value] is in the set. | 58 * Returns true if [value] is in the set. |
| 58 */ | 59 */ |
| 59 bool contains(Object value); | 60 bool contains(Object value); |
| 60 | 61 |
| 61 /** | 62 /** |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 void retainWhere(bool test(E element)); | 115 void retainWhere(bool test(E element)); |
| 115 | 116 |
| 116 /** | 117 /** |
| 117 * Returns whether this Set contains all the elements of [other]. | 118 * Returns whether this Set contains all the elements of [other]. |
| 118 */ | 119 */ |
| 119 bool containsAll(Iterable<Object> other); | 120 bool containsAll(Iterable<Object> other); |
| 120 | 121 |
| 121 /** | 122 /** |
| 122 * Returns a new set which is the intersection between this set and [other]. | 123 * Returns a new set which is the intersection between this set and [other]. |
| 123 * | 124 * |
| 124 * That is, the returned set contains all the elements of this `Set` that | 125 * That is, the returned set contains all the elements of this [Set] that |
| 125 * are also elements of `other` according to `other.contains`. | 126 * are also elements of [other] according to `other.contains`. |
| 126 */ | 127 */ |
| 127 Set<E> intersection(Set<Object> other); | 128 Set<E> intersection(Set<Object> other); |
| 128 | 129 |
| 129 /** | 130 /** |
| 130 * Returns a new set which contains all the elements of this set and [other]. | 131 * Returns a new set which contains all the elements of this set and [other]. |
| 131 * | 132 * |
| 132 * That is, the returned set contains all the elements of this `Set` and | 133 * That is, the returned set contains all the elements of this [Set] and |
| 133 * all the elements of [other]. | 134 * all the elements of [other]. |
| 134 */ | 135 */ |
| 135 Set<E> union(Set<E> other); | 136 Set<E> union(Set<E> other); |
| 136 | 137 |
| 137 /** | 138 /** |
| 138 * Returns a new set with the the elements of this that are not in [other]. | 139 * Returns a new set with the the elements of this that are not in [other]. |
| 139 * | 140 * |
| 140 * That is, the returned set contains all the elements of this `Set` that | 141 * That is, the returned set contains all the elements of this [Set] that |
| 141 * are not elements of [other] according to `other.contains`. | 142 * are not elements of [other] according to `other.contains`. |
| 142 */ | 143 */ |
| 143 Set<E> difference(Set<E> other); | 144 Set<E> difference(Set<E> other); |
| 144 | 145 |
| 145 /** | 146 /** |
| 146 * Removes all elements in the set. | 147 * Removes all elements in the set. |
| 147 */ | 148 */ |
| 148 void clear(); | 149 void clear(); |
| 149 } | 150 } |
| OLD | NEW |