Adding push/shift operations to JsArray* classes.
Review by: knorton
git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@5200 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/gwt/core/client/JsArray.java b/user/src/com/google/gwt/core/client/JsArray.java
index 4008079..9fa56f5 100644
--- a/user/src/com/google/gwt/core/client/JsArray.java
+++ b/user/src/com/google/gwt/core/client/JsArray.java
@@ -1,12 +1,12 @@
/*
* Copyright 2008 Google Inc.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
@@ -18,10 +18,10 @@
/**
* A simple wrapper around a homogeneous native array of
* {@link JavaScriptObject} values.
- *
+ *
* This class may not be directly instantiated, and can only be returned from a
* native method. For example,
- *
+ *
* <code>
* native JsArray<JavaScriptObject> getNativeArray() /*-{
* return [
@@ -31,7 +31,7 @@
* ];
* }-* /;
* </code>
- *
+ *
* @param <T> the concrete type of object contained in this array
*/
public class JsArray<T extends JavaScriptObject> extends JavaScriptObject {
@@ -41,7 +41,7 @@
/**
* Gets the object at a given index.
- *
+ *
* @param index the index to be retrieved
* @return the object at the given index, or <code>null</code> if none
* exists
@@ -52,7 +52,7 @@
/**
* Gets the length of the array.
- *
+ *
* @return the array length
*/
public final native int length() /*-{
@@ -60,15 +60,31 @@
}-*/;
/**
+ * Pushes the given value onto the end of the array.
+ */
+ public final native void push(T value) /*-{
+ this[this.length] = value;
+ }-*/;
+
+ /**
* Sets the object value at a given index.
- *
+ *
* If the index is out of bounds, the value will still be set. The array's
* length will be updated to encompass the bounds implied by the added object.
- *
+ *
* @param index the index to be set
* @param value the object to be stored
*/
public final native void set(int index, T value) /*-{
this[index] = value;
}-*/;
+
+ /**
+ * Shifts the first value off the array.
+ * @return the shifted value
+ */
+ public final native T shift() /*-{
+ return this.shift();
+ }-*/;
+
}
diff --git a/user/src/com/google/gwt/core/client/JsArrayBoolean.java b/user/src/com/google/gwt/core/client/JsArrayBoolean.java
index 80bb05e..27b57b8 100644
--- a/user/src/com/google/gwt/core/client/JsArrayBoolean.java
+++ b/user/src/com/google/gwt/core/client/JsArrayBoolean.java
@@ -1,12 +1,12 @@
/*
* Copyright 2008 Google Inc.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
@@ -17,10 +17,10 @@
/**
* A simple wrapper around a homogeneous native array of boolean values.
- *
+ *
* This class may not be directly instantiated, and can only be returned from a
* native method. For example,
- *
+ *
* <code>
* native JsArrayBoolean getNativeArray() /*-{
* return [true, false, true];
@@ -34,21 +34,21 @@
/**
* Gets the value at a given index.
- *
+ *
* If an undefined or non-boolean value exists at the given index, a
* type-conversion error will occur in hosted mode and unpredictable behavior
* may occur in web mode.
- *
+ *
* @param index the index to be retrieved
* @return the value at the given index
*/
public final native boolean get(int index) /*-{
return this[index];
}-*/;
-
+
/**
* Gets the length of the array.
- *
+ *
* @return the array length
*/
public final native int length() /*-{
@@ -56,15 +56,31 @@
}-*/;
/**
+ * Pushes the given boolean onto the end of the array.
+ */
+ public final native void push(boolean value) /*-{
+ this[this.length] = value;
+ }-*/;
+
+ /**
* Sets the value value at a given index.
- *
+ *
* If the index is out of bounds, the value will still be set. The array's
* length will be updated to encompass the bounds implied by the added value.
- *
+ *
* @param index the index to be set
* @param value the value to be stored
*/
public final native void set(int index, boolean value) /*-{
this[index] = value;
}-*/;
+
+ /**
+ * Shifts the first value off the array.
+ * @return the shifted value
+ */
+ public final native boolean shift() /*-{
+ return this.shift();
+ }-*/;
+
}
diff --git a/user/src/com/google/gwt/core/client/JsArrayInteger.java b/user/src/com/google/gwt/core/client/JsArrayInteger.java
index eef3150..65b0bb2 100644
--- a/user/src/com/google/gwt/core/client/JsArrayInteger.java
+++ b/user/src/com/google/gwt/core/client/JsArrayInteger.java
@@ -1,12 +1,12 @@
/*
* Copyright 2008 Google Inc.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
@@ -17,10 +17,10 @@
/**
* A simple wrapper around a homogeneous native array of integer values.
- *
+ *
* This class may not be directly instantiated, and can only be returned from a
* native method. For example,
- *
+ *
* <code>
* native JsArrayInteger getNativeArray() /*-{
* return [1, 2, 3];
@@ -34,12 +34,12 @@
/**
* Gets the value at a given index.
- *
+ *
* If no value exists at the given index, a type-conversion error will occur
* in hosted mode and unpredictable behavior may occur in web mode. If the
* numeric value returned is non-integral, it will cause a warning in hosted
* mode, and may affect the results of mathematical expressions.
- *
+ *
* @param index the index to be retrieved
* @return the value at the given index
*/
@@ -49,7 +49,7 @@
/**
* Gets the length of the array.
- *
+ *
* @return the array length
*/
public final native int length() /*-{
@@ -57,15 +57,30 @@
}-*/;
/**
+ * Pushes the given integer onto the end of the array.
+ */
+ public final native void push(int value) /*-{
+ this[this.length] = value;
+ }-*/;
+
+ /**
* Sets the value value at a given index.
- *
+ *
* If the index is out of bounds, the value will still be set. The array's
* length will be updated to encompass the bounds implied by the added value.
- *
+ *
* @param index the index to be set
* @param value the value to be stored
*/
public final native void set(int index, int value) /*-{
this[index] = value;
}-*/;
+
+ /**
+ * Shifts the first value off the array.
+ * @return the shifted value
+ */
+ public final native int shift() /*-{
+ return this.shift();
+ }-*/;
}
diff --git a/user/src/com/google/gwt/core/client/JsArrayNumber.java b/user/src/com/google/gwt/core/client/JsArrayNumber.java
index c6822d3..406fc6b 100644
--- a/user/src/com/google/gwt/core/client/JsArrayNumber.java
+++ b/user/src/com/google/gwt/core/client/JsArrayNumber.java
@@ -1,12 +1,12 @@
/*
* Copyright 2008 Google Inc.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
@@ -17,13 +17,13 @@
/**
* A simple wrapper around a homogeneous native array of numeric values.
- *
+ *
* All native JavaScript numeric values are implicitly double-precision, so only
* double values may be set and retrieved.
- *
+ *
* This class may not be directly instantiated, and can only be returned from a
* native method. For example,
- *
+ *
* <code>
* native JsArrayNumber getNativeArray() /*-{
* return [1.1, 2.2, 3.3];
@@ -31,17 +31,17 @@
* </code>
*/
public class JsArrayNumber extends JavaScriptObject {
-
+
protected JsArrayNumber() {
}
/**
* Gets the value at a given index.
- *
+ *
* If an undefined or non-numeric value exists at the given index, a
* type-conversion error will occur in hosted mode and unpredictable behavior
* may occur in web mode.
- *
+ *
* @param index the index to be retrieved
* @return the value at the given index
*/
@@ -51,23 +51,39 @@
/**
* Gets the length of the array.
- *
+ *
* @return the array length
*/
public final native int length() /*-{
return this.length;
}-*/;
+
+ /**
+ * Pushes the given number onto the end of the array.
+ */
+ public final native void push(double value) /*-{
+ this[this.length] = value;
+ }-*/;
+
/**
* Sets the value value at a given index.
- *
+ *
* If the index is out of bounds, the value will still be set. The array's
* length will be updated to encompass the bounds implied by the added value.
- *
+ *
* @param index the index to be set
* @param value the value to be stored
*/
public final native void set(int index, double value) /*-{
this[index] = value;
}-*/;
+
+ /**
+ * Shifts the first value off the array.
+ * @return the shifted value
+ */
+ public final native double shift() /*-{
+ return this.shift();
+ }-*/;
}
diff --git a/user/src/com/google/gwt/core/client/JsArrayString.java b/user/src/com/google/gwt/core/client/JsArrayString.java
index d2b1de3..9518c12 100644
--- a/user/src/com/google/gwt/core/client/JsArrayString.java
+++ b/user/src/com/google/gwt/core/client/JsArrayString.java
@@ -1,12 +1,12 @@
/*
* Copyright 2008 Google Inc.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
@@ -17,10 +17,10 @@
/**
* A simple wrapper around a homogeneous native array of string values.
- *
+ *
* This class may not be directly instantiated, and can only be returned from a
* native method. For example,
- *
+ *
* <code>
* native JsArrayString getNativeArray() /*-{
* return ['foo', 'bar', 'baz'];
@@ -34,7 +34,7 @@
/**
* Gets the value at a given index.
- *
+ *
* @param index the index to be retrieved
* @return the value at the given index, or <code>null</code> if none exists
*/
@@ -44,7 +44,7 @@
/**
* Gets the length of the array.
- *
+ *
* @return the array length
*/
public final native int length() /*-{
@@ -52,15 +52,30 @@
}-*/;
/**
+ * Pushes the given value onto the end of the array.
+ */
+ public final native void push(String value) /*-{
+ this[this.length] = value;
+ }-*/;
+
+ /**
* Sets the value value at a given index.
- *
+ *
* If the index is out of bounds, the value will still be set. The array's
* length will be updated to encompass the bounds implied by the added value.
- *
+ *
* @param index the index to be set
* @param value the value to be stored
*/
public final native void set(int index, String value) /*-{
this[index] = value;
}-*/;
+
+ /**
+ * Shifts the first value off the array.
+ * @return the shifted value
+ */
+ public final native String shift() /*-{
+ return this.shift();
+ }-*/;
}