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

Side by Side Diff: tools/dom/src/WrappedList.dart

Issue 13852008: Removing redundant collection methods from DOM collections. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 8 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
« no previous file with comments | « tests/html/node_test.dart ('k') | tools/dom/templates/html/impl/impl_Element.darttemplate » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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> implements List<E> { 11 class _WrappedList<E> extends ListBase<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
47 int get length => _list.length; 20 int get length => _list.length;
48 21
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
75 // Collection APIs 22 // Collection APIs
76 23
77 void add(E element) { _list.add(element); } 24 void add(E element) { _list.add(element); }
78 25
79 void addAll(Iterable<E> elements) { _list.addAll(elements); }
80
81 void remove(Object element) { _list.remove(element); } 26 void remove(Object element) { _list.remove(element); }
82 27
83 void removeWhere(bool test(E element)) { _list.removeWhere(test); }
84
85 void retainWhere(bool test(E element)) { _list.retainWhere(test); }
86
87 void clear() { _list.clear(); } 28 void clear() { _list.clear(); }
88 29
89 // List APIs 30 // List APIs
90 31
91 E operator [](int index) => _list[index]; 32 E operator [](int index) => _list[index];
92 33
93 void operator []=(int index, E value) { _list[index] = value; } 34 void operator []=(int index, E value) { _list[index] = value; }
94 35
95 void set length(int newLength) { _list.length = newLength; } 36 void set length(int newLength) { _list.length = newLength; }
96 37
97 Iterable<E> get reversed => _list.reversed;
98
99 void sort([int compare(E a, E b)]) { _list.sort(compare); } 38 void sort([int compare(E a, E b)]) { _list.sort(compare); }
100 39
101 int indexOf(E element, [int start = 0]) => _list.indexOf(element, start); 40 int indexOf(E element, [int start = 0]) => _list.indexOf(element, start);
102 41
103 int lastIndexOf(E element, [int start]) => _list.lastIndexOf(element, start); 42 int lastIndexOf(E element, [int start]) => _list.lastIndexOf(element, start);
104 43
105 void insert(int index, E element) => _list.insert(index, element); 44 void insert(int index, E element) => _list.insert(index, element);
106 45
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
113 E removeAt(int index) => _list.removeAt(index); 46 E removeAt(int index) => _list.removeAt(index);
114 47
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
121 void setRange(int start, int end, Iterable<E> iterable, [int skipCount = 0]) { 48 void setRange(int start, int end, Iterable<E> iterable, [int skipCount = 0]) {
122 _list.setRange(start, end, iterable, skipCount); 49 _list.setRange(start, end, iterable, skipCount);
123 } 50 }
124 51
125 void removeRange(int start, int end) { _list.removeRange(start, end); } 52 void removeRange(int start, int end) { _list.removeRange(start, end); }
126 53
127 void replaceRange(int start, int end, Iterable<E> iterable) { 54 void replaceRange(int start, int end, Iterable<E> iterable) {
128 _list.replaceRange(start, end, iterable); 55 _list.replaceRange(start, end, iterable);
129 } 56 }
130 57
131 void fillRange(int start, int end, [E fillValue]) { 58 void fillRange(int start, int end, [E fillValue]) {
132 _list.fillRange(start, end, fillValue); 59 _list.fillRange(start, end, fillValue);
133 } 60 }
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 }
143 } 61 }
144 62
145 /** 63 /**
146 * Iterator wrapper for _WrappedList. 64 * Iterator wrapper for _WrappedList.
147 */ 65 */
148 class _WrappedIterator<E> implements Iterator<E> { 66 class _WrappedIterator<E> implements Iterator<E> {
149 Iterator _iterator; 67 Iterator _iterator;
150 68
151 _WrappedIterator(this._iterator); 69 _WrappedIterator(this._iterator);
152 70
153 bool moveNext() { 71 bool moveNext() {
154 return _iterator.moveNext(); 72 return _iterator.moveNext();
155 } 73 }
156 74
157 E get current => _iterator.current; 75 E get current => _iterator.current;
158 } 76 }
OLDNEW
« no previous file with comments | « tests/html/node_test.dart ('k') | tools/dom/templates/html/impl/impl_Element.darttemplate » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698