| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 class GrowableObjectArray<T> implements List<T> { | 5 class GrowableObjectArray<T> implements List<T> { |
| 6 factory GrowableObjectArray._uninstantiable() { | 6 factory GrowableObjectArray._uninstantiable() { |
| 7 throw const UnsupportedOperationException( | 7 throw const UnsupportedOperationException( |
| 8 "GrowableObjectArray can only be allocated by the VM"); | 8 "GrowableObjectArray can only be allocated by the VM"); |
| 9 } | 9 } |
| 10 | 10 |
| 11 T removeAt(int index) { | 11 T removeAt(int index) { |
| 12 if (index is! int) throw new IllegalArgumentException(index); | 12 if (index is! int) throw new IllegalArgumentException(index); |
| 13 T result = this[index]; | 13 T result = this[index]; |
| 14 int newLength = this.length - 1; | 14 int newLength = this.length - 1; |
| 15 Arrays.copy(this, | 15 Arrays.copy(this, |
| 16 index + 1, | 16 index + 1, |
| 17 this, | 17 this, |
| 18 index, | 18 index, |
| 19 newLength - index); | 19 newLength - index); |
| 20 this.length = newLength; | 20 this.length = newLength; |
| 21 return result; | 21 return result; |
| 22 } | 22 } |
| 23 | 23 |
| 24 void setRange(int start, int length, List<T> from, [int startFrom = 0]) { | 24 void setRange(int start, int length, List<T> from, [int startFrom = 0]) { |
| 25 if (length < 0) { | 25 if (length < 0) { |
| 26 throw new IllegalArgumentException("negative length $length"); | 26 throw new IllegalArgumentException("negative length $length"); |
| 27 } | 27 } |
| 28 Arrays.copy(from, startFrom, this, start, length); | 28 Arrays.copy(from, startFrom, this, start, length); |
| 29 } | 29 } |
| 30 | 30 |
| 31 void removeRange(int start, int length) { | 31 void removeRange(int start, int length) { |
| 32 if (length == 0) { | 32 if (length == 0) { |
| 33 return; | 33 return; |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 } | 132 } |
| 133 | 133 |
| 134 void addAll(Collection<T> collection) { | 134 void addAll(Collection<T> collection) { |
| 135 for (T elem in collection) { | 135 for (T elem in collection) { |
| 136 add(elem); | 136 add(elem); |
| 137 } | 137 } |
| 138 } | 138 } |
| 139 | 139 |
| 140 T removeLast() { | 140 T removeLast() { |
| 141 var len = length - 1; | 141 var len = length - 1; |
| 142 if (len < 0) { | |
| 143 throw new IndexOutOfRangeException(-1); | |
| 144 } | |
| 145 var elem = this[len]; | 142 var elem = this[len]; |
| 146 this[len] = null; | 143 this[len] = null; |
| 147 _setLength(len); | 144 _setLength(len); |
| 148 return elem; | 145 return elem; |
| 149 } | 146 } |
| 150 | 147 |
| 151 T last() { | 148 T last() { |
| 152 if (length === 0) { | |
| 153 throw new IndexOutOfRangeException(-1); | |
| 154 } | |
| 155 return this[length - 1]; | 149 return this[length - 1]; |
| 156 } | 150 } |
| 157 | 151 |
| 158 int indexOf(T element, [int start = 0]) { | 152 int indexOf(T element, [int start = 0]) { |
| 159 return Arrays.indexOf(this, element, start, length); | 153 return Arrays.indexOf(this, element, start, length); |
| 160 } | 154 } |
| 161 | 155 |
| 162 int lastIndexOf(T element, [int start = null]) { | 156 int lastIndexOf(T element, [int start = null]) { |
| 163 if (start === null) start = length - 1; | 157 if (start === null) start = length - 1; |
| 164 return Arrays.lastIndexOf(this, element, start); | 158 return Arrays.lastIndexOf(this, element, start); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 T next() { | 234 T next() { |
| 241 if (!hasNext()) { | 235 if (!hasNext()) { |
| 242 throw const NoMoreElementsException(); | 236 throw const NoMoreElementsException(); |
| 243 } | 237 } |
| 244 return _array[_pos++]; | 238 return _array[_pos++]; |
| 245 } | 239 } |
| 246 | 240 |
| 247 final GrowableObjectArray<T> _array; | 241 final GrowableObjectArray<T> _array; |
| 248 int _pos; | 242 int _pos; |
| 249 } | 243 } |
| OLD | NEW |