OLD | NEW |
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 /** | 5 /** |
6 * Wrappers that prevent List, Set, or Map objects from being modified. | 6 * Wrappers that prevent List, Set, or Map objects from being modified. |
7 * | 7 * |
8 * The [Set] and [Map] wrappers allow reading from the wrapped collection, | 8 * The [Set] and [Map] wrappers allow reading from the wrapped collection, |
9 * but prohibit writing. | 9 * but prohibit writing. |
10 * | 10 * |
11 * The [List] wrapper prevents changes to the length of the wrapped list, | 11 * The [List] wrapper prevents changes to the length of the wrapped list, |
12 * but allows changes to the contents. | 12 * but allows changes to the contents. |
13 */ | 13 */ |
14 library unmodifiable_collection; | 14 library unmodifiable_collection; |
15 | 15 |
| 16 import "dart:math" show Random; |
16 export "dart:collection" show UnmodifiableListView; | 17 export "dart:collection" show UnmodifiableListView; |
17 | 18 |
18 /** | 19 /** |
19 * A fixed-length list. | 20 * A fixed-length list. |
20 * | 21 * |
21 * A NonGrowableListView contains a [List] object and ensures that | 22 * A NonGrowableListView contains a [List] object and ensures that |
22 * its length does not change. | 23 * its length does not change. |
23 * Methods that would change the length of the list, | 24 * Methods that would change the length of the list, |
24 * such as [add] and [remove], throw an [UnsupportedError]. | 25 * such as [add] and [remove], throw an [UnsupportedError]. |
25 * | 26 * |
(...skipping 25 matching lines...) Expand all Loading... |
51 List<E> sublist(int start, [int end]) => _source.sublist(start, end); | 52 List<E> sublist(int start, [int end]) => _source.sublist(start, end); |
52 | 53 |
53 Iterable<E> get reversed => _source.reversed; | 54 Iterable<E> get reversed => _source.reversed; |
54 | 55 |
55 Map<int, E> asMap() => _source.asMap(); | 56 Map<int, E> asMap() => _source.asMap(); |
56 | 57 |
57 void operator []=(int index, E value) { _source[index] = value; } | 58 void operator []=(int index, E value) { _source[index] = value; } |
58 | 59 |
59 void sort([int compare(E a, E b)]) { _source.sort(compare); } | 60 void sort([int compare(E a, E b)]) { _source.sort(compare); } |
60 | 61 |
61 void shuffle() { _source.shuffle(); } | 62 void shuffle([Random random]) { _source.shuffle(random); } |
62 | 63 |
63 void setRange(int start, int end, Iterable<E> iterable, [int skipCount = 0]) { | 64 void setRange(int start, int end, Iterable<E> iterable, [int skipCount = 0]) { |
64 _source.setRange(start, end, iterable, skipCount); | 65 _source.setRange(start, end, iterable, skipCount); |
65 } | 66 } |
66 | 67 |
67 void fillRange(int start, int end, [E fillValue]) { | 68 void fillRange(int start, int end, [E fillValue]) { |
68 _source.fillRange(start, end, fillValue); | 69 _source.fillRange(start, end, fillValue); |
69 } | 70 } |
70 | 71 |
71 void setAll(int index, Iterable<E> iterable) { | 72 void setAll(int index, Iterable<E> iterable) { |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 Iterable<E> take(int n) => _source.take(n); | 350 Iterable<E> take(int n) => _source.take(n); |
350 | 351 |
351 Iterable<E> takeWhile(bool test(E value)) => _source.takeWhile(test); | 352 Iterable<E> takeWhile(bool test(E value)) => _source.takeWhile(test); |
352 | 353 |
353 List<E> toList({ bool growable: true }) => _source.toList(growable: growable); | 354 List<E> toList({ bool growable: true }) => _source.toList(growable: growable); |
354 | 355 |
355 Set<E> toSet() => _source.toSet(); | 356 Set<E> toSet() => _source.toSet(); |
356 | 357 |
357 Iterable<E> where(bool test(E element)) => _source.where(test); | 358 Iterable<E> where(bool test(E element)) => _source.where(test); |
358 } | 359 } |
OLD | NEW |