emul/compact/src/main/java/java/util/Hashtable.java
changeset 599 d0f57d3ea898
parent 597 ee8a922f4268
     1.1 --- a/emul/compact/src/main/java/java/util/Hashtable.java	Mon Jan 28 13:28:02 2013 +0100
     1.2 +++ b/emul/compact/src/main/java/java/util/Hashtable.java	Mon Jan 28 13:52:28 2013 +0100
     1.3 @@ -836,116 +836,6 @@
     1.4      }
     1.5  
     1.6      /**
     1.7 -     * Save the state of the Hashtable to a stream (i.e., serialize it).
     1.8 -     *
     1.9 -     * @serialData The <i>capacity</i> of the Hashtable (the length of the
    1.10 -     *             bucket array) is emitted (int), followed by the
    1.11 -     *             <i>size</i> of the Hashtable (the number of key-value
    1.12 -     *             mappings), followed by the key (Object) and value (Object)
    1.13 -     *             for each key-value mapping represented by the Hashtable
    1.14 -     *             The key-value mappings are emitted in no particular order.
    1.15 -     */
    1.16 -    private void writeObject(java.io.ObjectOutputStream s)
    1.17 -            throws IOException {
    1.18 -        Entry<Object, Object> entryStack = null;
    1.19 -
    1.20 -        synchronized (this) {
    1.21 -            // Write out the length, threshold, loadfactor
    1.22 -            s.defaultWriteObject();
    1.23 -
    1.24 -            // Write out length, count of elements
    1.25 -            s.writeInt(table.length);
    1.26 -            s.writeInt(count);
    1.27 -
    1.28 -            // Stack copies of the entries in the table
    1.29 -            for (int index = 0; index < table.length; index++) {
    1.30 -                Entry entry = table[index];
    1.31 -
    1.32 -                while (entry != null) {
    1.33 -                    entryStack =
    1.34 -                        new Entry<>(0, entry.key, entry.value, entryStack);
    1.35 -                    entry = entry.next;
    1.36 -                }
    1.37 -            }
    1.38 -        }
    1.39 -
    1.40 -        // Write out the key/value objects from the stacked entries
    1.41 -        while (entryStack != null) {
    1.42 -            s.writeObject(entryStack.key);
    1.43 -            s.writeObject(entryStack.value);
    1.44 -            entryStack = entryStack.next;
    1.45 -        }
    1.46 -    }
    1.47 -
    1.48 -    /**
    1.49 -     * Reconstitute the Hashtable from a stream (i.e., deserialize it).
    1.50 -     */
    1.51 -    private void readObject(java.io.ObjectInputStream s)
    1.52 -         throws IOException, ClassNotFoundException
    1.53 -    {
    1.54 -        // Read in the length, threshold, and loadfactor
    1.55 -        s.defaultReadObject();
    1.56 -
    1.57 -        // Read the original length of the array and number of elements
    1.58 -        int origlength = s.readInt();
    1.59 -        int elements = s.readInt();
    1.60 -
    1.61 -        // Compute new size with a bit of room 5% to grow but
    1.62 -        // no larger than the original size.  Make the length
    1.63 -        // odd if it's large enough, this helps distribute the entries.
    1.64 -        // Guard against the length ending up zero, that's not valid.
    1.65 -        int length = (int)(elements * loadFactor) + (elements / 20) + 3;
    1.66 -        if (length > elements && (length & 1) == 0)
    1.67 -            length--;
    1.68 -        if (origlength > 0 && length > origlength)
    1.69 -            length = origlength;
    1.70 -
    1.71 -        Entry[] table = new Entry[length];
    1.72 -        count = 0;
    1.73 -
    1.74 -        // Read the number of elements and then all the key/value objects
    1.75 -        for (; elements > 0; elements--) {
    1.76 -            K key = (K)s.readObject();
    1.77 -            V value = (V)s.readObject();
    1.78 -            // synch could be eliminated for performance
    1.79 -            reconstitutionPut(table, key, value);
    1.80 -        }
    1.81 -        this.table = table;
    1.82 -    }
    1.83 -
    1.84 -    /**
    1.85 -     * The put method used by readObject. This is provided because put
    1.86 -     * is overridable and should not be called in readObject since the
    1.87 -     * subclass will not yet be initialized.
    1.88 -     *
    1.89 -     * <p>This differs from the regular put method in several ways. No
    1.90 -     * checking for rehashing is necessary since the number of elements
    1.91 -     * initially in the table is known. The modCount is not incremented
    1.92 -     * because we are creating a new instance. Also, no return value
    1.93 -     * is needed.
    1.94 -     */
    1.95 -    private void reconstitutionPut(Entry[] tab, K key, V value)
    1.96 -        throws StreamCorruptedException
    1.97 -    {
    1.98 -        if (value == null) {
    1.99 -            throw new java.io.StreamCorruptedException();
   1.100 -        }
   1.101 -        // Makes sure the key is not already in the hashtable.
   1.102 -        // This should not happen in deserialized version.
   1.103 -        int hash = key.hashCode();
   1.104 -        int index = (hash & 0x7FFFFFFF) % tab.length;
   1.105 -        for (Entry<K,V> e = tab[index] ; e != null ; e = e.next) {
   1.106 -            if ((e.hash == hash) && e.key.equals(key)) {
   1.107 -                throw new java.io.StreamCorruptedException();
   1.108 -            }
   1.109 -        }
   1.110 -        // Creates the new entry.
   1.111 -        Entry<K,V> e = tab[index];
   1.112 -        tab[index] = new Entry<>(hash, key, value, e);
   1.113 -        count++;
   1.114 -    }
   1.115 -
   1.116 -    /**
   1.117       * Hashtable collision list.
   1.118       */
   1.119      private static class Entry<K,V> implements Map.Entry<K,V> {