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

Side by Side Diff: runtime/lib/array.dart

Issue 8276005: Implement List.getRange. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 9 years, 2 months 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
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 class ArrayFactory<T> { 5 class ArrayFactory<T> {
6 factory Array.from(Iterable<T> other) { 6 factory Array.from(Iterable<T> other) {
7 GrowableObjectArray<T> array = new GrowableObjectArray<T>(); 7 GrowableObjectArray<T> array = new GrowableObjectArray<T>();
8 for (final e in other) { 8 for (final e in other) {
9 array.add(e); 9 array.add(e);
10 } 10 }
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 void removeRange(int start, int length) { 100 void removeRange(int start, int length) {
101 throw const UnsupportedOperationException( 101 throw const UnsupportedOperationException(
102 "Cannot remove range of a non-extendable array"); 102 "Cannot remove range of a non-extendable array");
103 } 103 }
104 104
105 void insertRange(int start, int length, [T initialValue = null]) { 105 void insertRange(int start, int length, [T initialValue = null]) {
106 throw const NotImplementedException(); 106 throw const NotImplementedException();
107 } 107 }
108 108
109 List<T> getRange(int start, int length) { 109 List<T> getRange(int start, int length) {
110 throw const NotImplementedException(); 110 if (length == 0) return [];
111 Arrays.rangeCheck(this, start, length);
112 return new List<T>.fromList(this, start, start + length);
111 } 113 }
112 114
113 /** 115 /**
114 * Collection interface. 116 * Collection interface.
115 */ 117 */
116 118
117 void forEach(f(T element)) { 119 void forEach(f(T element)) {
118 Collections.forEach(this, f); 120 Collections.forEach(this, f);
119 } 121 }
120 122
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 void removeRange(int start, int length) { 218 void removeRange(int start, int length) {
217 throw const UnsupportedOperationException( 219 throw const UnsupportedOperationException(
218 "Cannot remove range of an immutable array"); 220 "Cannot remove range of an immutable array");
219 } 221 }
220 222
221 void insertRange(int start, int length, [T initialValue = null]) { 223 void insertRange(int start, int length, [T initialValue = null]) {
222 throw const NotImplementedException(); 224 throw const NotImplementedException();
223 } 225 }
224 226
225 List<T> getRange(int start, int length) { 227 List<T> getRange(int start, int length) {
226 throw const NotImplementedException(); 228 if (length == 0) return [];
229 Arrays.rangeCheck(this, start, length);
230 return new List<T>.fromList(this, start, start + length);
227 } 231 }
228 232
229 /** 233 /**
230 * Collection interface. 234 * Collection interface.
231 */ 235 */
232 236
233 void forEach(f(T element)) { 237 void forEach(f(T element)) {
234 Collections.forEach(this, f); 238 Collections.forEach(this, f);
235 } 239 }
236 240
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 if (!hasNext()) { 325 if (!hasNext()) {
322 throw const NoMoreElementsException(); 326 throw const NoMoreElementsException();
323 } 327 }
324 return _array[_pos++]; 328 return _array[_pos++];
325 } 329 }
326 330
327 final Array<T> _array; 331 final Array<T> _array;
328 final int _length; // Cache array length for faster access. 332 final int _length; // Cache array length for faster access.
329 int _pos; 333 int _pos;
330 } 334 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698