/** * Save the state of the <tt>HashMap</tt> instance to a stream (i.e., serialize it). * * @param s * The ObjectOutputStream * @throws IOException * * @serialData The <i>capacity</i> of the HashMap (the length of the bucket array) is emitted * (int), followed by the <i>size</i> of the HashMap (the number of key-value * mappings), followed by the key (Object) and value (Object) for each key-value * mapping represented by the HashMap The key-value mappings are emitted in the * order that they are returned by <tt>entrySet().iterator()</tt>. * */ private void writeObject(java.io.ObjectOutputStream s) throws IOException { // Write out the threshold, loadfactor, and any hidden stuff s.defaultWriteObject(); // Write out number of buckets s.writeInt(table.length); // Write out size (number of Mappings) s.writeInt(size); // Write out keys and values (alternating) for (Iterator i = entrySet().iterator(); i.hasNext();) { Entry e = (Entry)i.next(); s.writeInt(e.getKey()); s.writeObject(e.getValue()); } }
/** * Save the state of the <tt>HashMap</tt> instance to a stream (i.e., serialize it). * * @param s * The ObjectOutputStream * @throws IOException * * @serialData The <i>capacity</i> of the HashMap (the length of the bucket array) is emitted * (int), followed by the <i>size</i> of the HashMap (the number of key-value * mappings), followed by the key (Object) and value (Object) for each key-value * mapping represented by the HashMap The key-value mappings are emitted in the * order that they are returned by <tt>entrySet().iterator()</tt>. * */ private void writeObject(java.io.ObjectOutputStream s) throws IOException { // Write out the threshold, loadfactor, and any hidden stuff s.defaultWriteObject(); // Write out number of buckets s.writeInt(table.length); // Write out size (number of Mappings) s.writeInt(size); // Write out keys and values (alternating) for (Iterator<Entry<V>> i = entrySet().iterator(); i.hasNext();) { Entry<V> e = i.next(); s.writeInt(e.getKey()); s.writeObject(e.getValue()); } }
/** * Save the state of the <tt>HashMap</tt> instance to a stream (i.e., serialize it). * * @param s * The ObjectOutputStream * @throws IOException * * @serialData The <i>capacity</i> of the HashMap (the length of the bucket array) is emitted * (int), followed by the <i>size</i> of the HashMap (the number of key-value * mappings), followed by the key (Object) and value (Object) for each key-value * mapping represented by the HashMap The key-value mappings are emitted in the * order that they are returned by <tt>entrySet().iterator()</tt>. * */ private void writeObject(final java.io.ObjectOutputStream s) throws IOException { // Write out the threshold, loadfactor, and any hidden stuff s.defaultWriteObject(); // Write out number of buckets s.writeInt(table.length); // Write out size (number of Mappings) s.writeInt(size); // Write out keys and values (alternating) for (Entry<V> entry : entrySet()) { s.writeInt(entry.getKey()); s.writeObject(entry.getValue()); } }
/** * @see java.lang.Object#equals(java.lang.Object) */ @SuppressWarnings("unchecked") @Override public boolean equals(final Object o) { if (!(o instanceof Entry)) { return false; } Entry<V> e = (Entry<V>)o; int k1 = getKey(); int k2 = e.getKey(); if (k1 == k2) { Object v1 = getValue(); Object v2 = e.getValue(); if ((v1 == v2) || ((v1 != null) && v1.equals(v2))) { return true; } } return false; }
/** * @see java.lang.Object#equals(java.lang.Object) */ public boolean equals(Object o) { if (!(o instanceof Entry)) { return false; } Entry e = (Entry)o; int k1 = getKey(); int k2 = e.getKey(); if (k1 == k2) { Object v1 = getValue(); Object v2 = e.getValue(); if (v1 == v2 || (v1 != null && v1.equals(v2))) { return true; } } return false; }
/** * @see java.lang.Object#equals(java.lang.Object) */ @SuppressWarnings("unchecked") @Override public boolean equals(Object o) { if (!(o instanceof Entry)) { return false; } Entry<V> e = (Entry<V>)o; int k1 = getKey(); int k2 = e.getKey(); if (k1 == k2) { Object v1 = getValue(); Object v2 = e.getValue(); if (v1 == v2 || (v1 != null && v1.equals(v2))) { return true; } } return false; }
/** * Add a new entry with the specified key, value and hash code to the specified bucket. It is * the responsibility of this method to resize the table if appropriate. * * Subclass overrides this to alter the behavior of put method. * * @param key * @param value * @param bucketIndex */ void addEntry(int key, V value, int bucketIndex) { table[bucketIndex] = new Entry<V>(key, value, table[bucketIndex]); if (size++ >= threshold) { resize(2 * table.length); } }
private void writeObject(java.io.ObjectOutputStream s) throws IOException { IntKeyWeakReference ref = null; while ((ref = (IntKeyWeakReference)queue.poll()) != null) { directComponentRefs.remove(ref.uid); } s.defaultWriteObject(); s.writeInt(directComponentRefs.size()); Iterator it = directComponentRefs.entrySet().iterator(); while (it.hasNext()) { IntHashMap.Entry entry = (Entry)it.next(); s.writeInt(entry.getKey()); ComponentAndInterface cai = (ComponentAndInterface)entry.getValue(); s.writeObject(cai.getComponent()); s.writeUTF(cai.getInterfaceName()); } } }
/** * Like addEntry except that this version is used when creating entries as part of Map * construction or "pseudo-construction" (cloning, deserialization). This version needn't worry * about resizing the table. * * Subclass overrides this to alter the behavior of HashMap(Map), clone, and readObject. * * @param key * @param value * @param bucketIndex */ void createEntry(final int key, final V value, final int bucketIndex) { table[bucketIndex] = new Entry<>(key, value, table[bucketIndex]); size++; }
/** * Add a new entry with the specified key, value and hash code to the specified bucket. It is * the responsibility of this method to resize the table if appropriate. * * Subclass overrides this to alter the behavior of put method. * * @param key * @param value * @param bucketIndex */ void addEntry(final int key, final V value, final int bucketIndex) { table[bucketIndex] = new Entry<>(key, value, table[bucketIndex]); if (size++ >= threshold) { resize(2 * table.length); } }
/** * Add a new entry with the specified key, value and hash code to the specified bucket. It is * the responsibility of this method to resize the table if appropriate. * * Subclass overrides this to alter the behavior of put method. * * @param key * @param value * @param bucketIndex */ void addEntry(int key, Object value, int bucketIndex) { table[bucketIndex] = new Entry(key, value, table[bucketIndex]); if (size++ >= threshold) { resize(2 * table.length); } }