Commit f1cd4ab0 by Bryce McKinlay Committed by Bryce McKinlay

HashMap.java (HashMap): If 0 is given for initialCapacity paramater, bump it to 1.

2001-03-24  Bryce McKinlay  <bryce@albatross.co.nz>

	* java/util/HashMap.java (HashMap): If 0 is given for initialCapacity
	paramater, bump it to 1.
	* java/util/Hashtable.java (Hashtable): Likewise.

From-SVN: r40812
parent aff68f1c
2001-03-24 Bryce McKinlay <bryce@albatross.co.nz>
* java/util/HashMap.java (HashMap): If 0 is given for initialCapacity
paramater, bump it to 1.
* java/util/Hashtable.java (Hashtable): Likewise.
2001-03-23 Per Bothner <per@bothner.com> 2001-03-23 Per Bothner <per@bothner.com>
* java/lang/natDouble.cc (parseDouble): Cannot use errno to * java/lang/natDouble.cc (parseDouble): Cannot use errno to
......
...@@ -157,7 +157,7 @@ public class HashMap extends AbstractMap ...@@ -157,7 +157,7 @@ public class HashMap extends AbstractMap
* @param loadFactor the load factor * @param loadFactor the load factor
* *
* @throws IllegalArgumentException if (initialCapacity < 0) || * @throws IllegalArgumentException if (initialCapacity < 0) ||
* (initialLoadFactor > 1.0) || * (loadFactor <= 0)
*/ */
public HashMap(int initialCapacity, float loadFactor) public HashMap(int initialCapacity, float loadFactor)
throws IllegalArgumentException throws IllegalArgumentException
...@@ -168,6 +168,8 @@ public class HashMap extends AbstractMap ...@@ -168,6 +168,8 @@ public class HashMap extends AbstractMap
if (loadFactor <= 0) if (loadFactor <= 0)
throw new IllegalArgumentException("Illegal Load Factor: " + loadFactor); throw new IllegalArgumentException("Illegal Load Factor: " + loadFactor);
if (initialCapacity == 0)
initialCapacity = 1;
buckets = new Entry[initialCapacity]; buckets = new Entry[initialCapacity];
this.loadFactor = loadFactor; this.loadFactor = loadFactor;
this.threshold = (int) (initialCapacity * loadFactor); this.threshold = (int) (initialCapacity * loadFactor);
......
...@@ -180,6 +180,8 @@ public class Hashtable extends Dictionary ...@@ -180,6 +180,8 @@ public class Hashtable extends Dictionary
if (loadFactor <= 0) if (loadFactor <= 0)
throw new IllegalArgumentException("Illegal Load Factor: " + loadFactor); throw new IllegalArgumentException("Illegal Load Factor: " + loadFactor);
if (initialCapacity == 0)
initialCapacity = 1;
buckets = new Entry[initialCapacity]; buckets = new Entry[initialCapacity];
this.loadFactor = loadFactor; this.loadFactor = loadFactor;
this.threshold = (int) (initialCapacity * loadFactor); this.threshold = (int) (initialCapacity * loadFactor);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment