OLD | NEW |
1 // TODO(jmesserly): remove this once we have a subclassable growable list | 1 // TODO(jmesserly): remove this once we have a subclassable growable list |
2 // in our libraries. | 2 // in our libraries. |
3 | 3 |
4 /** A [List] proxy that you can subclass. */ | 4 /** A [List] proxy that you can subclass. */ |
5 library list_proxy; | 5 library list_proxy; |
6 | 6 |
7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 import 'dart:math' show Random; |
8 | 9 |
9 // TOOD(jmesserly): this needs to be removed, but fixing NodeList is tricky. | 10 // TOOD(jmesserly): this needs to be removed, but fixing NodeList is tricky. |
10 class ListProxy<E> extends IterableBase<E> implements List<E> { | 11 class ListProxy<E> extends IterableBase<E> implements List<E> { |
11 | 12 |
12 /** The inner [List<T>] with the actual storage. */ | 13 /** The inner [List<T>] with the actual storage. */ |
13 final List<E> _list; | 14 final List<E> _list; |
14 | 15 |
15 /** | 16 /** |
16 * Creates a list proxy. | 17 * Creates a list proxy. |
17 * You can optionally specify the list to use for [storage] of the items, | 18 * You can optionally specify the list to use for [storage] of the items, |
(...skipping 26 matching lines...) Expand all Loading... |
44 | 45 |
45 // From List | 46 // From List |
46 E operator [](int index) => _list[index]; | 47 E operator [](int index) => _list[index]; |
47 operator []=(int index, E value) { _list[index] = value; } | 48 operator []=(int index, E value) { _list[index] = value; } |
48 set length(int value) { _list.length = value; } | 49 set length(int value) { _list.length = value; } |
49 void add(E value) { _list.add(value); } | 50 void add(E value) { _list.add(value); } |
50 | 51 |
51 void addLast(E value) { add(value); } | 52 void addLast(E value) { add(value); } |
52 void addAll(Iterable<E> collection) { _list.addAll(collection); } | 53 void addAll(Iterable<E> collection) { _list.addAll(collection); } |
53 void sort([int compare(E a, E b)]) { _list.sort(compare); } | 54 void sort([int compare(E a, E b)]) { _list.sort(compare); } |
54 void shuffle() { _list.shuffle(); } | 55 void shuffle([Random random]) { _list.shuffle(random); } |
55 | 56 |
56 int indexOf(E element, [int start = 0]) => _list.indexOf(element, start); | 57 int indexOf(E element, [int start = 0]) => _list.indexOf(element, start); |
57 int lastIndexOf(E element, [int start]) => _list.lastIndexOf(element, start); | 58 int lastIndexOf(E element, [int start]) => _list.lastIndexOf(element, start); |
58 void clear() { _list.clear(); } | 59 void clear() { _list.clear(); } |
59 | 60 |
60 E removeAt(int index) => _list.removeAt(index); | 61 E removeAt(int index) => _list.removeAt(index); |
61 E removeLast() => _list.removeLast(); | 62 E removeLast() => _list.removeLast(); |
62 | 63 |
63 void removeWhere(bool test(E element)) => _list.removeWhere(test); | 64 void removeWhere(bool test(E element)) => _list.removeWhere(test); |
64 void retainWhere(bool test(E element)) => _list.retainWhere(test); | 65 void retainWhere(bool test(E element)) => _list.retainWhere(test); |
(...skipping 15 matching lines...) Expand all Loading... |
80 Map<int, E> asMap() => _list.asMap(); | 81 Map<int, E> asMap() => _list.asMap(); |
81 | 82 |
82 void replaceRange(int start, int end, Iterable<E> newContents) => | 83 void replaceRange(int start, int end, Iterable<E> newContents) => |
83 _list.replaceRange(start, end, newContents); | 84 _list.replaceRange(start, end, newContents); |
84 | 85 |
85 void setAll(int index, Iterable<E> iterable) => _list.setAll(index, iterable); | 86 void setAll(int index, Iterable<E> iterable) => _list.setAll(index, iterable); |
86 | 87 |
87 void fillRange(int start, int end, [E fillValue]) | 88 void fillRange(int start, int end, [E fillValue]) |
88 => _list.fillRange(start, end, fillValue); | 89 => _list.fillRange(start, end, fillValue); |
89 } | 90 } |
OLD | NEW |