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

Side by Side Diff: sdk/lib/core/iterable.dart

Issue 745573002: Create generic check methods for RangeError causing checks. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix long line Created 6 years, 1 month 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/core/errors.dart ('k') | sdk/lib/core/string.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) 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 dart.core; 5 part of dart.core;
6 6
7 /** 7 /**
8 * An object that uses an [Iterator] to serve objects one at a time. 8 * An object that uses an [Iterator] to serve objects one at a time.
9 * 9 *
10 * You can iterate over all objects served by an Iterable object 10 * You can iterate over all objects served by an Iterable object
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 * Returns true if there is no element in this collection. 194 * Returns true if there is no element in this collection.
195 */ 195 */
196 bool get isEmpty; 196 bool get isEmpty;
197 197
198 /** 198 /**
199 * Returns true if there is at least one element in this collection. 199 * Returns true if there is at least one element in this collection.
200 */ 200 */
201 bool get isNotEmpty; 201 bool get isNotEmpty;
202 202
203 /** 203 /**
204 * Returns an [Iterable] with at most [n] elements. 204 * Returns an [Iterable] with at most [count] elements.
205 * 205 *
206 * The returned [Iterable] may contain fewer than [n] elements, if `this` 206 * The returned `Iterable` may contain fewer than `count` elements, if `this`
207 * contains fewer than [n] elements. 207 * contains fewer than `count` elements.
208 * 208 *
209 * It is an error if [n] is negative. 209 * It is an error if `count` is negative.
210 */ 210 */
211 Iterable<E> take(int n); 211 Iterable<E> take(int count);
212 212
213 /** 213 /**
214 * Returns an Iterable that stops once [test] is not satisfied anymore. 214 * Returns an Iterable that stops once [test] is not satisfied anymore.
215 * 215 *
216 * The filtering happens lazily. Every new Iterator of the returned 216 * The filtering happens lazily. Every new Iterator of the returned
217 * Iterable starts iterating over the elements of `this`. 217 * Iterable starts iterating over the elements of `this`.
218 * 218 *
219 * When the iterator encounters an element `e` that does not satisfy [test], 219 * When the iterator encounters an element `e` that does not satisfy [test],
220 * it discards `e` and moves into the finished state. That is, it does not 220 * it discards `e` and moves into the finished state. That is, it does not
221 * get or provide any more elements. 221 * get or provide any more elements.
222 */ 222 */
223 Iterable<E> takeWhile(bool test(E value)); 223 Iterable<E> takeWhile(bool test(E value));
224 224
225 /** 225 /**
226 * Returns an Iterable that skips the first [n] elements. 226 * Returns an Iterable that skips the first [count] elements.
227 * 227 *
228 * If `this` has fewer than [n] elements, then the resulting Iterable is 228 * If `this` has fewer than `count` elements, then the resulting Iterable is
229 * empty. 229 * empty.
230 * 230 *
231 * It is an error if [n] is negative. 231 * It is an error if `count` is negative.
232 */ 232 */
233 Iterable<E> skip(int n); 233 Iterable<E> skip(int count);
234 234
235 /** 235 /**
236 * Returns an Iterable that skips elements while [test] is satisfied. 236 * Returns an Iterable that skips elements while [test] is satisfied.
237 * 237 *
238 * The filtering happens lazily. Every new Iterator of the returned 238 * The filtering happens lazily. Every new Iterator of the returned
239 * Iterable iterates over all elements of `this`. 239 * Iterable iterates over all elements of `this`.
240 * 240 *
241 * As long as the iterator's elements satisfy [test] they are 241 * As long as the iterator's elements satisfy [test] they are
242 * discarded. Once an element does not satisfy the [test] the iterator stops 242 * discarded. Once an element does not satisfy the [test] the iterator stops
243 * testing and uses every later element unconditionally. That is, the elements 243 * testing and uses every later element unconditionally. That is, the elements
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 _GeneratorIterable(this._end, E generator(int n)) 314 _GeneratorIterable(this._end, E generator(int n))
315 : _start = 0, 315 : _start = 0,
316 _generator = (generator != null) ? generator : _id; 316 _generator = (generator != null) ? generator : _id;
317 317
318 _GeneratorIterable.slice(this._start, this._end, this._generator); 318 _GeneratorIterable.slice(this._start, this._end, this._generator);
319 319
320 Iterator<E> get iterator => 320 Iterator<E> get iterator =>
321 new _GeneratorIterator<E>(_start, _end, _generator); 321 new _GeneratorIterator<E>(_start, _end, _generator);
322 int get length => _end - _start; 322 int get length => _end - _start;
323 323
324 Iterable<E> skip(int n) { 324 Iterable<E> skip(int count) {
325 if (n < 0) throw new RangeError.value(n); 325 RangeError.checkNotNegative(count, "count");
326 if (n == 0) return this; 326 if (count == 0) return this;
327 int newStart = _start + n; 327 int newStart = _start + count;
328 if (newStart >= _end) return new EmptyIterable<E>(); 328 if (newStart >= _end) return new EmptyIterable<E>();
329 return new _GeneratorIterable<E>.slice(newStart, _end, _generator); 329 return new _GeneratorIterable<E>.slice(newStart, _end, _generator);
330 } 330 }
331 331
332 Iterable<E> take(int n) { 332 Iterable<E> take(int count) {
333 if (n < 0) throw new RangeError.value(n); 333 RangeError.checkNotNegative(count, "count");
334 if (n == 0) return new EmptyIterable<E>(); 334 if (count == 0) return new EmptyIterable<E>();
335 int newEnd = _start + n; 335 int newEnd = _start + count;
336 if (newEnd >= _end) return this; 336 if (newEnd >= _end) return this;
337 return new _GeneratorIterable<E>.slice(_start, newEnd, _generator); 337 return new _GeneratorIterable<E>.slice(_start, newEnd, _generator);
338 } 338 }
339 339
340 static int _id(int n) => n; 340 static int _id(int n) => n;
341 } 341 }
342 342
343 class _GeneratorIterator<E> implements Iterator<E> { 343 class _GeneratorIterator<E> implements Iterator<E> {
344 final int _end; 344 final int _end;
345 final _Generator<E> _generator; 345 final _Generator<E> _generator;
(...skipping 21 matching lines...) Expand all
367 */ 367 */
368 abstract class BidirectionalIterator<E> implements Iterator<E> { 368 abstract class BidirectionalIterator<E> implements Iterator<E> {
369 /** 369 /**
370 * Move back to the previous element. 370 * Move back to the previous element.
371 * 371 *
372 * Returns true and updates [current] if successful. Returns false 372 * Returns true and updates [current] if successful. Returns false
373 * and sets [current] to null if there is no previous element. 373 * and sets [current] to null if there is no previous element.
374 */ 374 */
375 bool movePrevious(); 375 bool movePrevious();
376 } 376 }
OLDNEW
« no previous file with comments | « sdk/lib/core/errors.dart ('k') | sdk/lib/core/string.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698