| 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 part of dart._internal; | 5 part of dart._internal; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * Mixin that throws on the length changing operations of [List]. | 8 * Mixin that throws on the length changing operations of [List]. |
| 9 * | 9 * |
| 10 * Intended to mix-in on top of [ListMixin] for fixed-length lists. | 10 * Intended to mix-in on top of [ListMixin] for fixed-length lists. |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 class ReversedListIterable<E> extends ListIterable<E> { | 300 class ReversedListIterable<E> extends ListIterable<E> { |
| 301 Iterable<E> _source; | 301 Iterable<E> _source; |
| 302 ReversedListIterable(this._source); | 302 ReversedListIterable(this._source); |
| 303 | 303 |
| 304 int get length => _source.length; | 304 int get length => _source.length; |
| 305 | 305 |
| 306 E elementAt(int index) => _source.elementAt(_source.length - 1 - index); | 306 E elementAt(int index) => _source.elementAt(_source.length - 1 - index); |
| 307 } | 307 } |
| 308 | 308 |
| 309 /** | 309 /** |
| 310 * Creates errors thrown by unmodifiable lists when they are attempted modified. |
| 311 * |
| 312 * This class creates [UnsupportedError]s with specialized messages. |
| 313 */ |
| 314 abstract class UnmodifiableListError { |
| 315 /** Error thrown when trying to add elements to an unmodifiable list. */ |
| 316 static UnsupportedError add() |
| 317 => new UnsupportedError("Cannot add to unmodifiable List"); |
| 318 |
| 319 /** Error thrown when trying to add elements to an unmodifiable list. */ |
| 320 static UnsupportedError change() |
| 321 => new UnsupportedError( |
| 322 "Cannot change the content of an unmodifiable List"); |
| 323 |
| 324 /** Error thrown when trying to change the length of an unmodifiable list. */ |
| 325 static UnsupportedError length() |
| 326 => new UnsupportedError("Cannot change length of unmodifiable List"); |
| 327 |
| 328 /** Error thrown when trying to remove elements from an unmodifiable list. */ |
| 329 static UnsupportedError remove() |
| 330 => new UnsupportedError("Cannot remove from unmodifiable List"); |
| 331 } |
| 332 |
| 333 /** |
| 334 * Creates errors thrown by non-growable lists when they are attempted modified. |
| 335 * |
| 336 * This class creates [UnsupportedError]s with specialized messages. |
| 337 */ |
| 338 abstract class NonGrowableListError { |
| 339 /** Error thrown when trying to add elements to an non-growable list. */ |
| 340 static UnsupportedError add() |
| 341 => new UnsupportedError("Cannot add to non-growable List"); |
| 342 |
| 343 /** Error thrown when trying to change the length of an non-growable list. */ |
| 344 static UnsupportedError length() |
| 345 => new UnsupportedError("Cannot change length of non-growable List"); |
| 346 |
| 347 /** Error thrown when trying to remove elements from an non-growable list. */ |
| 348 static UnsupportedError remove() |
| 349 => new UnsupportedError("Cannot remove from non-growable List"); |
| 350 } |
| 351 |
| 352 /** |
| 310 * Converts a growable list to a fixed length list with the same elements. | 353 * Converts a growable list to a fixed length list with the same elements. |
| 311 * | 354 * |
| 312 * For internal use only. | 355 * For internal use only. |
| 313 * Only works on growable lists as created by `[]` or `new List()`. | 356 * Only works on growable lists as created by `[]` or `new List()`. |
| 314 * May throw on any other list. | 357 * May throw on any other list. |
| 315 * | 358 * |
| 316 * The operation is efficient. It doesn't copy the elements, but converts | 359 * The operation is efficient. It doesn't copy the elements, but converts |
| 317 * the existing list directly to a fixed length list. | 360 * the existing list directly to a fixed length list. |
| 318 * That means that it is a destructive conversion. | 361 * That means that it is a destructive conversion. |
| 319 * The original list should not be used afterwards. | 362 * The original list should not be used afterwards. |
| 320 * | 363 * |
| 321 * The returned list may be the same list as the orginal, | 364 * The returned list may be the same list as the orginal, |
| 322 * or it may be a different list (according to [identical]). | 365 * or it may be a different list (according to [identical]). |
| 323 * The original list may have changed type to be a fixed list, | 366 * The original list may have changed type to be a fixed list, |
| 324 * or become empty or been otherwise modified. | 367 * or become empty or been otherwise modified. |
| 325 * It will still be a valid object, so references to it will not, e.g., crash | 368 * It will still be a valid object, so references to it will not, e.g., crash |
| 326 * the runtime if accessed, but no promises are made wrt. its contents. | 369 * the runtime if accessed, but no promises are made wrt. its contents. |
| 327 * | 370 * |
| 328 * This unspecified behavior is the reason the function is not exposed to | 371 * This unspecified behavior is the reason the function is not exposed to |
| 329 * users. We allow the underlying implementation to make the most efficient | 372 * users. We allow the underlying implementation to make the most efficient |
| 330 * conversion, at the cost of leaving the original list in an unspecified | 373 * conversion, at the cost of leaving the original list in an unspecified |
| 331 * state. | 374 * state. |
| 332 */ | 375 */ |
| 333 external List makeListFixedLength(List growableList); | 376 external List makeListFixedLength(List growableList); |
| OLD | NEW |