/[classpath]/classpath/java/util/Hashtable.java
ViewVC logotype

Diff of /classpath/java/util/Hashtable.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.32.2.2 by tromey, Sat Nov 6 22:11:53 2004 UTC revision 1.32.2.3 by tromey, Wed Jan 12 01:12:48 2005 UTC
# Line 269  public class Hashtable<K, V> extends Dic Line 269  public class Hashtable<K, V> extends Dic
269    
270      if (initialCapacity == 0)      if (initialCapacity == 0)
271        initialCapacity = 1;        initialCapacity = 1;
272      buckets = new HashEntry<K, V>[initialCapacity];      buckets = (HashEntry<K, V>[]) new HashEntry[initialCapacity];
273      this.loadFactor = loadFactor;      this.loadFactor = loadFactor;
274      threshold = (int) (initialCapacity * loadFactor);      threshold = (int) (initialCapacity * loadFactor);
275    }    }
# Line 562  public class Hashtable<K, V> extends Dic Line 562  public class Hashtable<K, V> extends Dic
562        {        {
563          // This is impossible.          // This is impossible.
564        }        }
565      copy.buckets = new HashEntry<K, V>[buckets.length];      copy.buckets = (HashEntry<K, V>[]) new HashEntry[buckets.length];
566      copy.putAllInternal(this);      copy.putAllInternal(this);
567      // Clear the caches.      // Clear the caches.
568      copy.keys = null;      copy.keys = null;
# Line 820  public class Hashtable<K, V> extends Dic Line 820  public class Hashtable<K, V> extends Dic
820     * @return the bucket number     * @return the bucket number
821     * @throws NullPointerException if key is null     * @throws NullPointerException if key is null
822     */     */
823    private int hash(K key)    private int hash(Object key)
824    {    {
825      // Note: Inline Math.abs here, for less method overhead, and to avoid      // Note: Inline Math.abs here, for less method overhead, and to avoid
826      // a bootstrap dependency, since Math relies on native methods.      // a bootstrap dependency, since Math relies on native methods.
# Line 839  public class Hashtable<K, V> extends Dic Line 839  public class Hashtable<K, V> extends Dic
839    // Package visible, for use in nested classes.    // Package visible, for use in nested classes.
840    HashEntry<K, V> getEntry(Object o)    HashEntry<K, V> getEntry(Object o)
841    {    {
842      if (! (o instanceof Map.Entry<K, V>))      if (! (o instanceof Map.Entry))
843        return null;        return null;
844      K key = ((Map.Entry<K, V>) o).getKey();      K key = ((Map.Entry<K, V>) o).getKey();
845      if (key == null)      if (key == null)
# Line 899  public class Hashtable<K, V> extends Dic Line 899  public class Hashtable<K, V> extends Dic
899    
900      int newcapacity = (buckets.length * 2) + 1;      int newcapacity = (buckets.length * 2) + 1;
901      threshold = (int) (newcapacity * loadFactor);      threshold = (int) (newcapacity * loadFactor);
902      buckets = new HashEntry<K, V>[newcapacity];      buckets = (HashEntry<K, V>[]) new HashEntry[newcapacity];
903    
904      for (int i = oldBuckets.length - 1; i >= 0; i--)      for (int i = oldBuckets.length - 1; i >= 0; i--)
905        {        {
# Line 975  public class Hashtable<K, V> extends Dic Line 975  public class Hashtable<K, V> extends Dic
975      s.defaultReadObject();      s.defaultReadObject();
976    
977      // Read and use capacity.      // Read and use capacity.
978      buckets = new HashEntry<K, V>[s.readInt()];      buckets = (HashEntry<K, V>[]) new HashEntry[s.readInt()];
979      int len = s.readInt();      int len = s.readInt();
980    
981      // Read and use key/value pairs.      // Read and use key/value pairs.
982      // TODO: should we be defensive programmers, and check for illegal nulls?      // TODO: should we be defensive programmers, and check for illegal nulls?
983      while (--len >= 0)      while (--len >= 0)
984        put(s.readObject(), s.readObject());        put((K) s.readObject(), (V) s.readObject());
985    }    }
986    
987    /**    /**
# Line 1061  public class Hashtable<K, V> extends Dic Line 1061  public class Hashtable<K, V> extends Dic
1061        next = e.next;        next = e.next;
1062        last = e;        last = e;
1063        if (type == VALUES)        if (type == VALUES)
1064          return e.value;          return (T) e.value;
1065        if (type == KEYS)        if (type == KEYS)
1066          return e.key;          return (T) e.key;
1067        return e;        return (T) e;
1068      }      }
1069    
1070      /**      /**
# Line 1141  public class Hashtable<K, V> extends Dic Line 1141  public class Hashtable<K, V> extends Dic
1141       * @return the next element       * @return the next element
1142       * @throws NoSuchElementException if there is none.       * @throws NoSuchElementException if there is none.
1143       */       */
1144      public Object nextElement()      public T nextElement()
1145      {      {
1146        if (count == 0)        if (count == 0)
1147          throw new NoSuchElementException("Hashtable Enumerator");          throw new NoSuchElementException("Hashtable Enumerator");
# Line 1152  public class Hashtable<K, V> extends Dic Line 1152  public class Hashtable<K, V> extends Dic
1152          e = buckets[--idx];          e = buckets[--idx];
1153    
1154        next = e.next;        next = e.next;
1155        return type == VALUES ? e.value : e.key;        return type == VALUES ? (T) e.value : (T) e.key;
1156      }      }
1157    } // class Enumerator    } // class Enumerator
1158  } // class Hashtable  } // class Hashtable

Legend:
Removed from v.1.32.2.2  
changed lines
  Added in v.1.32.2.3

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26