OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 | 5 |
6 // TODO(srdjan): Use shared array implementation. | 6 // TODO(srdjan): Use shared array implementation. |
7 class _List<E> implements List<E> { | 7 class _List<E> implements List<E> { |
8 static final int _classId = (new _List(0))._cid; | 8 static final int _classId = (new _List(0))._cid; |
9 | 9 |
10 factory _List(length) native "List_allocate"; | 10 factory _List(length) native "List_allocate"; |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 E get first { | 236 E get first { |
237 if (length > 0) return this[0]; | 237 if (length > 0) return this[0]; |
238 throw IterableElementError.noElement(); | 238 throw IterableElementError.noElement(); |
239 } | 239 } |
240 | 240 |
241 E get last { | 241 E get last { |
242 if (length > 0) return this[length - 1]; | 242 if (length > 0) return this[length - 1]; |
243 throw IterableElementError.noElement(); | 243 throw IterableElementError.noElement(); |
244 } | 244 } |
245 | 245 |
| 246 void set last(E value) { |
| 247 if (length == 0) throw IterableElementError.noElement(); |
| 248 this[length - 1] = value; |
| 249 } |
| 250 |
246 E get single { | 251 E get single { |
247 if (length == 1) return this[0]; | 252 if (length == 1) return this[0]; |
248 if (length == 0) throw IterableElementError.noElement(); | 253 if (length == 0) throw IterableElementError.noElement(); |
249 throw IterableElementError.tooMany(); | 254 throw IterableElementError.tooMany(); |
250 } | 255 } |
251 | 256 |
252 List<E> toList({ bool growable: true}) { | 257 List<E> toList({ bool growable: true}) { |
253 return new List<E>.from(this, growable: growable); | 258 return new List<E>.from(this, growable: growable); |
254 } | 259 } |
255 | 260 |
(...skipping 24 matching lines...) Expand all Loading... |
280 | 285 |
281 factory _ImmutableList._from(List from, int offset, int length) | 286 factory _ImmutableList._from(List from, int offset, int length) |
282 native "ImmutableList_from"; | 287 native "ImmutableList_from"; |
283 | 288 |
284 E operator [](int index) native "List_getIndexed"; | 289 E operator [](int index) native "List_getIndexed"; |
285 | 290 |
286 void operator []=(int index, E value) { | 291 void operator []=(int index, E value) { |
287 throw UnmodifiableListError.change(); | 292 throw UnmodifiableListError.change(); |
288 } | 293 } |
289 | 294 |
| 295 void set last(E value) { |
| 296 throw UnmodifiableListError.change(); |
| 297 } |
| 298 |
290 int get length native "List_getLength"; | 299 int get length native "List_getLength"; |
291 | 300 |
292 void insert(int index, E element) { | 301 void insert(int index, E element) { |
293 throw UnmodifiableListError.add(); | 302 throw UnmodifiableListError.add(); |
294 } | 303 } |
295 | 304 |
296 void insertAll(int index, Iterable<E> iterable) { | 305 void insertAll(int index, Iterable<E> iterable) { |
297 throw UnmodifiableListError.add(); | 306 throw UnmodifiableListError.add(); |
298 } | 307 } |
299 | 308 |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
530 } | 539 } |
531 _position = _length; | 540 _position = _length; |
532 _current = null; | 541 _current = null; |
533 return false; | 542 return false; |
534 } | 543 } |
535 | 544 |
536 E get current { | 545 E get current { |
537 return _current; | 546 return _current; |
538 } | 547 } |
539 } | 548 } |
OLD | NEW |