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 import 'dart:math' show Random; |
9 | 9 |
10 // 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. |
11 class ListProxy<E> extends IterableBase<E> implements List<E> { | 11 class ListProxy<E> extends IterableBase<E> implements List<E> { |
12 | 12 |
13 /** The inner [List<T>] with the actual storage. */ | 13 /// The inner [List<T>] with the actual storage. |
14 final List<E> _list; | 14 final List<E> _list; |
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, | 18 /// otherwise this will create a [List<E>]. |
19 * otherwise this will create a [List<E>]. | |
20 */ | |
21 ListProxy([List<E> storage]) | 19 ListProxy([List<E> storage]) |
22 : _list = storage != null ? storage : <E>[]; | 20 : _list = storage != null ? storage : <E>[]; |
23 | 21 |
24 // TODO(jmesserly): This should be on List. | 22 // TODO(jmesserly): This should be on List. |
25 // See http://code.google.com/p/dart/issues/detail?id=947 | 23 // See http://code.google.com/p/dart/issues/detail?id=947 |
26 bool remove(E item) { | 24 bool remove(E item) { |
27 int i = indexOf(item); | 25 int i = indexOf(item); |
28 if (i == -1) return false; | 26 if (i == -1) return false; |
29 removeAt(i); | 27 removeAt(i); |
30 return true; | 28 return true; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 Map<int, E> asMap() => _list.asMap(); | 79 Map<int, E> asMap() => _list.asMap(); |
82 | 80 |
83 void replaceRange(int start, int end, Iterable<E> newContents) => | 81 void replaceRange(int start, int end, Iterable<E> newContents) => |
84 _list.replaceRange(start, end, newContents); | 82 _list.replaceRange(start, end, newContents); |
85 | 83 |
86 void setAll(int index, Iterable<E> iterable) => _list.setAll(index, iterable); | 84 void setAll(int index, Iterable<E> iterable) => _list.setAll(index, iterable); |
87 | 85 |
88 void fillRange(int start, int end, [E fillValue]) | 86 void fillRange(int start, int end, [E fillValue]) |
89 => _list.fillRange(start, end, fillValue); | 87 => _list.fillRange(start, end, fillValue); |
90 } | 88 } |
OLD | NEW |