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

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

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