| 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._collection.dev; | 5 part of dart._collection.dev; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * Class implementing the read-operations on [List]. | 8 * Class implementing the read-operations on [List]. |
| 9 * | 9 * |
| 10 * Implements all read-only operations, except [:operator[]:] and [:length:], | 10 * Implements all read-only operations, except [:operator[]:] and [:length:], |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 | 22 |
| 23 // Iterable interface. | 23 // Iterable interface. |
| 24 E elementAt(int index) { | 24 E elementAt(int index) { |
| 25 return this[index]; | 25 return this[index]; |
| 26 } | 26 } |
| 27 | 27 |
| 28 Map<int, E> asMap() { | 28 Map<int, E> asMap() { |
| 29 return new ListMapView(this); | 29 return new ListMapView(this); |
| 30 } | 30 } |
| 31 | 31 |
| 32 List<E> getRange(int start, int length) { | 32 List<E> sublist(int start, [int end]) { |
| 33 if (end == null) end = length; |
| 33 if (start < 0 || start > this.length) { | 34 if (start < 0 || start > this.length) { |
| 34 throw new RangeError.range(start, 0, this.length); | 35 throw new RangeError.range(start, 0, this.length); |
| 35 } | 36 } |
| 36 if (length < 0 || start + length > this.length) { | 37 if (end < start || end > this.length) { |
| 37 throw new RangeError.range(length, 0, this.length - start); | 38 throw new RangeError.range(end, start, this.length); |
| 38 } | 39 } |
| 39 List<E> result = new List<E>(length); | 40 int length = end - start; |
| 41 List<E> result = new List<E>()..length = length; |
| 40 for (int i = 0; i < length; i++) { | 42 for (int i = 0; i < length; i++) { |
| 41 result[i] = this[start + i]; | 43 result[i] = this[start + i]; |
| 42 } | 44 } |
| 43 return result; | 45 return result; |
| 44 } | 46 } |
| 45 | 47 |
| 48 List<E> getRange(int start, int length) => sublist(start, start + length); |
| 49 |
| 46 int indexOf(E element, [int start = 0]) { | 50 int indexOf(E element, [int start = 0]) { |
| 47 return Arrays.indexOf(this, element, start, this.length); | 51 return Arrays.indexOf(this, element, start, this.length); |
| 48 } | 52 } |
| 49 | 53 |
| 50 int lastIndexOf(E element, [int start = null]) { | 54 int lastIndexOf(E element, [int start = null]) { |
| 51 if (start == null) start = length - 1; | 55 if (start == null) start = length - 1; |
| 52 return Arrays.lastIndexOf(this, element, start); | 56 return Arrays.lastIndexOf(this, element, start); |
| 53 } | 57 } |
| 54 | 58 |
| 55 Iterable<E> get reversed => new ReversedListIterable(this); | 59 Iterable<E> get reversed => new ReversedListIterable(this); |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 } | 332 } |
| 329 | 333 |
| 330 E remove(int key) { | 334 E remove(int key) { |
| 331 throw new UnsupportedError("Cannot modify an unmodifiable map"); | 335 throw new UnsupportedError("Cannot modify an unmodifiable map"); |
| 332 } | 336 } |
| 333 | 337 |
| 334 void clear() { | 338 void clear() { |
| 335 throw new UnsupportedError("Cannot modify an unmodifiable map"); | 339 throw new UnsupportedError("Cannot modify an unmodifiable map"); |
| 336 } | 340 } |
| 337 } | 341 } |
| OLD | NEW |