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 library web_ui.observe.set; | 5 library web_ui.observe.set; |
6 | 6 |
7 import 'dart:collection'; | 7 import 'dart:collection'; |
8 import 'observable.dart'; | 8 import 'observable.dart'; |
9 import 'map.dart' show MapFactory; | 9 import 'map.dart' show MapFactory; |
10 import 'package:web_ui/src/utils_observe.dart' show IterableWorkaround; | 10 import 'package:web_ui/src/utils_observe.dart' show IterableWorkaround; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 */ | 46 */ |
47 bool contains(E value) { | 47 bool contains(E value) { |
48 if (observeReads) notifyRead(this, ChangeRecord.INDEX, value); | 48 if (observeReads) notifyRead(this, ChangeRecord.INDEX, value); |
49 return _map.containsKey(value); | 49 return _map.containsKey(value); |
50 } | 50 } |
51 | 51 |
52 /** | 52 /** |
53 * Adds [value] into the set. The method has no effect if | 53 * Adds [value] into the set. The method has no effect if |
54 * [value] was already in the set. | 54 * [value] was already in the set. |
55 */ | 55 */ |
56 void add(E value) { | 56 bool add(E value) { |
57 int len = _map.length; | 57 int len = _map.length; |
58 _map[value] = const Object(); | 58 _map[value] = const Object(); |
59 if (len != _map.length) { | 59 if (len != _map.length) { |
60 notifyChange(this, ChangeRecord.FIELD, 'length', len, _map.length); | 60 notifyChange(this, ChangeRecord.FIELD, 'length', len, _map.length); |
61 notifyChange(this, ChangeRecord.INSERT, value, null, value); | 61 notifyChange(this, ChangeRecord.INSERT, value, null, value); |
| 62 return true; |
62 } | 63 } |
| 64 return false; |
63 } | 65 } |
64 | 66 |
65 /** | 67 /** |
66 * Removes [value] from the set. Returns true if [value] was | 68 * Removes [value] from the set. Returns true if [value] was |
67 * in the set. Returns false otherwise. The method has no effect | 69 * in the set. Returns false otherwise. The method has no effect |
68 * if [value] value was not in the set. | 70 * if [value] value was not in the set. |
69 */ | 71 */ |
70 bool remove(E value) { | 72 bool remove(E value) { |
71 // notifyRead because result depends on if the key already exists | 73 // notifyRead because result depends on if the key already exists |
72 if (observeReads) notifyRead(this, ChangeRecord.INDEX, value); | 74 if (observeReads) notifyRead(this, ChangeRecord.INDEX, value); |
(...skipping 30 matching lines...) Expand all Loading... |
103 | 105 |
104 bool get isEmpty => length == 0; | 106 bool get isEmpty => length == 0; |
105 | 107 |
106 Iterator<E> get iterator => new _ObservableSetIterator<E>(this); | 108 Iterator<E> get iterator => new _ObservableSetIterator<E>(this); |
107 | 109 |
108 /** | 110 /** |
109 * Adds all the elements of the given collection to the set. | 111 * Adds all the elements of the given collection to the set. |
110 */ | 112 */ |
111 void addAll(Iterable<E> collection) => collection.forEach(add); | 113 void addAll(Iterable<E> collection) => collection.forEach(add); |
112 | 114 |
| 115 E lookup(Object object) { throw new UnimplementedError(); } |
| 116 |
113 /** | 117 /** |
114 * Removes all the elements of the given collection from the set. | 118 * Removes all the elements of the given collection from the set. |
115 */ | 119 */ |
116 void removeAll(Iterable collection) => collection.forEach(remove); | 120 void removeAll(Iterable collection) => collection.forEach(remove); |
117 | 121 |
118 void retainAll(Iterable collection) => retainWhere(collection.contains); | 122 void retainAll(Iterable collection) => retainWhere(collection.contains); |
119 | 123 |
120 void removeWhere(bool test(E element)) => | 124 void removeWhere(bool test(E element)) => |
121 where(test).toList().forEach(remove); | 125 where(test).toList().forEach(remove); |
122 | 126 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 _set.length; | 184 _set.length; |
181 return _hasNext = _iterator.moveNext(); | 185 return _hasNext = _iterator.moveNext(); |
182 } | 186 } |
183 | 187 |
184 E get current { | 188 E get current { |
185 var result = _iterator.current; | 189 var result = _iterator.current; |
186 if (observeReads && _hasNext) notifyRead(_set, ChangeRecord.INDEX, result); | 190 if (observeReads && _hasNext) notifyRead(_set, ChangeRecord.INDEX, result); |
187 return result; | 191 return result; |
188 } | 192 } |
189 } | 193 } |
OLD | NEW |