| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 /** | |
| 6 * A [List] is an indexable collection with a length. It can be of | |
| 7 * fixed size or extendable. | |
| 8 */ | |
| 9 interface List<E> extends Collection<E> default ListImplementation<E> { | |
| 10 | |
| 11 /** | |
| 12 * Creates a list of the given [length]. | |
| 13 */ | |
| 14 List([int length]); | |
| 15 | |
| 16 /** | |
| 17 * Creates a list with the elements of [other]. The order in | |
| 18 * the list will be the order provided by the iterator of [other]. | |
| 19 */ | |
| 20 List.from(Iterable<E> other); | |
| 21 | |
| 22 /** | |
| 23 * Returns the element at the given [index] in the list or throws | |
| 24 * an [IndexOutOfRangeException] if [index] is out of bounds. | |
| 25 */ | |
| 26 E operator [](int index); | |
| 27 | |
| 28 /** | |
| 29 * Sets the entry at the given [index] in the list to [value]. | |
| 30 * Throws an [IndexOutOfRangeException] if [index] is out of bounds. | |
| 31 */ | |
| 32 void operator []=(int index, E value); | |
| 33 | |
| 34 /** | |
| 35 * Changes the length of the list. If [newLength] is greater than | |
| 36 * the current [length], entries are initialized to [:null:]. Throws | |
| 37 * an [UnsupportedOperationException] if the list is not extendable. | |
| 38 */ | |
| 39 void set length(int newLength); | |
| 40 | |
| 41 /** | |
| 42 * Adds [value] at the end of the list, extending the length by | |
| 43 * one. Throws an [UnsupportedOperationException] if the list is not | |
| 44 * extendable. | |
| 45 */ | |
| 46 void add(E value); | |
| 47 | |
| 48 /** | |
| 49 * Adds [value] at the end of the list, extending the length by | |
| 50 * one. Throws an [UnsupportedOperationException] if the list is not | |
| 51 * extendable. | |
| 52 */ | |
| 53 void addLast(E value); | |
| 54 | |
| 55 /** | |
| 56 * Appends all elements of the [collection] to the end of the list. | |
| 57 * Extends the length of the list by the length of [collection]. | |
| 58 * Throws an [UnsupportedOperationException] if the list is not | |
| 59 * extendable. | |
| 60 */ | |
| 61 void addAll(Collection<E> collection); | |
| 62 | |
| 63 /** | |
| 64 * Sorts the list according to the order specified by the comparator. | |
| 65 * The order specified by the comparator must be reflexive, | |
| 66 * anti-symmetric, and transitive. | |
| 67 * | |
| 68 * The comparator function [compare] must take two arguments [a] and [b] | |
| 69 * and return | |
| 70 * | |
| 71 * an integer strictly less than 0 if a < b, | |
| 72 * 0 if a = b, and | |
| 73 * an integer strictly greater than 0 if a > b. | |
| 74 */ | |
| 75 void sort(int compare(E a, E b)); | |
| 76 | |
| 77 /** | |
| 78 * Returns the first index of [element] in the list. Searches the | |
| 79 * list from index [start] to the length of the list. Returns | |
| 80 * -1 if [element] is not found. | |
| 81 */ | |
| 82 int indexOf(E element, [int start]); | |
| 83 | |
| 84 /** | |
| 85 * Returns the last index of [element] in the list. Searches the | |
| 86 * list from index [start] (inclusive) to 0. Returns -1 if | |
| 87 * [element] is not found. | |
| 88 */ | |
| 89 int lastIndexOf(E element, [int start]); | |
| 90 | |
| 91 /** | |
| 92 * Removes all elements in the list. The length of the list | |
| 93 * becomes zero. Throws an [UnsupportedOperationException] if | |
| 94 * the list is not extendable. | |
| 95 */ | |
| 96 void clear(); | |
| 97 | |
| 98 /** | |
| 99 * Pops and returns the last element of the list. | |
| 100 * Throws a [UnsupportedOperationException] if the length of the | |
| 101 * list cannot be changed. | |
| 102 */ | |
| 103 E removeLast(); | |
| 104 | |
| 105 /** | |
| 106 * Returns the last element of the list, or throws an out of bounds | |
| 107 * exception if the list is empty. | |
| 108 */ | |
| 109 E last(); | |
| 110 | |
| 111 /** | |
| 112 * Returns a new list containing [length] elements from the list, | |
| 113 * starting at [start]. | |
| 114 * Returns an empty list if [length] is 0. | |
| 115 * Throws an [IllegalArgumentException] if [length] is negative. | |
| 116 * Throws an [IndexOutOfRangeException] if [start] or | |
| 117 * [:start + length - 1:] are out of range. | |
| 118 */ | |
| 119 List<E> getRange(int start, int length); | |
| 120 | |
| 121 /** | |
| 122 * Copies [length] elements of [from], starting | |
| 123 * at [startFrom], into the list, starting at [start]. | |
| 124 * If [length] is 0, this method does not do anything. | |
| 125 * Throws an [IllegalArgumentException] if [length] is negative. | |
| 126 * Throws an [IndexOutOfRangeException] if [start] or | |
| 127 * [:start + length - 1:] are out of range for [:this:], or if | |
| 128 * [startFrom] or [:startFrom + length - 1:] are out of range for [from]. | |
| 129 */ | |
| 130 void setRange(int start, int length, List<E> from, [int startFrom]); | |
| 131 | |
| 132 /** | |
| 133 * Removes [length] elements from the list, beginning at [start]. | |
| 134 * Throws an [UnsupportedOperationException] if the list is | |
| 135 * not extendable. | |
| 136 * If [length] is 0, this method does not do anything. | |
| 137 * Throws an [IllegalArgumentException] if [length] is negative. | |
| 138 * Throws an [IndexOutOfRangeException] if [start] or | |
| 139 * [:start + length: - 1] are out of range. | |
| 140 */ | |
| 141 void removeRange(int start, int length); | |
| 142 | |
| 143 /** | |
| 144 * Inserts a new range into the list, starting from [start] to | |
| 145 * [:start + length - 1:]. The entries are filled with [initialValue]. | |
| 146 * Throws an [UnsupportedOperationException] if the list is | |
| 147 * not extendable. | |
| 148 * If [length] is 0, this method does not do anything. | |
| 149 * If [start] is the length of the list, this method inserts the | |
| 150 * range at the end of the list. | |
| 151 * Throws an [IllegalArgumentException] if [length] is negative. | |
| 152 * Throws an [IndexOutOfRangeException] if [start] is negative or if | |
| 153 * [start] is greater than the length of the list. | |
| 154 */ | |
| 155 void insertRange(int start, int length, [E initialValue]); | |
| 156 } | |
| OLD | NEW |