| 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 ListBase<E> { | 11 class _WrappedList<E> implements List<E> { |
| 12 final List _list; | 12 final List _list; |
| 13 | 13 |
| 14 _WrappedList(this._list); | 14 _WrappedList(this._list); |
| 15 | 15 |
| 16 // Iterable APIs | 16 // Iterable APIs |
| 17 | 17 |
| 18 Iterator<E> get iterator => new _WrappedIterator(_list.iterator); | 18 Iterator<E> get iterator => new _WrappedIterator(_list.iterator); |
| 19 | 19 |
| 20 Iterable map(f(E element)) => _list.map(f); |
| 21 |
| 22 Iterable<E> where(bool f(E element)) => _list.where(f); |
| 23 |
| 24 Iterable expand(Iterable f(E element)) => _list.expand(f); |
| 25 |
| 26 bool contains(E element) => _list.contains(element); |
| 27 |
| 28 void forEach(void f(E element)) { _list.forEach(f); } |
| 29 |
| 30 E reduce(E combine(E value, E element)) => |
| 31 _list.reduce(combine); |
| 32 |
| 33 dynamic fold(initialValue, combine(previousValue, E element)) => |
| 34 _list.fold(initialValue, combine); |
| 35 |
| 36 bool every(bool f(E element)) => _list.every(f); |
| 37 |
| 38 String join([String separator = ""]) => _list.join(separator); |
| 39 |
| 40 bool any(bool f(E element)) => _list.any(f); |
| 41 |
| 42 List<E> toList({ bool growable: true }) => |
| 43 new List.from(_list, growable: growable); |
| 44 |
| 45 Set<E> toSet() => _list.toSet(); |
| 46 |
| 20 int get length => _list.length; | 47 int get length => _list.length; |
| 21 | 48 |
| 49 bool get isEmpty => _list.isEmpty; |
| 50 |
| 51 Iterable<E> take(int n) => _list.take(n); |
| 52 |
| 53 Iterable<E> takeWhile(bool test(E value)) => _list.takeWhile(test); |
| 54 |
| 55 Iterable<E> skip(int n) => _list.skip(n); |
| 56 |
| 57 Iterable<E> skipWhile(bool test(E value)) => _list.skipWhile(test); |
| 58 |
| 59 E get first => _list.first; |
| 60 |
| 61 E get last => _list.last; |
| 62 |
| 63 E get single => _list.single; |
| 64 |
| 65 E firstWhere(bool test(E value), { E orElse() }) => |
| 66 _list.firstWhere(test, orElse: orElse); |
| 67 |
| 68 E lastWhere(bool test(E value), {E orElse()}) => |
| 69 _list.lastWhere(test, orElse: orElse); |
| 70 |
| 71 E singleWhere(bool test(E value)) => _list.singleWhere(test); |
| 72 |
| 73 E elementAt(int index) => _list.elementAt(index); |
| 74 |
| 22 // Collection APIs | 75 // Collection APIs |
| 23 | 76 |
| 24 void add(E element) { _list.add(element); } | 77 void add(E element) { _list.add(element); } |
| 25 | 78 |
| 79 void addAll(Iterable<E> elements) { _list.addAll(elements); } |
| 80 |
| 26 void remove(Object element) { _list.remove(element); } | 81 void remove(Object element) { _list.remove(element); } |
| 27 | 82 |
| 83 void removeWhere(bool test(E element)) { _list.removeWhere(test); } |
| 84 |
| 85 void retainWhere(bool test(E element)) { _list.retainWhere(test); } |
| 86 |
| 28 void clear() { _list.clear(); } | 87 void clear() { _list.clear(); } |
| 29 | 88 |
| 30 // List APIs | 89 // List APIs |
| 31 | 90 |
| 32 E operator [](int index) => _list[index]; | 91 E operator [](int index) => _list[index]; |
| 33 | 92 |
| 34 void operator []=(int index, E value) { _list[index] = value; } | 93 void operator []=(int index, E value) { _list[index] = value; } |
| 35 | 94 |
| 36 void set length(int newLength) { _list.length = newLength; } | 95 void set length(int newLength) { _list.length = newLength; } |
| 37 | 96 |
| 97 Iterable<E> get reversed => _list.reversed; |
| 98 |
| 38 void sort([int compare(E a, E b)]) { _list.sort(compare); } | 99 void sort([int compare(E a, E b)]) { _list.sort(compare); } |
| 39 | 100 |
| 40 int indexOf(E element, [int start = 0]) => _list.indexOf(element, start); | 101 int indexOf(E element, [int start = 0]) => _list.indexOf(element, start); |
| 41 | 102 |
| 42 int lastIndexOf(E element, [int start]) => _list.lastIndexOf(element, start); | 103 int lastIndexOf(E element, [int start]) => _list.lastIndexOf(element, start); |
| 43 | 104 |
| 44 void insert(int index, E element) => _list.insert(index, element); | 105 void insert(int index, E element) => _list.insert(index, element); |
| 45 | 106 |
| 107 void insertAll(int index, Iterable<E> iterable) => |
| 108 _list.insertAll(index, iterable); |
| 109 |
| 110 void setAll(int index, Iterable<E> iterable) => |
| 111 _list.setAll(index, iterable); |
| 112 |
| 46 E removeAt(int index) => _list.removeAt(index); | 113 E removeAt(int index) => _list.removeAt(index); |
| 47 | 114 |
| 115 E removeLast() => _list.removeLast(); |
| 116 |
| 117 List<E> sublist(int start, [int end]) => _list.sublist(start, end); |
| 118 |
| 119 Iterable<E> getRange(int start, int end) => _list.getRange(start, end); |
| 120 |
| 48 void setRange(int start, int end, Iterable<E> iterable, [int skipCount = 0]) { | 121 void setRange(int start, int end, Iterable<E> iterable, [int skipCount = 0]) { |
| 49 _list.setRange(start, end, iterable, skipCount); | 122 _list.setRange(start, end, iterable, skipCount); |
| 50 } | 123 } |
| 51 | 124 |
| 52 void removeRange(int start, int end) { _list.removeRange(start, end); } | 125 void removeRange(int start, int end) { _list.removeRange(start, end); } |
| 53 | 126 |
| 54 void replaceRange(int start, int end, Iterable<E> iterable) { | 127 void replaceRange(int start, int end, Iterable<E> iterable) { |
| 55 _list.replaceRange(start, end, iterable); | 128 _list.replaceRange(start, end, iterable); |
| 56 } | 129 } |
| 57 | 130 |
| 58 void fillRange(int start, int end, [E fillValue]) { | 131 void fillRange(int start, int end, [E fillValue]) { |
| 59 _list.fillRange(start, end, fillValue); | 132 _list.fillRange(start, end, fillValue); |
| 60 } | 133 } |
| 134 |
| 135 Map<int, E> asMap() => _list.asMap(); |
| 136 |
| 137 String toString() { |
| 138 StringBuffer buffer = new StringBuffer('['); |
| 139 buffer.writeAll(this, ', '); |
| 140 buffer.write(']'); |
| 141 return buffer.toString(); |
| 142 } |
| 61 } | 143 } |
| 62 | 144 |
| 63 /** | 145 /** |
| 64 * Iterator wrapper for _WrappedList. | 146 * Iterator wrapper for _WrappedList. |
| 65 */ | 147 */ |
| 66 class _WrappedIterator<E> implements Iterator<E> { | 148 class _WrappedIterator<E> implements Iterator<E> { |
| 67 Iterator _iterator; | 149 Iterator _iterator; |
| 68 | 150 |
| 69 _WrappedIterator(this._iterator); | 151 _WrappedIterator(this._iterator); |
| 70 | 152 |
| 71 bool moveNext() { | 153 bool moveNext() { |
| 72 return _iterator.moveNext(); | 154 return _iterator.moveNext(); |
| 73 } | 155 } |
| 74 | 156 |
| 75 E get current => _iterator.current; | 157 E get current => _iterator.current; |
| 76 } | 158 } |
| OLD | NEW |