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

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

Issue 1319783003: Add static ensure() methods to unmodifiable views. Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Code review changes Created 5 years, 3 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
« no previous file with comments | « CHANGELOG.md ('k') | sdk/lib/collection/maps.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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 * An unmodifiable [List] view of another List. 8 * An unmodifiable [List] view of another List.
9 * 9 *
10 * The source of the elements may be a [List] or any [Iterable] with 10 * The source of the elements may be a [List] or any [Iterable] with
11 * efficient [Iterable.length] and [Iterable.elementAt]. 11 * efficient [Iterable.length] and [Iterable.elementAt].
12 */ 12 */
13 class UnmodifiableListView<E> extends UnmodifiableListBase<E> { 13 class UnmodifiableListView<E> extends UnmodifiableListBase<E> {
14 final Iterable<E> _source; 14 final Iterable<E> _source;
15
15 /** Create an unmodifiable list backed by [source]. */ 16 /** Create an unmodifiable list backed by [source]. */
16 UnmodifiableListView(Iterable<E> source) : _source = source; 17 UnmodifiableListView(Iterable<E> source) : _source = source;
18
19 /**
20 * Returns a view of [source] that's guaranteed to be unmodifiable.
21 *
22 * If [source] already extends [UnmodifiableListBase] or
23 * [UnmodifiableListView], it is returned without re-wrapping it.
24 */
25 static List ensure(Iterable source) =>
26 source is UnmodifiableListBase
27 ? source
28 : new UnmodifiableListView(source);
29
17 int get length => _source.length; 30 int get length => _source.length;
18 E operator[](int index) => _source.elementAt(index); 31 E operator[](int index) => _source.elementAt(index);
19 } 32 }
OLDNEW
« no previous file with comments | « CHANGELOG.md ('k') | sdk/lib/collection/maps.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698