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

Side by Side Diff: sdk/lib/collection/collections.dart

Issue 14065011: Implement getRange (returning an Iterable). (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fixes and status-file update. 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
OLDNEW
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 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 static Iterable mapList(List list, f(var element)) { 315 static Iterable mapList(List list, f(var element)) {
316 return new MappedListIterable(list, f); 316 return new MappedListIterable(list, f);
317 } 317 }
318 318
319 static Iterable expand(Iterable iterable, Iterable f(var element)) { 319 static Iterable expand(Iterable iterable, Iterable f(var element)) {
320 return new ExpandIterable(iterable, f); 320 return new ExpandIterable(iterable, f);
321 } 321 }
322 322
323 static Iterable takeList(List list, int n) { 323 static Iterable takeList(List list, int n) {
324 // The generic type is currently lost. It will be fixed with mixins. 324 // The generic type is currently lost. It will be fixed with mixins.
325 // This is currently a List as well as an Iterable.
326 return new SubListIterable(list, 0, n); 325 return new SubListIterable(list, 0, n);
327 } 326 }
328 327
329 static Iterable takeWhile(Iterable iterable, bool test(var value)) { 328 static Iterable takeWhile(Iterable iterable, bool test(var value)) {
330 // The generic type is currently lost. It will be fixed with mixins. 329 // The generic type is currently lost. It will be fixed with mixins.
331 return new TakeWhileIterable(iterable, test); 330 return new TakeWhileIterable(iterable, test);
332 } 331 }
333 332
334 static Iterable skipList(List list, int n) { 333 static Iterable skipList(List list, int n) {
335 // The generic type is currently lost. It will be fixed with mixins. 334 // The generic type is currently lost. It will be fixed with mixins.
336 // This is currently a List as well as an Iterable.
337 return new SubListIterable(list, n, null); 335 return new SubListIterable(list, n, null);
338 } 336 }
339 337
340 static Iterable skipWhile(Iterable iterable, bool test(var value)) { 338 static Iterable skipWhile(Iterable iterable, bool test(var value)) {
341 // The generic type is currently lost. It will be fixed with mixins. 339 // The generic type is currently lost. It will be fixed with mixins.
342 return new SkipWhileIterable(iterable, test); 340 return new SkipWhileIterable(iterable, test);
343 } 341 }
344 342
345 static Iterable reversedList(List list) { 343 static Iterable reversedList(List list) {
346 return new ReversedListIterable(list); 344 return new ReversedListIterable(list);
347 } 345 }
348 346
349 static void sortList(List list, int compare(a, b)) { 347 static void sortList(List list, int compare(a, b)) {
350 if (compare == null) compare = Comparable.compare; 348 if (compare == null) compare = Comparable.compare;
351 Sort.sort(list, compare); 349 Sort.sort(list, compare);
352 } 350 }
353 351
354 static int indexOfList(List list, var element, int start) { 352 static int indexOfList(List list, var element, int start) {
355 return Arrays.indexOf(list, element, start, list.length); 353 return Arrays.indexOf(list, element, start, list.length);
356 } 354 }
357 355
358 static int lastIndexOfList(List list, var element, int start) { 356 static int lastIndexOfList(List list, var element, int start) {
359 if (start == null) start = list.length - 1; 357 if (start == null) start = list.length - 1;
360 return Arrays.lastIndexOf(list, element, start); 358 return Arrays.lastIndexOf(list, element, start);
361 } 359 }
362 360
361 static Iterable getRangeList(List list, int start, int end) {
362 if (start < 0 || start > list.length) {
363 throw new RangeError.range(start, 0, list.length);
364 }
365 if (end < start || end > list.length) {
366 throw new RangeError.range(end, start, list.length);
367 }
368 // The generic type is currently lost. It will be fixed with mixins.
369 return new SubListIterable(list, start, end);
370 }
371
363 static void setRangeList(List list, int start, int length, 372 static void setRangeList(List list, int start, int length,
364 List from, int startFrom) { 373 List from, int startFrom) {
365 if (length == 0) return; 374 if (length == 0) return;
366 375
367 if (length < 0) throw new ArgumentError(length); 376 if (length < 0) throw new ArgumentError(length);
368 if (start < 0) throw new RangeError.value(start); 377 if (start < 0) throw new RangeError.value(start);
369 if (start + length > list.length) { 378 if (start + length > list.length) {
370 throw new RangeError.value(start + length); 379 throw new RangeError.value(start + length);
371 } 380 }
372 381
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 * The source of the elements may be a [List] or any [Iterable] with 438 * The source of the elements may be a [List] or any [Iterable] with
430 * efficient [Iterable.length] and [Iterable.elementAt]. 439 * efficient [Iterable.length] and [Iterable.elementAt].
431 */ 440 */
432 class UnmodifiableListView<E> extends UnmodifiableListBase<E> { 441 class UnmodifiableListView<E> extends UnmodifiableListBase<E> {
433 Iterable<E> _source; 442 Iterable<E> _source;
434 /** Create an unmodifiable list backed by [source]. */ 443 /** Create an unmodifiable list backed by [source]. */
435 UnmodifiableListView(Iterable<E> source) : _source = source; 444 UnmodifiableListView(Iterable<E> source) : _source = source;
436 int get length => _source.length; 445 int get length => _source.length;
437 E operator[](int index) => _source.elementAt(index); 446 E operator[](int index) => _source.elementAt(index);
438 } 447 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698