< prev index next >
src/java.base/share/classes/java/util/Hashtable.java
Print this page
*** 228,237 ****
--- 228,245 ----
this(Math.max(2*t.size(), 11), 0.75f);
putAll(t);
}
/**
+ * A constructor chained from {@link Properties} keeps Hashtable fields
+ * uninitialized since they are not used.
+ *
+ * @param dummy a dummy parameter
+ */
+ Hashtable(Void dummy) {}
+
+ /**
* Returns the number of keys in this hashtable.
*
* @return the number of keys in this hashtable.
*/
public synchronized int size() {
*** 547,568 ****
* This is a relatively expensive operation.
*
* @return a clone of the hashtable
*/
public synchronized Object clone() {
! try {
! Hashtable<?,?> t = (Hashtable<?,?>)super.clone();
t.table = new Entry<?,?>[table.length];
for (int i = table.length ; i-- > 0 ; ) {
t.table[i] = (table[i] != null)
? (Entry<?,?>) table[i].clone() : null;
}
t.keySet = null;
t.entrySet = null;
t.values = null;
t.modCount = 0;
return t;
} catch (CloneNotSupportedException e) {
// this shouldn't happen, since we are Cloneable
throw new InternalError(e);
}
}
--- 555,581 ----
* This is a relatively expensive operation.
*
* @return a clone of the hashtable
*/
public synchronized Object clone() {
! Hashtable<?,?> t = cloneHashtable();
t.table = new Entry<?,?>[table.length];
for (int i = table.length ; i-- > 0 ; ) {
t.table[i] = (table[i] != null)
? (Entry<?,?>) table[i].clone() : null;
}
t.keySet = null;
t.entrySet = null;
t.values = null;
t.modCount = 0;
return t;
+ }
+
+ /** Calls super.clone() */
+ final Hashtable<?,?> cloneHashtable() {
+ try {
+ return (Hashtable<?,?>)super.clone();
} catch (CloneNotSupportedException e) {
// this shouldn't happen, since we are Cloneable
throw new InternalError(e);
}
}
*** 1187,1196 ****
--- 1200,1214 ----
* for each key-value mapping represented by the Hashtable
* The key-value mappings are emitted in no particular order.
*/
private void writeObject(java.io.ObjectOutputStream s)
throws IOException {
+ writeHashtable(s);
+ }
+
+ void writeHashtable(java.io.ObjectOutputStream s)
+ throws IOException {
Entry<Object, Object> entryStack = null;
synchronized (this) {
// Write out the threshold and loadFactor
s.defaultWriteObject();
*** 1217,1231 ****
entryStack = entryStack.next;
}
}
/**
* Reconstitute the Hashtable from a stream (i.e., deserialize it).
*/
private void readObject(java.io.ObjectInputStream s)
! throws IOException, ClassNotFoundException
! {
// Read in the threshold and loadFactor
s.defaultReadObject();
// Validate loadFactor (ignore threshold - it will be re-computed)
if (loadFactor <= 0 || Float.isNaN(loadFactor))
--- 1235,1264 ----
entryStack = entryStack.next;
}
}
/**
+ * Write out the simulated threshold, loadfactor
+ * Called by Properties
+ */
+ final void defaultWriteHashtable(java.io.ObjectOutputStream s, int length,
+ float loadFactor) throws IOException {
+ this.threshold = (int)Math.min(length * loadFactor, MAX_ARRAY_SIZE + 1);
+ this.loadFactor = loadFactor;
+ s.defaultWriteObject();
+ }
+
+ /**
* Reconstitute the Hashtable from a stream (i.e., deserialize it).
*/
private void readObject(java.io.ObjectInputStream s)
! throws IOException, ClassNotFoundException {
! readHashtable(s);
! }
!
! void readHashtable(java.io.ObjectInputStream s)
! throws IOException, ClassNotFoundException {
// Read in the threshold and loadFactor
s.defaultReadObject();
// Validate loadFactor (ignore threshold - it will be re-computed)
if (loadFactor <= 0 || Float.isNaN(loadFactor))
< prev index next >