Example #1
0
  /**
   * Save the state of this {@code HashSet} instance to a stream (that is, serialize it).
   *
   * @serialData The capacity of the backing {@code HashMap} instance (int), and its load factor
   *     (float) are emitted, followed by the size of the set (the number of elements it contains)
   *     (int), followed by all of its elements (each an Object) in no particular order.
   */
  private void writeObject(java.io.ObjectOutputStream s) throws java.io.IOException {
    // Write out any hidden serialization magic
    s.defaultWriteObject();

    // Write out HashMap capacity and load factor
    s.writeInt(map.capacity());
    s.writeFloat(map.loadFactor());

    // Write out size
    s.writeInt(map.size());

    // Write out all elements in the proper order.
    for (E e : map.keySet()) s.writeObject(e);
  }