| 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.dom.html; | 5 part of dart.dom.html; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * A list which just wraps another list, for either intercepting list calls or | 8 * A list which just wraps another list, for either intercepting list calls or |
| 9 * retyping the list (for example, from List<A> to List<B> where B extends A). | 9 * retyping the list (for example, from List<A> to List<B> where B extends A). |
| 10 */ | 10 */ |
| 11 class _WrappedList<E extends Node> extends ListBase<E> | 11 class _WrappedList<E extends Node> extends ListBase<E> |
| 12 implements NodeListWrapper { | 12 implements NodeListWrapper { |
| 13 final List<Node> _list; | 13 final List<Node> _list; |
| 14 | 14 |
| 15 _WrappedList(this._list); | 15 _WrappedList(this._list); |
| 16 | 16 |
| 17 // Iterable APIs | 17 // Iterable APIs |
| 18 | 18 |
| 19 Iterator<E> get iterator => new _WrappedIterator<E>(_list.iterator); | 19 Iterator<E> get iterator => new _WrappedIterator<E>(_list.iterator); |
| 20 | 20 |
| 21 int get length => _list.length; | 21 int get length => _list.length; |
| 22 | 22 |
| 23 // Collection APIs | 23 // Collection APIs |
| 24 | 24 |
| 25 void add(E element) { _list.add(element); } | 25 void add(E element) { |
| 26 _list.add(element); |
| 27 } |
| 26 | 28 |
| 27 bool remove(Object element) => _list.remove(element); | 29 bool remove(Object element) => _list.remove(element); |
| 28 | 30 |
| 29 void clear() { _list.clear(); } | 31 void clear() { |
| 32 _list.clear(); |
| 33 } |
| 30 | 34 |
| 31 // List APIs | 35 // List APIs |
| 32 | 36 |
| 33 E operator [](int index) => _downcast/*<Node, E>*/(_list[index]); | 37 E operator [](int index) => _downcast/*<Node, E>*/(_list[index]); |
| 34 | 38 |
| 35 void operator []=(int index, E value) { _list[index] = value; } | 39 void operator []=(int index, E value) { |
| 40 _list[index] = value; |
| 41 } |
| 36 | 42 |
| 37 set length(int newLength) { _list.length = newLength; } | 43 set length(int newLength) { |
| 44 _list.length = newLength; |
| 45 } |
| 38 | 46 |
| 39 void sort([int compare(E a, E b)]) { _list.sort((Node a, Node b) => compare(_d
owncast/*<Node, E>*/(a), _downcast/*<Node, E>*/(b))); } | 47 void sort([int compare(E a, E b)]) { |
| 48 _list.sort((Node a, Node b) => |
| 49 compare(_downcast/*<Node, E>*/(a), _downcast/*<Node, E>*/(b))); |
| 50 } |
| 40 | 51 |
| 41 int indexOf(Object element, [int start = 0]) => _list.indexOf(element, start); | 52 int indexOf(Object element, [int start = 0]) => _list.indexOf(element, start); |
| 42 | 53 |
| 43 int lastIndexOf(Object element, [int start]) => _list.lastIndexOf(element, sta
rt); | 54 int lastIndexOf(Object element, [int start]) => |
| 55 _list.lastIndexOf(element, start); |
| 44 | 56 |
| 45 void insert(int index, E element) => _list.insert(index, element); | 57 void insert(int index, E element) => _list.insert(index, element); |
| 46 | 58 |
| 47 E removeAt(int index) => _downcast/*<Node, E>*/(_list.removeAt(index)); | 59 E removeAt(int index) => _downcast/*<Node, E>*/(_list.removeAt(index)); |
| 48 | 60 |
| 49 void setRange(int start, int end, Iterable<E> iterable, [int skipCount = 0]) { | 61 void setRange(int start, int end, Iterable<E> iterable, [int skipCount = 0]) { |
| 50 _list.setRange(start, end, iterable, skipCount); | 62 _list.setRange(start, end, iterable, skipCount); |
| 51 } | 63 } |
| 52 | 64 |
| 53 void removeRange(int start, int end) { _list.removeRange(start, end); } | 65 void removeRange(int start, int end) { |
| 66 _list.removeRange(start, end); |
| 67 } |
| 54 | 68 |
| 55 void replaceRange(int start, int end, Iterable<E> iterable) { | 69 void replaceRange(int start, int end, Iterable<E> iterable) { |
| 56 _list.replaceRange(start, end, iterable); | 70 _list.replaceRange(start, end, iterable); |
| 57 } | 71 } |
| 58 | 72 |
| 59 void fillRange(int start, int end, [E fillValue]) { | 73 void fillRange(int start, int end, [E fillValue]) { |
| 60 _list.fillRange(start, end, fillValue); | 74 _list.fillRange(start, end, fillValue); |
| 61 } | 75 } |
| 62 | 76 |
| 63 List<Node> get rawList => _list; | 77 List<Node> get rawList => _list; |
| 64 } | 78 } |
| 65 | 79 |
| 66 /** | 80 /** |
| 67 * Iterator wrapper for _WrappedList. | 81 * Iterator wrapper for _WrappedList. |
| 68 */ | 82 */ |
| 69 class _WrappedIterator<E extends Node> implements Iterator<E> { | 83 class _WrappedIterator<E extends Node> implements Iterator<E> { |
| 70 Iterator<Node> _iterator; | 84 Iterator<Node> _iterator; |
| 71 | 85 |
| 72 _WrappedIterator(this._iterator); | 86 _WrappedIterator(this._iterator); |
| 73 | 87 |
| 74 bool moveNext() { | 88 bool moveNext() { |
| 75 return _iterator.moveNext(); | 89 return _iterator.moveNext(); |
| 76 } | 90 } |
| 77 | 91 |
| 78 E get current => _downcast/*<Node, E>*/(_iterator.current); | 92 E get current => _downcast/*<Node, E>*/(_iterator.current); |
| 79 } | 93 } |
| 80 | 94 |
| 81 // ignore: STRONG_MODE_DOWN_CAST_COMPOSITE | 95 // ignore: STRONG_MODE_DOWN_CAST_COMPOSITE |
| 82 /*=To*/ _downcast/*<From, To extends From>*/(dynamic /*=From*/ x) => x; | 96 /*=To*/ _downcast/*<From, To extends From>*/(dynamic/*=From*/ x) => x; |
| OLD | NEW |