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 part of dart.collection; | 5 part of dart.collection; |
6 | 6 |
7 /** | 7 /** |
8 * This class provides default implementations for Iterables (including Lists). | 8 * This class provides default implementations for Iterables (including Lists). |
9 * | 9 * |
10 * Once Dart receives Mixins it will be replaced with mixin classes. | 10 * Once Dart receives Mixins it will be replaced with mixin classes. |
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 if (start < 0 || start > list.length) { | 362 if (start < 0 || start > list.length) { |
363 throw new RangeError.range(start, 0, list.length); | 363 throw new RangeError.range(start, 0, list.length); |
364 } | 364 } |
365 if (end < start || end > list.length) { | 365 if (end < start || end > list.length) { |
366 throw new RangeError.range(end, start, list.length); | 366 throw new RangeError.range(end, start, list.length); |
367 } | 367 } |
368 // The generic type is currently lost. It will be fixed with mixins. | 368 // The generic type is currently lost. It will be fixed with mixins. |
369 return new SubListIterable(list, start, end); | 369 return new SubListIterable(list, start, end); |
370 } | 370 } |
371 | 371 |
372 static void setRangeList(List list, int start, int length, | 372 static void setRangeList(List list, int start, int end, |
373 List from, int startFrom) { | 373 List from, int startFrom) { |
374 if (length == 0) return; | 374 if (start < 0 || start > list.length) { |
375 | 375 throw new RangeError.range(start, 0, list.length); |
376 if (length < 0) throw new ArgumentError(length); | |
377 if (start < 0) throw new RangeError.value(start); | |
378 if (start + length > list.length) { | |
379 throw new RangeError.value(start + length); | |
380 } | 376 } |
381 | 377 if (end < start || end > list.length) { |
| 378 throw new RangeError.range(end, start, list.length); |
| 379 } |
| 380 int length = end - start; |
| 381 if (startFrom < 0 || startFrom + length > from.length) { |
| 382 throw new RangeError.range(startFrom, 0, from.length - length); |
| 383 } |
382 Arrays.copy(from, startFrom, list, start, length); | 384 Arrays.copy(from, startFrom, list, start, length); |
383 } | 385 } |
384 | 386 |
385 static Map<int, dynamic> asMapList(List l) { | 387 static Map<int, dynamic> asMapList(List l) { |
386 return new ListMapView(l); | 388 return new ListMapView(l); |
387 } | 389 } |
388 | 390 |
389 static bool setContainsAll(Set set, Iterable other) { | 391 static bool setContainsAll(Set set, Iterable other) { |
390 for (var element in other) { | 392 for (var element in other) { |
391 if (!set.contains(element)) return false; | 393 if (!set.contains(element)) return false; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
438 * The source of the elements may be a [List] or any [Iterable] with | 440 * The source of the elements may be a [List] or any [Iterable] with |
439 * efficient [Iterable.length] and [Iterable.elementAt]. | 441 * efficient [Iterable.length] and [Iterable.elementAt]. |
440 */ | 442 */ |
441 class UnmodifiableListView<E> extends UnmodifiableListBase<E> { | 443 class UnmodifiableListView<E> extends UnmodifiableListBase<E> { |
442 Iterable<E> _source; | 444 Iterable<E> _source; |
443 /** Create an unmodifiable list backed by [source]. */ | 445 /** Create an unmodifiable list backed by [source]. */ |
444 UnmodifiableListView(Iterable<E> source) : _source = source; | 446 UnmodifiableListView(Iterable<E> source) : _source = source; |
445 int get length => _source.length; | 447 int get length => _source.length; |
446 E operator[](int index) => _source.elementAt(index); | 448 E operator[](int index) => _source.elementAt(index); |
447 } | 449 } |
OLD | NEW |