This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Fix for PR 2040


Heres the fix for 2040. I figure if people really want loadFactor > 1
(to guarantee fast iterator performance, perhaps) then there's not
reason to stop them...

regards

  [ bryce ]

2001-02-22  Bryce McKinlay  <bryce@albatross.co.nz>

	Fix for PR java/2040:
	* java/util/HashMap.java (HashMap): Don't throw exception for 
	loadFactor > 1. Add exception messages.
	* java/util/Hashtable.java (Hashtable): Likewise.

Index: HashMap.java
===================================================================
RCS file: /cvs/gcc/egcs/libjava/java/util/HashMap.java,v
retrieving revision 1.4.4.1
diff -u -r1.4.4.1 HashMap.java
--- HashMap.java	2001/02/17 01:06:45	1.4.4.1
+++ HashMap.java	2001/02/22 04:10:14
@@ -160,14 +160,16 @@
    * 
    * @throws   IllegalArgumentException    if (initialCapacity < 0) ||
    *                                          (initialLoadFactor > 1.0) ||
-   *                                          (initialLoadFactor <= 0.0)
    */
   public HashMap(int initialCapacity, float loadFactor)
     throws IllegalArgumentException
   {
-    if (initialCapacity < 0 || loadFactor <= 0 || loadFactor > 1)
-      throw new IllegalArgumentException();
-    
+    if (initialCapacity < 0)
+      throw new IllegalArgumentException("Illegal Initial Capacity: " 
+      					 + initialCapacity);    
+    if (loadFactor <= 0)
+      throw new IllegalArgumentException("Illegal Load Factor: " + loadFactor);
+  
     buckets = new Entry[initialCapacity];
     this.loadFactor = loadFactor;
     this.threshold = (int) (initialCapacity * loadFactor);
Index: Hashtable.java
===================================================================
RCS file: /cvs/gcc/egcs/libjava/java/util/Hashtable.java,v
retrieving revision 1.10
diff -u -r1.10 Hashtable.java
--- Hashtable.java	2000/12/21 02:00:15	1.10
+++ Hashtable.java	2001/02/22 04:10:14
@@ -171,15 +171,17 @@
    * @param   loadFactor       the load factor
    * 
    * @throws   IllegalArgumentException    if (initialCapacity < 0) ||
-   *                                          (initialLoadFactor > 1.0) ||
    *                                          (initialLoadFactor <= 0.0)
    */
   public Hashtable(int initialCapacity, float loadFactor)
     throws IllegalArgumentException
   {
-    if (initialCapacity < 0 || loadFactor <= 0 || loadFactor > 1)
-      throw new IllegalArgumentException();
-    
+    if (initialCapacity < 0)
+      throw new IllegalArgumentException("Illegal Initial Capacity: " 
+      					 + initialCapacity);    
+    if (loadFactor <= 0)
+      throw new IllegalArgumentException("Illegal Load Factor: " + loadFactor);
+     
     buckets = new Entry[initialCapacity];
     this.loadFactor = loadFactor;
     this.threshold = (int) (initialCapacity * loadFactor);

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]