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

Side by Side Diff: tools/dom/templates/immutable_list_mixin.darttemplate

Issue 14036014: Updating DOM code to use list mixins (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 7 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 | « tools/dom/templates/html/impl/impl_TouchList.darttemplate ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // -- start List<$E> mixins. 1 // -- start List<$E> mixins.
2 // $E is the element type. 2 // $E is the element type.
3 3
4 // From Iterable<$E>:
5
6 Iterator<$E> get iterator {
7 // Note: NodeLists are not fixed size. And most probably length shouldn't
8 // be cached in both iterator _and_ forEach method. For now caching it
9 // for consistency.
10 return new FixedSizeListIterator<$E>(this);
11 }
12
13 $if DEFINE_LENGTH_AS_NUM_ITEMS 4 $if DEFINE_LENGTH_AS_NUM_ITEMS
14 // SVG Collections expose numberOfItems rather than length. 5 // SVG Collections expose numberOfItems rather than length.
15 int get length => numberOfItems; 6 int get length => numberOfItems;
16 $endif 7 $endif
17 $E reduce($E combine($E value, $E element)) {
18 return IterableMixinWorkaround.reduce(this, combine);
19 }
20 8
21 dynamic fold(dynamic initialValue,
22 dynamic combine(dynamic previousValue, $E element)) {
23 return IterableMixinWorkaround.fold(this, initialValue, combine);
24 }
25
26 $if DEFINE_CONTAINS
27 bool contains($E element) => IterableMixinWorkaround.contains(this, element);
28 $else
29 // contains() defined by IDL.
30 $endif
31
32 void forEach(void f($E element)) => IterableMixinWorkaround.forEach(this, f);
33
34 String join([String separator = ""]) =>
35 IterableMixinWorkaround.joinList(this, separator);
36
37 Iterable map(f($E element)) =>
38 IterableMixinWorkaround.mapList(this, f);
39
40 Iterable<$E> where(bool f($E element)) =>
41 IterableMixinWorkaround.where(this, f);
42
43 Iterable expand(Iterable f($E element)) =>
44 IterableMixinWorkaround.expand(this, f);
45
46 bool every(bool f($E element)) => IterableMixinWorkaround.every(this, f);
47
48 bool any(bool f($E element)) => IterableMixinWorkaround.any(this, f);
49
50 List<$E> toList({ bool growable: true }) =>
51 new List<$E>.from(this, growable: growable);
52
53 Set<$E> toSet() => new Set<$E>.from(this);
54
55 bool get isEmpty => this.length == 0;
56
57 Iterable<$E> take(int n) => IterableMixinWorkaround.takeList(this, n);
58
59 Iterable<$E> takeWhile(bool test($E value)) {
60 return IterableMixinWorkaround.takeWhile(this, test);
61 }
62
63 Iterable<$E> skip(int n) => IterableMixinWorkaround.skipList(this, n);
64
65 Iterable<$E> skipWhile(bool test($E value)) {
66 return IterableMixinWorkaround.skipWhile(this, test);
67 }
68
69 $E firstWhere(bool test($E value), { $E orElse() }) {
70 return IterableMixinWorkaround.firstWhere(this, test, orElse);
71 }
72
73 $E lastWhere(bool test($E value), {$E orElse()}) {
74 return IterableMixinWorkaround.lastWhereList(this, test, orElse);
75 }
76
77 $E singleWhere(bool test($E value)) {
78 return IterableMixinWorkaround.singleWhere(this, test);
79 }
80
81 $E elementAt(int index) {
82 return this[index];
83 }
84
85 // From Collection<$E>:
86
87 void add($E value) {
88 throw new UnsupportedError("Cannot add to immutable List.");
89 }
90
91 void addAll(Iterable<$E> iterable) {
92 throw new UnsupportedError("Cannot add to immutable List.");
93 }
94
95 // From List<$E>:
96 $if DEFINE_LENGTH_SETTER 9 $if DEFINE_LENGTH_SETTER
97 void set length(int value) { 10 void set length(int value) {
98 throw new UnsupportedError("Cannot resize immutable List."); 11 throw new UnsupportedError("Cannot resize immutable List.");
99 } 12 }
100 $endif 13 $endif
101 14
102 $if DEFINE_CLEAR
103 void clear() {
104 throw new UnsupportedError("Cannot clear immutable List.");
105 }
106 $else
107 // clear() defined by IDL.
108 $endif
109
110 Iterable<$E> get reversed {
111 return IterableMixinWorkaround.reversedList(this);
112 }
113
114 void sort([int compare($E a, $E b)]) {
115 throw new UnsupportedError("Cannot sort immutable List.");
116 }
117
118 int indexOf($E element, [int start = 0]) =>
119 Lists.indexOf(this, element, start, this.length);
120
121 int lastIndexOf($E element, [int start]) {
122 if (start == null) start = length - 1;
123 return Lists.lastIndexOf(this, element, start);
124 }
125
126 $E get first {
127 if (this.length > 0) return this[0];
128 throw new StateError("No elements");
129 }
130
131 $E get last {
132 if (this.length > 0) return this[this.length - 1];
133 throw new StateError("No elements");
134 }
135
136 $E get single {
137 if (length == 1) return this[0];
138 if (length == 0) throw new StateError("No elements");
139 throw new StateError("More than one element");
140 }
141
142 void insert(int index, $E element) {
143 throw new UnsupportedError("Cannot add to immutable List.");
144 }
145
146 void insertAll(int index, Iterable<$E> iterable) {
147 throw new UnsupportedError("Cannot add to immutable List.");
148 }
149
150 void setAll(int index, Iterable<$E> iterable) {
151 throw new UnsupportedError("Cannot modify an immutable List.");
152 }
153
154 $E removeAt(int pos) {
155 throw new UnsupportedError("Cannot remove from immutable List.");
156 }
157
158 $E removeLast() {
159 throw new UnsupportedError("Cannot remove from immutable List.");
160 }
161
162 bool remove(Object object) {
163 throw new UnsupportedError("Cannot remove from immutable List.");
164 }
165
166 void removeWhere(bool test($E element)) {
167 throw new UnsupportedError("Cannot remove from immutable List.");
168 }
169
170 void retainWhere(bool test($E element)) {
171 throw new UnsupportedError("Cannot remove from immutable List.");
172 }
173
174 void setRange(int start, int end, Iterable<$E> iterable, [int skipCount=0]) {
175 throw new UnsupportedError("Cannot setRange on immutable List.");
176 }
177
178 void removeRange(int start, int end) {
179 throw new UnsupportedError("Cannot removeRange on immutable List.");
180 }
181
182 void replaceRange(int start, int end, Iterable<$E> iterable) {
183 throw new UnsupportedError("Cannot modify an immutable List.");
184 }
185
186 void fillRange(int start, int end, [$E fillValue]) {
187 throw new UnsupportedError("Cannot modify an immutable List.");
188 }
189
190 Iterable<$E> getRange(int start, int end) =>
191 IterableMixinWorkaround.getRangeList(this, start, end);
192
193 List<$E> sublist(int start, [int end]) {
194 if (end == null) end = length;
195 return Lists.getRange(this, start, end, <$E>[]);
196 }
197
198 Map<int, $E> asMap() =>
199 IterableMixinWorkaround.asMapList(this);
200
201 String toString() {
202 StringBuffer buffer = new StringBuffer('[');
203 buffer.writeAll(this, ', ');
204 buffer.write(']');
205 return buffer.toString();
206 }
207
208 // -- end List<$E> mixins. 15 // -- end List<$E> mixins.
OLDNEW
« no previous file with comments | « tools/dom/templates/html/impl/impl_TouchList.darttemplate ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698