Revision: 8298
Author: rchan...@google.com
Date: Mon Jun 14 06:05:16 2010
Log: Implemented Array and descendants as overlay types. Simplified Assertion convenience methods. Fixed code style issues.
Review at http://gwt-code-reviews.appspot.com/605801

Review by: r...@google.com
http://code.google.com/p/google-web-toolkit/source/detail?r=8298

Added:
/branches/lwc-gwt-migration/bikeshed/super/com/google/gwt/collections/super/com/google/gwt/collections/Array.java /branches/lwc-gwt-migration/bikeshed/super/com/google/gwt/collections/super/com/google/gwt/collections/CollectionFactory.java /branches/lwc-gwt-migration/bikeshed/super/com/google/gwt/collections/super/com/google/gwt/collections/ImmutableArray.java /branches/lwc-gwt-migration/bikeshed/super/com/google/gwt/collections/super/com/google/gwt/collections/ImmutableArrayEmptyImpl.java /branches/lwc-gwt-migration/bikeshed/test/com/google/gwt/collections/ImmutableArrayInternalTest.java
Modified:
/branches/lwc-gwt-migration/bikeshed/src/com/google/gwt/collections/Assertions.java /branches/lwc-gwt-migration/bikeshed/src/com/google/gwt/collections/CollectionFactory.java /branches/lwc-gwt-migration/bikeshed/src/com/google/gwt/collections/ImmutableArrayEmptyImpl.java /branches/lwc-gwt-migration/bikeshed/src/com/google/gwt/collections/ImmutableArrayImpl.java /branches/lwc-gwt-migration/bikeshed/src/com/google/gwt/collections/MutableArray.java /branches/lwc-gwt-migration/bikeshed/super/com/google/gwt/collections/super/com/google/gwt/collections/ImmutableArrayImpl.java /branches/lwc-gwt-migration/bikeshed/super/com/google/gwt/collections/super/com/google/gwt/collections/MutableArray.java /branches/lwc-gwt-migration/bikeshed/test/com/google/gwt/collections/CollectionsServerSideTestSuite.java /branches/lwc-gwt-migration/bikeshed/test/com/google/gwt/collections/ImmutableArrayTest.java /branches/lwc-gwt-migration/bikeshed/test/com/google/gwt/collections/MutableArrayTest.java /branches/lwc-gwt-migration/bikeshed/test-super/com/google/gwt/collections/super/com/google/gwt/collections/MutableArrayInternalTest.java

=======================================
--- /dev/null
+++ /branches/lwc-gwt-migration/bikeshed/super/com/google/gwt/collections/super/com/google/gwt/collections/Array.java Mon Jun 14 06:05:16 2010
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2009 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
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.google.gwt.collections;
+
+import com.google.gwt.core.client.JavaScriptObject;
+
+/**
+ * The root Array type that provides read-access to an array that might still
+ * be mutable by another actor.
+ *
+ * @param <E> The type stored in the array elements
+ */
+public abstract class Array<E> extends JavaScriptObject {
+
+  protected Array() {
+  }
+
+  @ConstantTime
+  public final E get(int index) {
+    Assertions.assertIndexInRange(index, 0, size());
+    return jsniGet(index);
+  }
+
+  @ConstantTime
+  public final native int size() /*-{
+    return this.length;
+  }-*/;
+
+  @ConstantTime
+  private native E jsniGet(int index) /*-{
+    return this[index];
+  }-*/;
+
+}
=======================================
--- /dev/null
+++ /branches/lwc-gwt-migration/bikeshed/super/com/google/gwt/collections/super/com/google/gwt/collections/CollectionFactory.java Mon Jun 14 06:05:16 2010
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2009 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
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.google.gwt.collections;
+
+import com.google.gwt.core.client.JavaScriptObject;
+
+/**
+ * Made to be switched out using super source even while Collections itself isn't.
+ */
+public class CollectionFactory {
+
+  public static <E> MutableArray<E> createMutableArray() {
+    return JavaScriptObject.createArray().<MutableArray<E>>cast();
+  }
+
+ public static <E> MutableArray<E> createMutableArray(int size, E fillValue) {
+    MutableArray<E> r = createMutableArray();
+    r.setSize(size, fillValue);
+    return r;
+  }
+
+  public static <V> MutableStringMap<V> createMutableStringMap() {
+    return new MutableStringMap<V>();
+  }
+
+}
=======================================
--- /dev/null
+++ /branches/lwc-gwt-migration/bikeshed/super/com/google/gwt/collections/super/com/google/gwt/collections/ImmutableArray.java Mon Jun 14 06:05:16 2010
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2009 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
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.google.gwt.collections;
+
+/**
+ * An array that is guaranteed not to change, thus making it safe for disparate + * portions of code to maintain references to a shared instance, rather than
+ * feeling the need to make defensive copies.
+ *
+ * @param <E> The type stored in the array elements
+ */
+public abstract class ImmutableArray<E> extends Array<E> {
+
+  protected ImmutableArray() {
+  }
+
+}
=======================================
--- /dev/null
+++ /branches/lwc-gwt-migration/bikeshed/super/com/google/gwt/collections/super/com/google/gwt/collections/ImmutableArrayEmptyImpl.java Mon Jun 14 06:05:16 2010
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2009 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
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.google.gwt.collections;
+
+/**
+ * Blank super implementation. This class is unused in JSNI version.
+ *
+ * @param <E> unused.
+ */
+class ImmutableArrayEmptyImpl<E> extends ImmutableArray<E> {
+
+  protected ImmutableArrayEmptyImpl() {
+  }
+
+}
=======================================
--- /dev/null
+++ /branches/lwc-gwt-migration/bikeshed/test/com/google/gwt/collections/ImmutableArrayInternalTest.java Mon Jun 14 06:05:16 2010
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2009 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
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.google.gwt.collections;
+
+import com.google.gwt.junit.client.GWTTestCase;
+
+/**
+ * Tests mutable array implementation internal details.
+ */
+public class ImmutableArrayInternalTest extends GWTTestCase {
+
+  @Override
+  public String getModuleName() {
+    return null;
+  }
+
+  public void testImmutableNoCopy() {
+    MutableArray<String> ma = CollectionFactory.createMutableArray();
+    ma.add("pear");
+    ma.add("apple");
+ ImmutableArrayImpl<String> ia1 = (ImmutableArrayImpl<String>) ma.freeze();
+
+    assertTrue(ma.elems == ia1.elems);
+
+ ImmutableArrayImpl<String> ia2 = (ImmutableArrayImpl<String>) ma.freeze();
+
+    assertTrue(ia1.elems == ia2.elems);
+  }
+
+}
=======================================
--- /branches/lwc-gwt-migration/bikeshed/src/com/google/gwt/collections/Assertions.java Tue Jun 22 12:49:14 2010 +++ /branches/lwc-gwt-migration/bikeshed/src/com/google/gwt/collections/Assertions.java Mon Jun 14 06:05:16 2010
@@ -20,13 +20,17 @@
  */
 class Assertions {

-  static void assertGetFromImmutableEmpty() {
- assert false : "Attempt to get an element from an immutable empty array";
-  }
+  /**
+ * Message for asserting that access to an empty array is an illegal operation.
+   */
+  public static final String ACCESS_EMPTY_ARRAY_MESSAGE =
+    "Attempt to access an element in an empty array";

static void assertIndexInRange(int index, int minInclusive, int maxExclusive) {
+    assert minInclusive < maxExclusive : ACCESS_EMPTY_ARRAY_MESSAGE;
assert (index >= minInclusive && index < maxExclusive) : "Index " + index - + " was not in the acceptable range [" + minInclusive + ", " + maxExclusive + ")";
+        + " was not in the acceptable range [" + minInclusive + ", "
+        + maxExclusive + ")";
   }

   static <E> void assertNotFrozen(MutableArray<E> a) {
=======================================
--- /branches/lwc-gwt-migration/bikeshed/src/com/google/gwt/collections/CollectionFactory.java Tue Jun 22 12:49:14 2010 +++ /branches/lwc-gwt-migration/bikeshed/src/com/google/gwt/collections/CollectionFactory.java Mon Jun 14 06:05:16 2010
@@ -16,20 +16,40 @@
 package com.google.gwt.collections;

 /**
- * Made to be switched out using super source even while Collections itself isn't.
+ * Made to be switched out using super source even while Collections itself
+ * isn't.
  */
 public class CollectionFactory {

+  /**
+   * Creates an empty {...@link MutableArray}.
+   * @param <E> type of elements in the array
+   * @return an empty {...@code MutableArray}
+   */
   public static <E> MutableArray<E> createMutableArray() {
     return new MutableArray<E>();
   }

+  /**
+   * Creates a {...@link MutableArray} with {...@code size} references to 
{...@code
+   * fillValue}.
+   *
+   * @param <E> type of elements in the array
+   * @param size size of the array
+   * @param fillValue initial value to use for the elements
+   * @return a {...@code MutableArray}
+   */
public static <E> MutableArray<E> createMutableArray(int size, E fillValue) {
     MutableArray<E> r = new MutableArray<E>();
     r.setSize(size, fillValue);
     return r;
   }

+  /**
+   * Creates an empty {...@link MutableStringMap}.
+   * @param <V> type of elements in the map
+   * @return an empty {...@code MutableStringMap}
+   */
   public static <V> MutableStringMap<V> createMutableStringMap() {
     return new MutableStringMap<V>();
   }
=======================================
--- /branches/lwc-gwt-migration/bikeshed/src/com/google/gwt/collections/ImmutableArrayEmptyImpl.java Tue Jun 22 12:49:14 2010 +++ /branches/lwc-gwt-migration/bikeshed/src/com/google/gwt/collections/ImmutableArrayEmptyImpl.java Mon Jun 14 06:05:16 2010
@@ -23,13 +23,14 @@
 class ImmutableArrayEmptyImpl<E> extends ImmutableArray<E> {

   @Override
-  public E get(int index) {
-    Assertions.assertGetFromImmutableEmpty();
+  public final E get(int index) {
+    // Get always fails for an empty array
+    Assertions.assertIndexInRange(index, 0, 0);
     return null;
   }

   @Override
-  public int size() {
+  public final int size() {
     return 0;
   }

=======================================
--- /branches/lwc-gwt-migration/bikeshed/src/com/google/gwt/collections/ImmutableArrayImpl.java Tue Jun 22 12:49:14 2010 +++ /branches/lwc-gwt-migration/bikeshed/src/com/google/gwt/collections/ImmutableArrayImpl.java Mon Jun 14 06:05:16 2010
@@ -30,13 +30,13 @@
   }

   @Override
-  public E get(int index) {
+  public final E get(int index) {
     Assertions.assertIndexInRange(index, 0, elems.length);
     return elems[index];
   }

   @Override
-  public int size() {
+  public final int size() {
     return elems.length;
   }

=======================================
--- /branches/lwc-gwt-migration/bikeshed/src/com/google/gwt/collections/MutableArray.java Tue Jun 22 12:49:14 2010 +++ /branches/lwc-gwt-migration/bikeshed/src/com/google/gwt/collections/MutableArray.java Mon Jun 14 06:05:16 2010
@@ -22,7 +22,7 @@
  *
  * @param <E> The type stored in the array elements
  */
-public class MutableArray<E> extends Array<E> {
+public final class MutableArray<E> extends Array<E> {

   // TODO: refactor the unchecked elems construction into a separate method
   // The elements in the array
@@ -34,7 +34,7 @@
   /**
    * Can only be constructed via {...@link CollectionFactory}.
    */
-  MutableArray() {
+  protected MutableArray() {
   }

   @ConstantTime
@@ -49,10 +49,10 @@
   }

   /**
- * Creates an immutable array based on this one. Also marks this object as read-only. - * After calling {...@code freeze()}, only use methods from {...@link Array} or the returned
-   * {...@link ImmutableArray} should be to access the elements
-   * of the array is preferred.
+   * Creates an {...@link ImmutableArray} with the contents of this {...@code
+ * MutableArray}. Also marks this {...@link MutableArray} as read-only. After + * calling {...@code freeze()}, only use read-only methods to access the elements
+   * in the array.
    */
   public ImmutableArray<E> freeze() {
     Assertions.markFrozen(this);
@@ -79,7 +79,7 @@
   }

   /**
-   * Inserts {...@code element} before the element residing at {...@code 
index}.
+   * Inserts {...@code elem} before the element residing at {...@code index}.
    *
* @param index in the range [0, this.size()], inclusive; if index is equal * to the array's current size, the result is equivalent to calling
=======================================
--- /branches/lwc-gwt-migration/bikeshed/super/com/google/gwt/collections/super/com/google/gwt/collections/ImmutableArrayImpl.java Tue Jun 22 12:49:14 2010 +++ /branches/lwc-gwt-migration/bikeshed/super/com/google/gwt/collections/super/com/google/gwt/collections/ImmutableArrayImpl.java Mon Jun 14 06:05:16 2010
@@ -15,8 +15,6 @@
  */
 package com.google.gwt.collections;

-import com.google.gwt.core.client.JsArray;
-
 /**
  * The standard JSNI implementation of an immutable array.
  *
@@ -24,26 +22,7 @@
  */
 public class ImmutableArrayImpl<E> extends ImmutableArray<E> {

-  final JsArray elems;
-
-  ImmutableArrayImpl(JsArray elems) {
-    Assertions.assertNotNull(elems);
-    this.elems = elems;
-  }
-
-  @Override
-  public E get(int index) {
-    Assertions.assertIndexInRange(index, 0, size());
-    return jsniGet(index);
-  }
-
-  @Override
-  public int size() {
-    return elems.length();
-  }
-
-  private native E jsniGet(int index) /*-{
- return th...@com.google.gwt.collections.immutablearrayimpl::elems[index];
-  }-*/;
+  protected ImmutableArrayImpl() {
+  }

 }
=======================================
--- /branches/lwc-gwt-migration/bikeshed/super/com/google/gwt/collections/super/com/google/gwt/collections/MutableArray.java Tue Jun 22 12:49:14 2010 +++ /branches/lwc-gwt-migration/bikeshed/super/com/google/gwt/collections/super/com/google/gwt/collections/MutableArray.java Mon Jun 14 06:05:16 2010
@@ -15,26 +15,18 @@
  */
 package com.google.gwt.collections;

-import com.google.gwt.core.client.JavaScriptObject;
-import com.google.gwt.core.client.JsArray;
-
 /**
* An array whose content and length can change over time. This implementation
  * is used in web mode.
  *
  * @param <E> The type stored in the array elements
  */
-public class MutableArray<E> extends Array<E> {
-
-  JsArray elems;
-
-  private boolean frozen;
+public final class MutableArray<E> extends Array<E> {

   /**
    * Can only be constructed via {...@link CollectionFactory}.
    */
-  MutableArray() {
-    elems = (JsArray) JavaScriptObject.createArray();
+  protected MutableArray() {
   }

   @ConstantTime
@@ -46,33 +38,22 @@
   @ConstantTime
   public void clear() {
     Assertions.assertNotFrozen(this);
-    elems.setLength(0);
+    jsniClear();
   }

   /**
- * Creates an immutable array based on this one. Also marks this object as
-   * read-only. After calling {...@code freeze()}, only use methods from
- * {...@link Array} or the returned {...@link ImmutableArray} should be to access
-   * the elements of the array is preferred.
+   * Creates an {...@link ImmutableArray} with the contents of this {...@code
+ * MutableArray}. Also marks this {...@link MutableArray} as read-only. After + * calling {...@code freeze()}, only use read-only methods to access the elements
+   * in the array.
    */
   public ImmutableArray<E> freeze() {
     Assertions.markFrozen(this);
-    if (size() != 0) {
-      return new ImmutableArrayImpl(elems);
-    } else {
-      return ImmutableArray.getEmptyInstance();
-    }
-  }
-
-  @Override
-  @ConstantTime
-  public E get(int index) {
-    Assertions.assertIndexInRange(index, 0, size());
-    return jsniGet(index);
+    return this.<ImmutableArray<E>>cast();
   }

   /**
-   * Inserts {...@code element} before the element residing at {...@code 
index}.
+   * Inserts {...@code elem} before the element residing at {...@code index}.
    *
* @param index in the range [0, this.size()], inclusive; if index is equal to
    *          the array's current size, the result is equivalent to calling
@@ -82,7 +63,9 @@
   @LinearTime
   public void insert(int index, E elem) {
     Assertions.assertNotFrozen(this);
-    Assertions.assertIndexInRange(index, 0, size() + 1);
+    // TODO: fix gwtc to optimize away Assertions.assertIndexInRange
+    assert (index >= 0 && index < size() + 1) : "Index " + index
+ + " was not in the acceptable range [" + 0 + ", " + (size() + 1) + ")";
     jsniInsert(index, elem);
   }

@@ -92,7 +75,10 @@
   @LinearTime
   public void remove(int index) {
     Assertions.assertNotFrozen(this);
-    Assertions.assertIndexInRange(index, 0, size());
+    // TODO: fix gwtc to optimize away Assertions.assertIndexInRange
+    assert 0 < size() : Assertions.ACCESS_EMPTY_ARRAY_MESSAGE;
+    assert (index >= 0 && index < size()) : "Index " + index
+        + " was not in the acceptable range [" + 0 + ", " + size() + ")";
     jsniRemove(index);
   }

@@ -105,7 +91,10 @@
   @ConstantTime
   public void set(int index, E elem) {
     Assertions.assertNotFrozen(this);
-    Assertions.assertIndexInRange(index, 0, size());
+    // TODO: fix gwtc to optimize away Assertions.assertIndexInRange
+    assert 0 < size() : Assertions.ACCESS_EMPTY_ARRAY_MESSAGE;
+    assert (index >= 0 && index < size()) : "Index " + index
+        + " was not in the acceptable range [" + 0 + ", " + size() + ")";

     jsniSet(index, elem);
   }
@@ -121,44 +110,25 @@
     Assertions.assertNotFrozen(this);
     jsniSetSize(newSize, fillValue);
   }
-
-  @Override
-  @ConstantTime
-  public int size() {
-    return elems.length();
-  }

   // Only meant to be called from within Assertions
-  boolean isFrozen() {
-    return frozen;
-  }
+  native boolean isFrozen() /*-{
+    return !!this.frozen;
+  }-*/;

   // Only meant to be called from within Assertions
-  void markFrozen() {
-    frozen = true;
-  }
-
-  private Object[] copyNativeArray(JsArray jsElems) {
-    if (jsElems == null) {
-      return null;
-    }
-
-    Object[] jreElems = new Object[jsElems.length()];
-
-    for (int i = 0; i < jsElems.length(); ++i) {
-      jreElems[i] = jsElems.get(i);
-    }
-    return jreElems;
-  }
+  native void markFrozen() /*-{
+    this.frozen = true;
+  }-*/;

   @ConstantTime
   private native void jsniAdd(E elem) /*-{
-    th...@com.google.gwt.collections.mutablearray::elems.push(elem);
+    this.push(elem);
   }-*/;

   @ConstantTime
-  private native E jsniGet(int index) /*-{
-    return th...@com.google.gwt.collections.mutablearray::elems[index];
+  private native void jsniClear() /*-{
+    this.length = 0;
   }-*/;

   /**
@@ -171,7 +141,7 @@
    */
   @LinearTime
   private native void jsniInsert(int index, E elem) /*-{
- th...@com.google.gwt.collections.mutablearray::elems.splice(index, 0, elem);
+    this.splice(index, 0, elem);
   }-*/;

   /**
@@ -179,7 +149,7 @@
    */
   @LinearTime
   private native void jsniRemove(int index) /*-{
-    th...@com.google.gwt.collections.mutablearray::elems.splice(index, 1);
+    this.splice(index, 1);
   }-*/;

   /**
@@ -190,7 +160,7 @@
    */
   @ConstantTime
   private native void jsniSet(int index, E elem) /*-{
-    th...@com.google.gwt.collections.mutablearray::elems[index] = elem;
+    this[index] = elem;
   }-*/;

   /**
@@ -201,16 +171,11 @@
    */
   @LinearTime
   private native void jsniSetSize(int newSize, E fillValue) /*-{
-    var fillStart;
-    var i;
-
- fillStart = th...@com.google.gwt.collections.mutablearray::elems.length;
-
-    th...@com.google.gwt.collections.mutablearray::elems.length = newSize;
-
-    if (fillValue != null) {
-      for (i = fillStart; i < newSize; ++i) {
- th...@com.google.gwt.collections.mutablearray::elems[i] = fillValue;
+    if (fillValue == null) {
+      this.length = newSize;
+    } else {
+      for (var i = this.length; i < newSize; ++i) {
+        this[i] = fillValue;
       }
     }
   }-*/;
=======================================
--- /branches/lwc-gwt-migration/bikeshed/test/com/google/gwt/collections/CollectionsServerSideTestSuite.java Tue Jun 22 12:49:14 2010 +++ /branches/lwc-gwt-migration/bikeshed/test/com/google/gwt/collections/CollectionsServerSideTestSuite.java Mon Jun 14 06:05:16 2010
@@ -29,6 +29,7 @@
     suite.addTestSuite(MutableArrayTest.class);
     suite.addTestSuite(MutableArrayInternalTest.class);
     suite.addTestSuite(ImmutableArrayTest.class);
+    suite.addTestSuite(ImmutableArrayInternalTest.class);

     return suite;
   }
=======================================
--- /branches/lwc-gwt-migration/bikeshed/test/com/google/gwt/collections/ImmutableArrayTest.java Tue Jun 22 12:49:14 2010 +++ /branches/lwc-gwt-migration/bikeshed/test/com/google/gwt/collections/ImmutableArrayTest.java Mon Jun 14 06:05:16 2010
@@ -66,7 +66,7 @@
       ia.get(ia.size());
       fail("Expected an assertion failure");
     } catch (AssertionError e) {
- assertEquals("Attempt to get an element from an immutable empty array", e.getMessage()); + assertEquals("Attempt to access an element in an empty array", e.getMessage());
     }
   }

@@ -97,19 +97,6 @@
     assertEquals(1, ia.size());
     assertEquals("pear", ia.get(0));
   }
-
-  public void testImmutableNoCopy() {
-    MutableArray<String> ma = CollectionFactory.createMutableArray();
-    ma.add("pear");
-    ma.add("apple");
- ImmutableArrayImpl<String> ia1 = (ImmutableArrayImpl<String>) ma.freeze();
-
-    assertTrue(ma.elems == ia1.elems);
-
- ImmutableArrayImpl<String> ia2 = (ImmutableArrayImpl<String>) ma.freeze();
-
-    assertTrue(ia1.elems == ia2.elems);
-  }

   public void testModifyFrozenMutable() {
     // Do not test undefined behavior with assertions disabled
=======================================
--- /branches/lwc-gwt-migration/bikeshed/test/com/google/gwt/collections/MutableArrayTest.java Tue Jun 22 12:49:14 2010 +++ /branches/lwc-gwt-migration/bikeshed/test/com/google/gwt/collections/MutableArrayTest.java Mon Jun 14 06:05:16 2010
@@ -1,12 +1,12 @@
 /*
  * Copyright 2009 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
@@ -182,23 +182,23 @@
     b.setSize(0, null);
     assertEquals(0, b.size());
   }
-
+
   public void testSingleElementAddAndRemove() {
-      MutableArray<String> a = createMutableArray();
-
-      a.add("foo");
-
-      assertEquals(1, a.size());
-      assertEquals("foo", a.get(0));
-
-      a.remove(0);
-
-      assertEquals(0, a.size());
-
-      a.add("bar");
-
-      assertEquals(1, a.size());
-      assertEquals("bar", a.get(0));
+    MutableArray<String> a = createMutableArray();
+
+    a.add("foo");
+
+    assertEquals(1, a.size());
+    assertEquals("foo", a.get(0));
+
+    a.remove(0);
+
+    assertEquals(0, a.size());
+
+    a.add("bar");
+
+    assertEquals(1, a.size());
+    assertEquals("bar", a.get(0));
   }

   public void testSingleElementNull() {
@@ -236,8 +236,8 @@
       a.get(1);
       fail("That should have failed");
     } catch (AssertionError e) {
- assertEquals(("Index " + 1 + " was not in the acceptable range [" + 0 + ", " + 1 + ")"),
-          e.getMessage());
+      assertEquals(("Index " + 1 + " was not in the acceptable range [" + 0
+          + ", " + 1 + ")"), e.getMessage());
     }
   }

@@ -265,8 +265,7 @@
           fail("Should have triggered an assertion");
         } catch (AssertionError e) {
           // Good
- assertEquals(("Index " + i + " was not in the acceptable range [" + 0 + ", "
-          + 0 + ")"), e.getMessage());
+ assertEquals(Assertions.ACCESS_EMPTY_ARRAY_MESSAGE, e.getMessage());
         }
       }
     }
@@ -281,8 +280,7 @@
           fail("Should have triggered an assertion");
         } catch (AssertionError e) {
           // Good
- assertEquals(("Index " + i + " was not in the acceptable range [" + 0 + ", "
-          + 0 + ")"), e.getMessage());
+ assertEquals(Assertions.ACCESS_EMPTY_ARRAY_MESSAGE, e.getMessage());
         }
       }
     }
=======================================
--- /branches/lwc-gwt-migration/bikeshed/test-super/com/google/gwt/collections/super/com/google/gwt/collections/MutableArrayInternalTest.java Tue Jun 22 12:49:14 2010 +++ /branches/lwc-gwt-migration/bikeshed/test-super/com/google/gwt/collections/super/com/google/gwt/collections/MutableArrayInternalTest.java Mon Jun 14 06:05:16 2010
@@ -15,10 +15,6 @@
  */
 package com.google.gwt.collections;

-import static com.google.gwt.collections.CollectionFactory.createMutableArray;
-
-import com.google.gwt.junit.client.GWTTestCase;
-
 /**
  * Tests mutable array implementation internal details.
  */
@@ -29,18 +25,8 @@
     return null;
   }

-  public native boolean hasElems(MutableArray ma) /*-{
-    return !(ma.elems === undefined)
-  }-*/;
-
   public void testSetSizeNullElems() {
-    MutableArray<String> b = createMutableArray();
-
-    b.setSize(1, "fillValue");
-    assertTrue(hasElems(b));
-
-    b.setSize(0, null);
-    assertFalse(hasElems(b));
+    // Not necessary in JSNI implementation
   }

 }

--
http://groups.google.com/group/Google-Web-Toolkit-Contributors

Reply via email to