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

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

Issue 12391046: Add List.asMap(). (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 7 years, 9 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 | « sdk/lib/_internal/compiler/implementation/lib/js_array.dart ('k') | sdk/lib/core/list.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 if (from is! List) throw new ArgumentError(from); 377 if (from is! List) throw new ArgumentError(from);
378 if (startFrom is! int) throw new ArgumentError(startFrom); 378 if (startFrom is! int) throw new ArgumentError(startFrom);
379 if (length < 0) throw new ArgumentError(length); 379 if (length < 0) throw new ArgumentError(length);
380 if (start < 0) throw new RangeError.value(start); 380 if (start < 0) throw new RangeError.value(start);
381 if (start + length > list.length) { 381 if (start + length > list.length) {
382 throw new RangeError.value(start + length); 382 throw new RangeError.value(start + length);
383 } 383 }
384 384
385 Arrays.copy(from, startFrom, list, start, length); 385 Arrays.copy(from, startFrom, list, start, length);
386 } 386 }
387
388 static Map<int, dynamic> asMapList(List l) {
389 return new ListMapView(l);
390 }
387 } 391 }
388 392
389 class Collections { 393 class Collections {
390 static String collectionToString(Collection c) 394 static String collectionToString(Collection c)
391 => ToString.collectionToString(c); 395 => ToString.collectionToString(c);
392 } 396 }
393 397
394 /** 398 /**
395 * An unmodifiable [List] view of another List. 399 * An unmodifiable [List] view of another List.
396 * 400 *
397 * The source of the elements may be a [List] or any [Iterable] with 401 * The source of the elements may be a [List] or any [Iterable] with
398 * efficient [Iterable.length] and [Iterable.elementAt]. 402 * efficient [Iterable.length] and [Iterable.elementAt].
399 */ 403 */
400 class UnmodifiableListView<E> extends UnmodifiableListBase<E> { 404 class UnmodifiableListView<E> extends UnmodifiableListBase<E> {
401 Iterable<E> _source; 405 Iterable<E> _source;
402 /** Create an unmodifiable list backed by [source]. */ 406 /** Create an unmodifiable list backed by [source]. */
403 UnmodifiableListView(Iterable<E> source) : _source = source; 407 UnmodifiableListView(Iterable<E> source) : _source = source;
404 int get length => _source.length; 408 int get length => _source.length;
405 E operator[](int index) => _source.elementAt(index); 409 E operator[](int index) => _source.elementAt(index);
406 } 410 }
OLDNEW
« no previous file with comments | « sdk/lib/_internal/compiler/implementation/lib/js_array.dart ('k') | sdk/lib/core/list.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698