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

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

Issue 11727007: Add min and max to Iterable and Stream. (Closed) Base URL: https://dart.googlecode.com/svn/experimental/lib_v2/dart
Patch Set: Created 7 years, 11 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) 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 new UnsupportedError( 7 throw new UnsupportedError(
8 "GrowableObjectArray can only be allocated by the VM"); 8 "GrowableObjectArray can only be allocated by the VM");
9 } 9 }
10 10
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 if (length > 0) return this[length - 1]; 154 if (length > 0) return this[length - 1];
155 throw new StateError("No elements"); 155 throw new StateError("No elements");
156 } 156 }
157 157
158 T get single { 158 T get single {
159 if (length == 1) return this[0]; 159 if (length == 1) return this[0];
160 if (length == 0) throw new StateError("No elements"); 160 if (length == 0) throw new StateError("No elements");
161 throw new StateError("More than one element"); 161 throw new StateError("More than one element");
162 } 162 }
163 163
164 int min([int compare(int a, int b)]) => Collections.min(this, compare);
165
166 int max([int compare(int a, int b)]) => Collections.max(this, compare);
167
164 int indexOf(T element, [int start = 0]) { 168 int indexOf(T element, [int start = 0]) {
165 return Arrays.indexOf(this, element, start, length); 169 return Arrays.indexOf(this, element, start, length);
166 } 170 }
167 171
168 int lastIndexOf(T element, [int start = null]) { 172 int lastIndexOf(T element, [int start = null]) {
169 if (start == null) start = length - 1; 173 if (start == null) start = length - 1;
170 return Arrays.lastIndexOf(this, element, start); 174 return Arrays.lastIndexOf(this, element, start);
171 } 175 }
172 176
173 void _grow(int new_length) { 177 void _grow(int new_length) {
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 } 288 }
285 289
286 List<T> toList() { 290 List<T> toList() {
287 return new List<T>.from(this); 291 return new List<T>.from(this);
288 } 292 }
289 293
290 Set<T> toSet() { 294 Set<T> toSet() {
291 return new Set<T>.from(this); 295 return new Set<T>.from(this);
292 } 296 }
293 } 297 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698