| 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 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 if (start < 0 || start > list.length) { | 262 if (start < 0 || start > list.length) { |
| 263 throw new RangeError.range(start, 0, list.length); | 263 throw new RangeError.range(start, 0, list.length); |
| 264 } | 264 } |
| 265 if (end < start || end > list.length) { | 265 if (end < start || end > list.length) { |
| 266 throw new RangeError.range(end, start, list.length); | 266 throw new RangeError.range(end, start, list.length); |
| 267 } | 267 } |
| 268 // The generic type is currently lost. It will be fixed with mixins. | 268 // The generic type is currently lost. It will be fixed with mixins. |
| 269 return new SubListIterable(list, start, end); | 269 return new SubListIterable(list, start, end); |
| 270 } | 270 } |
| 271 | 271 |
| 272 static void setRangeList(List list, int start, int length, | 272 static void setRangeList(List list, int start, int end, |
| 273 List from, int startFrom) { | 273 Iterable from, int skipCount) { |
| 274 if (start < 0 || start > list.length) { |
| 275 throw new RangeError.range(start, 0, list.length); |
| 276 } |
| 277 if (end < start || end > list.length) { |
| 278 throw new RangeError.range(end, start, list.length); |
| 279 } |
| 280 int length = end - start; |
| 274 if (length == 0) return; | 281 if (length == 0) return; |
| 275 | 282 |
| 276 if (length < 0) throw new ArgumentError(length); | 283 if (skipCount < 0) throw new ArgumentError(skipCount); |
| 277 if (start < 0) throw new RangeError.value(start); | 284 |
| 278 if (start + length > list.length) { | 285 // TODO(floitsch): Make this accept more. |
| 279 throw new RangeError.value(start + length); | 286 List otherList; |
| 287 int otherStart; |
| 288 if (from is List) { |
| 289 otherList = from; |
| 290 otherStart = skipCount; |
| 291 } else { |
| 292 otherList = from.skip(skipCount).toList(growable: false); |
| 293 otherStart = 0; |
| 280 } | 294 } |
| 281 | 295 if (otherStart + length > otherList.length) { |
| 282 Arrays.copy(from, startFrom, list, start, length); | 296 throw new StateError("Not enough elements"); |
| 297 } |
| 298 Arrays.copy(otherList, otherStart, list, start, length); |
| 283 } | 299 } |
| 284 | 300 |
| 285 static Map<int, dynamic> asMapList(List l) { | 301 static Map<int, dynamic> asMapList(List l) { |
| 286 return new ListMapView(l); | 302 return new ListMapView(l); |
| 287 } | 303 } |
| 288 | 304 |
| 289 static bool setContainsAll(Set set, Iterable other) { | 305 static bool setContainsAll(Set set, Iterable other) { |
| 290 for (var element in other) { | 306 for (var element in other) { |
| 291 if (!set.contains(element)) return false; | 307 if (!set.contains(element)) return false; |
| 292 } | 308 } |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 * The source of the elements may be a [List] or any [Iterable] with | 349 * The source of the elements may be a [List] or any [Iterable] with |
| 334 * efficient [Iterable.length] and [Iterable.elementAt]. | 350 * efficient [Iterable.length] and [Iterable.elementAt]. |
| 335 */ | 351 */ |
| 336 class UnmodifiableListView<E> extends UnmodifiableListBase<E> { | 352 class UnmodifiableListView<E> extends UnmodifiableListBase<E> { |
| 337 Iterable<E> _source; | 353 Iterable<E> _source; |
| 338 /** Create an unmodifiable list backed by [source]. */ | 354 /** Create an unmodifiable list backed by [source]. */ |
| 339 UnmodifiableListView(Iterable<E> source) : _source = source; | 355 UnmodifiableListView(Iterable<E> source) : _source = source; |
| 340 int get length => _source.length; | 356 int get length => _source.length; |
| 341 E operator[](int index) => _source.elementAt(index); | 357 E operator[](int index) => _source.elementAt(index); |
| 342 } | 358 } |
| OLD | NEW |