Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(132)

Side by Side Diff: tools/dom/templates/html/impl/impl_Element.darttemplate

Issue 11971016: Create IterableMixinWorkaround and move most of the Collections methods there. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix typo (mappedByList instead of mappedBy). Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 html; 5 part of html;
6 6
7 // TODO(jacobr): use _Lists.dart to remove some of the duplicated 7 // TODO(jacobr): use _Lists.dart to remove some of the duplicated
8 // functionality. 8 // functionality.
9 class _ChildrenElementList implements List { 9 class _ChildrenElementList implements List {
10 // Raw Element. 10 // Raw Element.
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 bool any(bool f(Element element)) { 51 bool any(bool f(Element element)) {
52 for (Element element in this) { 52 for (Element element in this) {
53 if (f(element)) { 53 if (f(element)) {
54 return true; 54 return true;
55 } 55 }
56 } 56 }
57 return false; 57 return false;
58 } 58 }
59 59
60 String join([String separator]) { 60 String join([String separator]) {
61 return Collections.joinList(this, separator); 61 return IterableMixinWorkaround.joinList(this, separator);
62 } 62 }
63 63
64 List mappedBy(f(Element element)) { 64 List mappedBy(f(Element element)) {
65 return new MappedList<Element, dynamic>(this, f); 65 return IterableMixinWorkaround.mappedByList(this, f);
66 } 66 }
67 67
68 Iterable<Element> where(bool f(Element element)) 68 Iterable<Element> where(bool f(Element element)) {
69 => new WhereIterable(this, f); 69 return IterableMixinWorkaround.where(this, f);
70 }
70 71
71 bool get isEmpty { 72 bool get isEmpty {
72 return _element.$dom_firstElementChild == null; 73 return _element.$dom_firstElementChild == null;
73 } 74 }
74 75
75 List<Element> take(int n) { 76 List<Element> take(int n) {
76 return new ListView<Element>(this, 0, n); 77 return IterableMixinWorkaround.takeList(this, n);
77 } 78 }
78 79
79 Iterable<Element> takeWhile(bool test(Element value)) { 80 Iterable<Element> takeWhile(bool test(Element value)) {
80 return new TakeWhileIterable<Element>(this, test); 81 return IterableMixinWorkaround.takeWhile(this, test);
81 } 82 }
82 83
83 List<Element> skip(int n) { 84 List<Element> skip(int n) {
84 return new ListView<Element>(this, n, null); 85 return IterableMixinWorkaround.skipList(this, n);
85 } 86 }
86 87
87 Iterable<Element> skipWhile(bool test(Element value)) { 88 Iterable<Element> skipWhile(bool test(Element value)) {
88 return new SkipWhileIterable<Element>(this, test); 89 return IterableMixinWorkaround.skipWhile(this, test);
89 } 90 }
90 91
91 Element firstMatching(bool test(Element value), {Element orElse()}) { 92 Element firstMatching(bool test(Element value), {Element orElse()}) {
92 return Collections.firstMatching(this, test, orElse); 93 return IterableMixinWorkaround.firstMatching(this, test, orElse);
93 } 94 }
94 95
95 Element lastMatching(bool test(Element value), {Element orElse()}) { 96 Element lastMatching(bool test(Element value), {Element orElse()}) {
96 return Collections.lastMatchingInList(this, test, orElse); 97 return IterableMixinWorkaround.lastMatchingInList(this, test, orElse);
97 } 98 }
98 99
99 Element singleMatching(bool test(Element value)) { 100 Element singleMatching(bool test(Element value)) {
100 return Collections.singleMatching(this, test); 101 return IterableMixinWorkaround.singleMatching(this, test);
101 } 102 }
102 103
103 Element elementAt(int index) { 104 Element elementAt(int index) {
104 return this[index]; 105 return this[index];
105 } 106 }
106 107
107 int get length { 108 int get length {
108 return _childElements.length; 109 return _childElements.length;
109 } 110 }
110 111
(...skipping 24 matching lines...) Expand all
135 _element.$dom_appendChild(element); 136 _element.$dom_appendChild(element);
136 } 137 }
137 } 138 }
138 139
139 void sort([int compare(Element a, Element b)]) { 140 void sort([int compare(Element a, Element b)]) {
140 throw new UnsupportedError('TODO(jacobr): should we impl?'); 141 throw new UnsupportedError('TODO(jacobr): should we impl?');
141 } 142 }
142 143
143 dynamic reduce(dynamic initialValue, 144 dynamic reduce(dynamic initialValue,
144 dynamic combine(dynamic previousValue, Element element)) { 145 dynamic combine(dynamic previousValue, Element element)) {
145 return Collections.reduce(this, initialValue, combine); 146 return IterableMixinWorkaround.reduce(this, initialValue, combine);
146 } 147 }
147 148
148 void setRange(int start, int rangeLength, List from, [int startFrom = 0]) { 149 void setRange(int start, int rangeLength, List from, [int startFrom = 0]) {
149 throw new UnimplementedError(); 150 throw new UnimplementedError();
150 } 151 }
151 152
152 void removeRange(int start, int rangeLength) { 153 void removeRange(int start, int rangeLength) {
153 throw new UnimplementedError(); 154 throw new UnimplementedError();
154 } 155 }
155 156
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 if (result == null) throw new StateError("No elements"); 204 if (result == null) throw new StateError("No elements");
204 return result; 205 return result;
205 } 206 }
206 207
207 Element get single { 208 Element get single {
208 if (length > 1) throw new StateError("More than one element"); 209 if (length > 1) throw new StateError("More than one element");
209 return first; 210 return first;
210 } 211 }
211 212
212 Element min([int compare(Element a, Element b)]) { 213 Element min([int compare(Element a, Element b)]) {
213 return Collections.min(this, compare); 214 return IterableMixinWorkaround.min(this, compare);
214 } 215 }
215 216
216 Element max([int compare(Element a, Element b)]) { 217 Element max([int compare(Element a, Element b)]) {
217 return Collections.max(this, compare); 218 return IterableMixinWorkaround.max(this, compare);
218 } 219 }
219 } 220 }
220 221
221 // TODO(jacobr): this is an inefficient implementation but it is hard to see 222 // TODO(jacobr): this is an inefficient implementation but it is hard to see
222 // a better option given that we cannot quite force NodeList to be an 223 // a better option given that we cannot quite force NodeList to be an
223 // ElementList as there are valid cases where a NodeList JavaScript object 224 // ElementList as there are valid cases where a NodeList JavaScript object
224 // contains Node objects that are not Elements. 225 // contains Node objects that are not Elements.
225 class _FrozenElementList implements List { 226 class _FrozenElementList implements List {
226 final List<Node> _nodeList; 227 final List<Node> _nodeList;
227 228
228 _FrozenElementList._wrap(this._nodeList); 229 _FrozenElementList._wrap(this._nodeList);
229 230
230 bool contains(Element element) { 231 bool contains(Element element) {
231 for (Element el in this) { 232 for (Element el in this) {
232 if (el == element) return true; 233 if (el == element) return true;
233 } 234 }
234 return false; 235 return false;
235 } 236 }
236 237
237 void forEach(void f(Element element)) { 238 void forEach(void f(Element element)) {
238 for (Element el in this) { 239 for (Element el in this) {
239 f(el); 240 f(el);
240 } 241 }
241 } 242 }
242 243
243 String join([String separator]) { 244 String join([String separator]) {
244 return Collections.joinList(this, separator); 245 return IterableMixinWorkaround.joinList(this, separator);
245 } 246 }
246 247
247 List mappedBy(f(Element element)) { 248 List mappedBy(f(Element element)) {
248 return new MappedList<Element, dynamic>(this, f); 249 return IterableMixinWorkaround.mappedByList(this, f);
249 } 250 }
250 251
251 Iterable<Element> where(bool f(Element element)) 252 Iterable<Element> where(bool f(Element element)) {
252 => new WhereIterable(this, f); 253 return IterableMixinWorkaround.where(this, f);
254 }
253 255
254 bool every(bool f(Element element)) { 256 bool every(bool f(Element element)) {
255 for(Element element in this) { 257 for(Element element in this) {
256 if (!f(element)) { 258 if (!f(element)) {
257 return false; 259 return false;
258 } 260 }
259 }; 261 };
260 return true; 262 return true;
261 } 263 }
262 264
263 bool any(bool f(Element element)) { 265 bool any(bool f(Element element)) {
264 for(Element element in this) { 266 for(Element element in this) {
265 if (f(element)) { 267 if (f(element)) {
266 return true; 268 return true;
267 } 269 }
268 }; 270 };
269 return false; 271 return false;
270 } 272 }
271 273
272 List<Element> toList() => new List<Element>.from(this); 274 List<Element> toList() => new List<Element>.from(this);
273 Set<Element> toSet() => new Set<Element>.from(this); 275 Set<Element> toSet() => new Set<Element>.from(this);
274 276
275 List<Element> take(int n) { 277 List<Element> take(int n) {
276 return new ListView<Element>(this, 0, n); 278 return IterableMixinWorkaround.takeList(this, n);
277 } 279 }
278 280
279 Iterable<Element> takeWhile(bool test(Element value)) { 281 Iterable<Element> takeWhile(bool test(Element value)) {
280 return new TakeWhileIterable<Element>(this, test); 282 return IterableMixinWorkaround.takeWhile(this, test);
281 } 283 }
282 284
283 List<Element> skip(int n) { 285 List<Element> skip(int n) {
284 return new ListView<Element>(this, n, null); 286 return IterableMixinWorkaround.skipList(this, n);
285 } 287 }
286 288
287 Iterable<Element> skipWhile(bool test(Element value)) { 289 Iterable<Element> skipWhile(bool test(Element value)) {
288 return new SkipWhileIterable<Element>(this, test); 290 return IterableMixinWorkaround.skipWhile(this, test);
289 } 291 }
290 292
291 Element firstMatching(bool test(Element value), {Element orElse()}) { 293 Element firstMatching(bool test(Element value), {Element orElse()}) {
292 return Collections.firstMatching(this, test, orElse); 294 return IterableMixinWorkaround.firstMatching(this, test, orElse);
293 } 295 }
294 296
295 Element lastMatching(bool test(Element value), {Element orElse()}) { 297 Element lastMatching(bool test(Element value), {Element orElse()}) {
296 return Collections.lastMatchingInList(this, test, orElse); 298 return IterableMixinWorkaround.lastMatchingInList(this, test, orElse);
297 } 299 }
298 300
299 Element singleMatching(bool test(Element value)) { 301 Element singleMatching(bool test(Element value)) {
300 return Collections.singleMatching(this, test); 302 return IterableMixinWorkaround.singleMatching(this, test);
301 } 303 }
302 304
303 Element elementAt(int index) { 305 Element elementAt(int index) {
304 return this[index]; 306 return this[index];
305 } 307 }
306 308
307 bool get isEmpty => _nodeList.isEmpty; 309 bool get isEmpty => _nodeList.isEmpty;
308 310
309 int get length => _nodeList.length; 311 int get length => _nodeList.length;
310 312
(...skipping 20 matching lines...) Expand all
331 void addAll(Iterable<Element> iterable) { 333 void addAll(Iterable<Element> iterable) {
332 throw new UnsupportedError(''); 334 throw new UnsupportedError('');
333 } 335 }
334 336
335 void sort([int compare(Element a, Element b)]) { 337 void sort([int compare(Element a, Element b)]) {
336 throw new UnsupportedError(''); 338 throw new UnsupportedError('');
337 } 339 }
338 340
339 dynamic reduce(dynamic initialValue, 341 dynamic reduce(dynamic initialValue,
340 dynamic combine(dynamic previousValue, Element element)) { 342 dynamic combine(dynamic previousValue, Element element)) {
341 return Collections.reduce(this, initialValue, combine); 343 return IterableMixinWorkaround.reduce(this, initialValue, combine);
342 } 344 }
343 345
344 void setRange(int start, int rangeLength, List from, [int startFrom = 0]) { 346 void setRange(int start, int rangeLength, List from, [int startFrom = 0]) {
345 throw new UnsupportedError(''); 347 throw new UnsupportedError('');
346 } 348 }
347 349
348 void removeRange(int start, int rangeLength) { 350 void removeRange(int start, int rangeLength) {
349 throw new UnsupportedError(''); 351 throw new UnsupportedError('');
350 } 352 }
351 353
(...skipping 22 matching lines...) Expand all
374 throw new UnsupportedError(''); 376 throw new UnsupportedError('');
375 } 377 }
376 378
377 Element get first => _nodeList.first; 379 Element get first => _nodeList.first;
378 380
379 Element get last => _nodeList.last; 381 Element get last => _nodeList.last;
380 382
381 Element get single => _nodeList.single; 383 Element get single => _nodeList.single;
382 384
383 Element min([int compare(Element a, Element b)]) { 385 Element min([int compare(Element a, Element b)]) {
384 return Collections.min(this, compare); 386 return IterableMixinWorkaround.min(this, compare);
385 } 387 }
386 388
387 Element max([int compare(Element a, Element b)]) { 389 Element max([int compare(Element a, Element b)]) {
388 return Collections.max(this, compare); 390 return IterableMixinWorkaround.max(this, compare);
389 } 391 }
390 } 392 }
391 393
392 class _FrozenElementListIterator implements Iterator<Element> { 394 class _FrozenElementListIterator implements Iterator<Element> {
393 final _FrozenElementList _list; 395 final _FrozenElementList _list;
394 int _index = -1; 396 int _index = -1;
395 Element _current; 397 Element _current;
396 398
397 _FrozenElementListIterator(this._list); 399 _FrozenElementListIterator(this._list);
398 400
(...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after
991 $if DART2JS 993 $if DART2JS
992 // Optimization to improve performance until the dart2js compiler inlines this 994 // Optimization to improve performance until the dart2js compiler inlines this
993 // method. 995 // method.
994 static dynamic createElement_tag(String tag) => 996 static dynamic createElement_tag(String tag) =>
995 JS('Element', 'document.createElement(#)', tag); 997 JS('Element', 'document.createElement(#)', tag);
996 $else 998 $else
997 static Element createElement_tag(String tag) => 999 static Element createElement_tag(String tag) =>
998 document.$dom_createElement(tag); 1000 document.$dom_createElement(tag);
999 $endif 1001 $endif
1000 } 1002 }
OLDNEW
« no previous file with comments | « tests/corelib/iterable_min_max_test.dart ('k') | tools/dom/templates/html/impl/impl_Node.darttemplate » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698