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
This commit is contained in:
Bryce McKinlay 2001-03-24 08:05:29 +00:00 committed by Bryce McKinlay
parent aff68f1cd9
commit f1cd4ab003
3 changed files with 13 additions and 3 deletions

View File

@ -1,3 +1,9 @@
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>
* java/lang/natDouble.cc (parseDouble): Cannot use errno to

View File

@ -157,7 +157,7 @@ public class HashMap extends AbstractMap
* @param loadFactor the load factor
*
* @throws IllegalArgumentException if (initialCapacity < 0) ||
* (initialLoadFactor > 1.0) ||
* (loadFactor <= 0)
*/
public HashMap(int initialCapacity, float loadFactor)
throws IllegalArgumentException
@ -167,7 +167,9 @@ public class HashMap extends AbstractMap
+ initialCapacity);
if (loadFactor <= 0)
throw new IllegalArgumentException("Illegal Load Factor: " + loadFactor);
if (initialCapacity == 0)
initialCapacity = 1;
buckets = new Entry[initialCapacity];
this.loadFactor = loadFactor;
this.threshold = (int) (initialCapacity * loadFactor);

View File

@ -179,7 +179,9 @@ public class Hashtable extends Dictionary
+ initialCapacity);
if (loadFactor <= 0)
throw new IllegalArgumentException("Illegal Load Factor: " + loadFactor);
if (initialCapacity == 0)
initialCapacity = 1;
buckets = new Entry[initialCapacity];
this.loadFactor = loadFactor;
this.threshold = (int) (initialCapacity * loadFactor);