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

Unified Diff: runtime/lib/byte_array.dart

Issue 10391056: - Typed arrays should implement all methods from Collection and List interfaces. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/lib/byte_array.dart
===================================================================
--- runtime/lib/byte_array.dart (revision 7508)
+++ runtime/lib/byte_array.dart (working copy)
@@ -240,6 +240,49 @@
abstract class _ByteArrayBase {
+
+ // Methods implementing the Collection interface.
+
+ void forEach(void f(element)) {
+ var len = this.length;
+ for (var i = 0; i < len; i++) {
+ f(this[i]);
+ }
+ }
+
+ Collection map(f(element)) {
+ return Collections.map(this,
+ new GrowableObjectArray.withCapacity(length),
Anders Johnsen 2012/05/11 08:38:54 This could be end up slowing down some users code.
+ f);
+ }
+
+ Collection filter(bool f(element)) {
+ return Collections.filter(this, new GrowableObjectArray(), f);
Anders Johnsen 2012/05/11 08:38:54 Ditto.
+ }
+
+ bool every(bool f(element)) {
+ return Collections.every(this, f);
+ }
+
+ bool some(bool f(element)) {
+ return Collections.some(this, f);;
+ }
+
+ bool isEmpty() {
+ return this.length === 0;
+ }
+
+ int get length() {
+ return _length();
+ }
+
+ // Methods implementing the List interface.
+
+ set length(newLength) {
+ throw const UnsupportedOperationException(
+ "Cannot resize a non-extendable array");
+ }
+
void add(value) {
throw const UnsupportedOperationException(
"Cannot add to a non-extendable array");
@@ -255,30 +298,22 @@
"Cannot add to a non-extendable array");
}
- void clear() {
- throw const UnsupportedOperationException(
- "Cannot remove from a non-extendable array");
+ void sort(int compare(a, b)) {
+ DualPivotQuicksort.sort(this, compare);
}
int indexOf(element, [int start = 0]) {
- for (int i = start; i < length; i++) {
- if (this[i] == element) return i;
- }
- return -1;
+ return Arrays.indexOf(this, element, start, this.length);
}
- void insertRange(int start, int length, [initialValue]) {
- throw const UnsupportedOperationException(
- "Cannot add to a non-extendable array");
+ int lastIndexOf(element, [int start = null]) {
+ if (start === null) start = length - 1;
+ return Arrays.lastIndexOf(this, element, start);
}
- int get length() {
- return _length();
- }
-
- set length(newLength) {
+ void clear() {
throw const UnsupportedOperationException(
- "Cannot resize a non-extendable array");
+ "Cannot remove from a non-extendable array");
}
int removeLast() {
@@ -286,11 +321,20 @@
"Cannot remove from a non-extendable array");
}
+ last() {
+ return this[length - 1];
+ }
+
void removeRange(int start, int length) {
throw const UnsupportedOperationException(
"Cannot remove from a non-extendable array");
}
+ void insertRange(int start, int length, [initialValue]) {
+ throw const UnsupportedOperationException(
+ "Cannot add to a non-extendable array");
+ }
+
ByteArray asByteArray([int start = 0, int length]) {
if (length === null) {
length = this.lengthInBytes();
@@ -1647,6 +1691,49 @@
class _ByteArrayViewBase {
+
+ // Methods implementing the Collection interface.
+
+ void forEach(void f(element)) {
+ var len = this.length;
+ for (var i = 0; i < len; i++) {
+ f(this[i]);
+ }
+ }
+
+ Collection map(f(element)) {
+ return Collections.map(this,
+ new GrowableObjectArray.withCapacity(length),
+ f);
+ }
+
+ Collection filter(bool f(element)) {
+ return Collections.filter(this, new GrowableObjectArray(), f);
+ }
+
+ bool every(bool f(element)) {
+ return Collections.every(this, f);
+ }
+
+ bool some(bool f(element)) {
+ return Collections.some(this, f);;
+ }
+
+ bool isEmpty() {
+ return this.length === 0;
+ }
+
+ int get length() {
+ return _length();
+ }
+
+ // Methods implementing the List interface.
+
+ set length(newLength) {
+ throw const UnsupportedOperationException(
+ "Cannot resize a non-extendable array");
+ }
+
void add(value) {
throw const UnsupportedOperationException(
"Cannot add to a non-extendable array");
@@ -1662,19 +1749,22 @@
"Cannot add to a non-extendable array");
}
- void clear() {
- throw const UnsupportedOperationException(
- "Cannot remove from a non-extendable array");
+ void sort(int compare(a, b)) {
+ DualPivotQuicksort.sort(this, compare);
}
- void insertRange(int start, int length, [initialValue]) {
- throw const UnsupportedOperationException(
- "Cannot add to a non-extendable array");
+ int indexOf(element, [int start = 0]) {
+ return Arrays.indexOf(this, element, start, this.length);
}
- set length(int newLength) {
+ int lastIndexOf(element, [int start = null]) {
+ if (start === null) start = length - 1;
+ return Arrays.lastIndexOf(this, element, start);
+ }
+
+ void clear() {
throw const UnsupportedOperationException(
- "Cannot resize a non-extendable array");
+ "Cannot remove from a non-extendable array");
}
int removeLast() {
@@ -1682,10 +1772,19 @@
"Cannot remove from a non-extendable array");
}
+ last() {
+ return this[length - 1];
+ }
+
void removeRange(int start, int length) {
throw const UnsupportedOperationException(
"Cannot remove from a non-extendable array");
}
+
+ void insertRange(int start, int length, [initialValue]) {
+ throw const UnsupportedOperationException(
+ "Cannot add to a non-extendable array");
+ }
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698