OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 protobuf; | 5 part of protobuf; |
6 | 6 |
7 class PbList<E> extends Object with ListMixin<E> implements List<E> { | 7 class PbList<E> extends Object with ListMixin<E> implements List<E> { |
8 | 8 |
9 PbList() : _wrappedList = <E>[]; | 9 PbList() : _wrappedList = <E>[]; |
10 | 10 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 _wrappedList.addAll(collection); | 81 _wrappedList.addAll(collection); |
82 } | 82 } |
83 | 83 |
84 /** | 84 /** |
85 * Copies [:end - start:] elements of the [from] array, starting | 85 * Copies [:end - start:] elements of the [from] array, starting |
86 * from [skipCount], into [:this:], starting at [start]. | 86 * from [skipCount], into [:this:], starting at [start]. |
87 * Throws an [UnsupportedError] if the list is | 87 * Throws an [UnsupportedError] if the list is |
88 * not extendable. | 88 * not extendable. |
89 */ | 89 */ |
90 void setRange(int start, int end, Iterable<E> from, [int skipCount = 0]) { | 90 void setRange(int start, int end, Iterable<E> from, [int skipCount = 0]) { |
91 from.sublist(skipCount, skipCount + end - start).forEach(_validate); | 91 // NOTE: In case `take()` returns less than `end - start` elements, the |
| 92 // _wrappedList will fail with a `StateError`. |
| 93 from.skip(skipCount).take(end - start).forEach(_validate); |
92 _wrappedList.setRange(start, end, from, skipCount); | 94 _wrappedList.setRange(start, end, from, skipCount); |
93 } | 95 } |
94 | 96 |
95 /** | 97 /** |
96 * Inserts a new element in the list. | 98 * Inserts a new element in the list. |
97 * The element must be valid (and not nullable) for the PbList type. | 99 * The element must be valid (and not nullable) for the PbList type. |
98 */ | 100 */ |
99 void insert(int index, E element) { | 101 void insert(int index, E element) { |
100 _validate(element); | 102 _validate(element); |
101 _wrappedList.insert(index, element); | 103 _wrappedList.insert(index, element); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 * [:-3.4E38, 3.4E38:], i.e., with the IEEE single-precision range. | 202 * [:-3.4E38, 3.4E38:], i.e., with the IEEE single-precision range. |
201 */ | 203 */ |
202 class PbFloatList extends PbList<double> { | 204 class PbFloatList extends PbList<double> { |
203 void _validateElement(double val) { | 205 void _validateElement(double val) { |
204 if (!_isFloat32(val)) { | 206 if (!_isFloat32(val)) { |
205 throw new ArgumentError('Illegal to add value (${val}):' | 207 throw new ArgumentError('Illegal to add value (${val}):' |
206 ' out of range for float'); | 208 ' out of range for float'); |
207 } | 209 } |
208 } | 210 } |
209 } | 211 } |
OLD | NEW |