Fix for issue #802. Adds constructors for ArrayList(int initialCapacity) and Vector(int initalCapacity) for JRE compatibility. The constructors are functionally identical to the default constructors. Found by: alau2003 Patch by: rdayal Review by: me git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@846 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/super/com/google/gwt/emul/java/util/ArrayList.java b/user/super/com/google/gwt/emul/java/util/ArrayList.java index 18e6415..5c84df7 100644 --- a/user/super/com/google/gwt/emul/java/util/ArrayList.java +++ b/user/super/com/google/gwt/emul/java/util/ArrayList.java
@@ -1,5 +1,5 @@ /* - * Copyright 2006 Google Inc. + * Copyright 2007 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 @@ -25,7 +25,10 @@ * <p> * <b>Capacity</b> There is no speed advantage to pre-allocating array sizes in * JavaScript, so this implementation does not include any of the capacity and - * "growth increment" concepts in the standard ArrayList class. + * "growth increment" concepts in the standard ArrayList class. Although + * <code>ArrayList(int)</code> accepts a value for the intitial capacity of + * the array, this constructor simply delegates to <code>ArrayList()</code>. + * It is only present for compatibility with JDK 1.4's API. * </p> * <p> * <b>Dual endedness</b> For increased performance, this implementation supports @@ -73,6 +76,17 @@ addAll(c); } + /** + * There is no speed advantage to pre-allocating array sizes in JavaScript, + * so the <code>intialCapacity</code> parameter is ignored. This constructor is + * only present for compatibility with JDK 1.4's API. + */ + public ArrayList(int initialCapacity) { + // initialCapacity is ignored in JS implementation; this constructor is + // present for JDK 1.4 compatibility + this(); + } + public native void add(int index, Object o) /*-{ var array = this.@java.util.ArrayList::array; var endIndex = this.@java.util.ArrayList::endIndex; @@ -272,4 +286,4 @@ this.@java.util.ArrayList::startIndex = HALFWAY_INDEX; this.@java.util.ArrayList::endIndex = HALFWAY_INDEX; }-*/; -} \ No newline at end of file +}
diff --git a/user/super/com/google/gwt/emul/java/util/Vector.java b/user/super/com/google/gwt/emul/java/util/Vector.java index 774ad4f..2be0add 100644 --- a/user/super/com/google/gwt/emul/java/util/Vector.java +++ b/user/super/com/google/gwt/emul/java/util/Vector.java
@@ -1,5 +1,5 @@ /* - * Copyright 2006 Google Inc. + * Copyright 2007 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 @@ -34,6 +34,15 @@ addAll(c); } + /** + * There is no speed advantage to pre-allocating array sizes in JavaScript, + * so the <code>intialCapacity</code> parameter is ignored. This constructor is + * only present for compatibility with JDK 1.4's API. + */ + public Vector(int initialCapacity) { + arrayList = new ArrayList(initialCapacity); + } + public void add(int index, Object o) { arrayList.add(index, o); }