Tabnine Logo
HashMap.init
Code IndexAdd Tabnine to your IDE (free)

How to use
init
method
in
java.util.HashMap

Best Java code snippets using java.util.HashMap.init (Showing top 20 results out of 315)

origin: robovm/robovm

  private void readObject(ObjectInputStream stream) throws IOException,
      ClassNotFoundException {
    stream.defaultReadObject();
    int capacity = stream.readInt();
    if (capacity < 0) {
      throw new InvalidObjectException("Capacity: " + capacity);
    }
    if (capacity < MINIMUM_CAPACITY) {
      capacity = MINIMUM_CAPACITY;
    } else if (capacity > MAXIMUM_CAPACITY) {
      capacity = MAXIMUM_CAPACITY;
    } else {
      capacity = Collections.roundUpToPowerOfTwo(capacity);
    }
    makeTable(capacity);

    int size = stream.readInt();
    if (size < 0) {
      throw new InvalidObjectException("Size: " + size);
    }

    init(); // Give subclass (LinkedHashMap) a chance to initialize itself
    for (int i = 0; i < size; i++) {
      @SuppressWarnings("unchecked") K key = (K) stream.readObject();
      @SuppressWarnings("unchecked") V val = (V) stream.readObject();
      constructorPut(key, val);
    }
  }
}
origin: robovm/robovm

/**
 * Returns a shallow copy of this map.
 *
 * @return a shallow copy of this map.
 */
@SuppressWarnings("unchecked")
@Override public Object clone() {
  /*
   * This could be made more efficient. It unnecessarily hashes all of
   * the elements in the map.
   */
  HashMap<K, V> result;
  try {
    result = (HashMap<K, V>) super.clone();
  } catch (CloneNotSupportedException e) {
    throw new AssertionError(e);
  }
  // Restore clone to empty state, retaining our capacity and threshold
  result.makeTable(table.length);
  result.entryForNullKey = null;
  result.size = 0;
  result.keySet = null;
  result.entrySet = null;
  result.values = null;
  result.init(); // Give subclass a chance to initialize itself
  result.constructorPutAll(this); // Calls method overridden in subclass!!
  return result;
}
origin: org.apidesign.bck2brwsr/emul

/**
 * Constructs an empty <tt>HashMap</tt> with the default initial capacity
 * (16) and the default load factor (0.75).
 */
public HashMap() {
  this.loadFactor = DEFAULT_LOAD_FACTOR;
  threshold = (int)(DEFAULT_INITIAL_CAPACITY * DEFAULT_LOAD_FACTOR);
  table = new Entry[DEFAULT_INITIAL_CAPACITY];
  init();
}
origin: jtulach/bck2brwsr

/**
 * Constructs an empty <tt>HashMap</tt> with the default initial capacity
 * (16) and the default load factor (0.75).
 */
public HashMap() {
  this.loadFactor = DEFAULT_LOAD_FACTOR;
  threshold = (int)(DEFAULT_INITIAL_CAPACITY * DEFAULT_LOAD_FACTOR);
  table = new Entry[DEFAULT_INITIAL_CAPACITY];
  init();
}
origin: jtulach/bck2brwsr

/**
 * Constructs an empty <tt>HashMap</tt> with the specified initial
 * capacity and load factor.
 *
 * @param  initialCapacity the initial capacity
 * @param  loadFactor      the load factor
 * @throws IllegalArgumentException if the initial capacity is negative
 *         or the load factor is nonpositive
 */
public HashMap(int initialCapacity, float loadFactor) {
  if (initialCapacity < 0)
    throw new IllegalArgumentException("Illegal initial capacity: " +
                      initialCapacity);
  if (initialCapacity > MAXIMUM_CAPACITY)
    initialCapacity = MAXIMUM_CAPACITY;
  if (loadFactor <= 0 || Float.isNaN(loadFactor))
    throw new IllegalArgumentException("Illegal load factor: " +
                      loadFactor);
  // Find a power of 2 >= initialCapacity
  int capacity = 1;
  while (capacity < initialCapacity)
    capacity <<= 1;
  this.loadFactor = loadFactor;
  threshold = (int)(capacity * loadFactor);
  table = new Entry[capacity];
  init();
}
origin: org.apidesign.bck2brwsr/emul

/**
 * Constructs an empty <tt>HashMap</tt> with the specified initial
 * capacity and load factor.
 *
 * @param  initialCapacity the initial capacity
 * @param  loadFactor      the load factor
 * @throws IllegalArgumentException if the initial capacity is negative
 *         or the load factor is nonpositive
 */
public HashMap(int initialCapacity, float loadFactor) {
  if (initialCapacity < 0)
    throw new IllegalArgumentException("Illegal initial capacity: " +
                      initialCapacity);
  if (initialCapacity > MAXIMUM_CAPACITY)
    initialCapacity = MAXIMUM_CAPACITY;
  if (loadFactor <= 0 || Float.isNaN(loadFactor))
    throw new IllegalArgumentException("Illegal load factor: " +
                      loadFactor);
  // Find a power of 2 >= initialCapacity
  int capacity = 1;
  while (capacity < initialCapacity)
    capacity <<= 1;
  this.loadFactor = loadFactor;
  threshold = (int)(capacity * loadFactor);
  table = new Entry[capacity];
  init();
}
origin: com.mobidevelop.robovm/robovm-rt

  private void readObject(ObjectInputStream stream) throws IOException,
      ClassNotFoundException {
    stream.defaultReadObject();
    int capacity = stream.readInt();
    if (capacity < 0) {
      throw new InvalidObjectException("Capacity: " + capacity);
    }
    if (capacity < MINIMUM_CAPACITY) {
      capacity = MINIMUM_CAPACITY;
    } else if (capacity > MAXIMUM_CAPACITY) {
      capacity = MAXIMUM_CAPACITY;
    } else {
      capacity = Collections.roundUpToPowerOfTwo(capacity);
    }
    makeTable(capacity);

    int size = stream.readInt();
    if (size < 0) {
      throw new InvalidObjectException("Size: " + size);
    }

    init(); // Give subclass (LinkedHashMap) a chance to initialize itself
    for (int i = 0; i < size; i++) {
      @SuppressWarnings("unchecked") K key = (K) stream.readObject();
      @SuppressWarnings("unchecked") V val = (V) stream.readObject();
      constructorPut(key, val);
    }
  }
}
origin: MobiVM/robovm

  private void readObject(ObjectInputStream stream) throws IOException,
      ClassNotFoundException {
    stream.defaultReadObject();
    int capacity = stream.readInt();
    if (capacity < 0) {
      throw new InvalidObjectException("Capacity: " + capacity);
    }
    if (capacity < MINIMUM_CAPACITY) {
      capacity = MINIMUM_CAPACITY;
    } else if (capacity > MAXIMUM_CAPACITY) {
      capacity = MAXIMUM_CAPACITY;
    } else {
      capacity = Collections.roundUpToPowerOfTwo(capacity);
    }
    makeTable(capacity);

    int size = stream.readInt();
    if (size < 0) {
      throw new InvalidObjectException("Size: " + size);
    }

    init(); // Give subclass (LinkedHashMap) a chance to initialize itself
    for (int i = 0; i < size; i++) {
      @SuppressWarnings("unchecked") K key = (K) stream.readObject();
      @SuppressWarnings("unchecked") V val = (V) stream.readObject();
      constructorPut(key, val);
    }
  }
}
origin: ibinti/bugvm

  private void readObject(ObjectInputStream stream) throws IOException,
      ClassNotFoundException {
    stream.defaultReadObject();
    int capacity = stream.readInt();
    if (capacity < 0) {
      throw new InvalidObjectException("Capacity: " + capacity);
    }
    if (capacity < MINIMUM_CAPACITY) {
      capacity = MINIMUM_CAPACITY;
    } else if (capacity > MAXIMUM_CAPACITY) {
      capacity = MAXIMUM_CAPACITY;
    } else {
      capacity = Collections.roundUpToPowerOfTwo(capacity);
    }
    makeTable(capacity);

    int size = stream.readInt();
    if (size < 0) {
      throw new InvalidObjectException("Size: " + size);
    }

    init(); // Give subclass (LinkedHashMap) a chance to initialize itself
    for (int i = 0; i < size; i++) {
      @SuppressWarnings("unchecked") K key = (K) stream.readObject();
      @SuppressWarnings("unchecked") V val = (V) stream.readObject();
      constructorPut(key, val);
    }
  }
}
origin: com.gluonhq/robovm-rt

  private void readObject(ObjectInputStream stream) throws IOException,
      ClassNotFoundException {
    stream.defaultReadObject();
    int capacity = stream.readInt();
    if (capacity < 0) {
      throw new InvalidObjectException("Capacity: " + capacity);
    }
    if (capacity < MINIMUM_CAPACITY) {
      capacity = MINIMUM_CAPACITY;
    } else if (capacity > MAXIMUM_CAPACITY) {
      capacity = MAXIMUM_CAPACITY;
    } else {
      capacity = Collections.roundUpToPowerOfTwo(capacity);
    }
    makeTable(capacity);

    int size = stream.readInt();
    if (size < 0) {
      throw new InvalidObjectException("Size: " + size);
    }

    init(); // Give subclass (LinkedHashMap) a chance to initialize itself
    for (int i = 0; i < size; i++) {
      @SuppressWarnings("unchecked") K key = (K) stream.readObject();
      @SuppressWarnings("unchecked") V val = (V) stream.readObject();
      constructorPut(key, val);
    }
  }
}
origin: FlexoVM/flexovm

  private void readObject(ObjectInputStream stream) throws IOException,
      ClassNotFoundException {
    stream.defaultReadObject();
    int capacity = stream.readInt();
    if (capacity < 0) {
      throw new InvalidObjectException("Capacity: " + capacity);
    }
    if (capacity < MINIMUM_CAPACITY) {
      capacity = MINIMUM_CAPACITY;
    } else if (capacity > MAXIMUM_CAPACITY) {
      capacity = MAXIMUM_CAPACITY;
    } else {
      capacity = Collections.roundUpToPowerOfTwo(capacity);
    }
    makeTable(capacity);

    int size = stream.readInt();
    if (size < 0) {
      throw new InvalidObjectException("Size: " + size);
    }

    init(); // Give subclass (LinkedHashMap) a chance to initialize itself
    for (int i = 0; i < size; i++) {
      @SuppressWarnings("unchecked") K key = (K) stream.readObject();
      @SuppressWarnings("unchecked") V val = (V) stream.readObject();
      constructorPut(key, val);
    }
  }
}
origin: com.bugvm/bugvm-rt

  private void readObject(ObjectInputStream stream) throws IOException,
      ClassNotFoundException {
    stream.defaultReadObject();
    int capacity = stream.readInt();
    if (capacity < 0) {
      throw new InvalidObjectException("Capacity: " + capacity);
    }
    if (capacity < MINIMUM_CAPACITY) {
      capacity = MINIMUM_CAPACITY;
    } else if (capacity > MAXIMUM_CAPACITY) {
      capacity = MAXIMUM_CAPACITY;
    } else {
      capacity = Collections.roundUpToPowerOfTwo(capacity);
    }
    makeTable(capacity);

    int size = stream.readInt();
    if (size < 0) {
      throw new InvalidObjectException("Size: " + size);
    }

    init(); // Give subclass (LinkedHashMap) a chance to initialize itself
    for (int i = 0; i < size; i++) {
      @SuppressWarnings("unchecked") K key = (K) stream.readObject();
      @SuppressWarnings("unchecked") V val = (V) stream.readObject();
      constructorPut(key, val);
    }
  }
}
origin: org.apidesign.bck2brwsr/emul

/**
 * Returns a shallow copy of this <tt>HashMap</tt> instance: the keys and
 * values themselves are not cloned.
 *
 * @return a shallow copy of this map
 */
public Object clone() {
  HashMap<K,V> result = null;
  try {
    result = (HashMap<K,V>)super.clone();
  } catch (CloneNotSupportedException e) {
    // assert false;
  }
  result.table = new Entry[table.length];
  result.entrySet = null;
  result.modCount = 0;
  result.size = 0;
  result.init();
  result.putAllForCreate(this);
  return result;
}
origin: jtulach/bck2brwsr

/**
 * Returns a shallow copy of this <tt>HashMap</tt> instance: the keys and
 * values themselves are not cloned.
 *
 * @return a shallow copy of this map
 */
public Object clone() {
  HashMap<K,V> result = null;
  try {
    result = (HashMap<K,V>)super.clone();
  } catch (CloneNotSupportedException e) {
    // assert false;
  }
  result.table = new Entry[table.length];
  result.entrySet = null;
  result.modCount = 0;
  result.size = 0;
  result.init();
  result.putAllForCreate(this);
  return result;
}
origin: ibinti/bugvm

/**
 * Returns a shallow copy of this map.
 *
 * @return a shallow copy of this map.
 */
@SuppressWarnings("unchecked")
@Override public Object clone() {
  /*
   * This could be made more efficient. It unnecessarily hashes all of
   * the elements in the map.
   */
  HashMap<K, V> result;
  try {
    result = (HashMap<K, V>) super.clone();
  } catch (CloneNotSupportedException e) {
    throw new AssertionError(e);
  }
  // Restore clone to empty state, retaining our capacity and threshold
  result.makeTable(table.length);
  result.entryForNullKey = null;
  result.size = 0;
  result.keySet = null;
  result.entrySet = null;
  result.values = null;
  result.init(); // Give subclass a chance to initialize itself
  result.constructorPutAll(this); // Calls method overridden in subclass!!
  return result;
}
origin: MobiVM/robovm

/**
 * Returns a shallow copy of this map.
 *
 * @return a shallow copy of this map.
 */
@SuppressWarnings("unchecked")
@Override public Object clone() {
  /*
   * This could be made more efficient. It unnecessarily hashes all of
   * the elements in the map.
   */
  HashMap<K, V> result;
  try {
    result = (HashMap<K, V>) super.clone();
  } catch (CloneNotSupportedException e) {
    throw new AssertionError(e);
  }
  // Restore clone to empty state, retaining our capacity and threshold
  result.makeTable(table.length);
  result.entryForNullKey = null;
  result.size = 0;
  result.keySet = null;
  result.entrySet = null;
  result.values = null;
  result.init(); // Give subclass a chance to initialize itself
  result.constructorPutAll(this); // Calls method overridden in subclass!!
  return result;
}
origin: com.bugvm/bugvm-rt

/**
 * Returns a shallow copy of this map.
 *
 * @return a shallow copy of this map.
 */
@SuppressWarnings("unchecked")
@Override public Object clone() {
  /*
   * This could be made more efficient. It unnecessarily hashes all of
   * the elements in the map.
   */
  HashMap<K, V> result;
  try {
    result = (HashMap<K, V>) super.clone();
  } catch (CloneNotSupportedException e) {
    throw new AssertionError(e);
  }
  // Restore clone to empty state, retaining our capacity and threshold
  result.makeTable(table.length);
  result.entryForNullKey = null;
  result.size = 0;
  result.keySet = null;
  result.entrySet = null;
  result.values = null;
  result.init(); // Give subclass a chance to initialize itself
  result.constructorPutAll(this); // Calls method overridden in subclass!!
  return result;
}
origin: com.mobidevelop.robovm/robovm-rt

/**
 * Returns a shallow copy of this map.
 *
 * @return a shallow copy of this map.
 */
@SuppressWarnings("unchecked")
@Override public Object clone() {
  /*
   * This could be made more efficient. It unnecessarily hashes all of
   * the elements in the map.
   */
  HashMap<K, V> result;
  try {
    result = (HashMap<K, V>) super.clone();
  } catch (CloneNotSupportedException e) {
    throw new AssertionError(e);
  }
  // Restore clone to empty state, retaining our capacity and threshold
  result.makeTable(table.length);
  result.entryForNullKey = null;
  result.size = 0;
  result.keySet = null;
  result.entrySet = null;
  result.values = null;
  result.init(); // Give subclass a chance to initialize itself
  result.constructorPutAll(this); // Calls method overridden in subclass!!
  return result;
}
origin: com.gluonhq/robovm-rt

/**
 * Returns a shallow copy of this map.
 *
 * @return a shallow copy of this map.
 */
@SuppressWarnings("unchecked")
@Override public Object clone() {
  /*
   * This could be made more efficient. It unnecessarily hashes all of
   * the elements in the map.
   */
  HashMap<K, V> result;
  try {
    result = (HashMap<K, V>) super.clone();
  } catch (CloneNotSupportedException e) {
    throw new AssertionError(e);
  }
  // Restore clone to empty state, retaining our capacity and threshold
  result.makeTable(table.length);
  result.entryForNullKey = null;
  result.size = 0;
  result.keySet = null;
  result.entrySet = null;
  result.values = null;
  result.init(); // Give subclass a chance to initialize itself
  result.constructorPutAll(this); // Calls method overridden in subclass!!
  return result;
}
origin: FlexoVM/flexovm

/**
 * Returns a shallow copy of this map.
 *
 * @return a shallow copy of this map.
 */
@SuppressWarnings("unchecked")
@Override public Object clone() {
  /*
   * This could be made more efficient. It unnecessarily hashes all of
   * the elements in the map.
   */
  HashMap<K, V> result;
  try {
    result = (HashMap<K, V>) super.clone();
  } catch (CloneNotSupportedException e) {
    throw new AssertionError(e);
  }
  // Restore clone to empty state, retaining our capacity and threshold
  result.makeTable(table.length);
  result.entryForNullKey = null;
  result.size = 0;
  result.keySet = null;
  result.entrySet = null;
  result.values = null;
  result.init(); // Give subclass a chance to initialize itself
  result.constructorPutAll(this); // Calls method overridden in subclass!!
  return result;
}
java.utilHashMapinit

Javadoc

This method is called from the pseudo-constructors (clone and readObject) prior to invoking constructorPut/constructorPutAll, which invoke the overridden constructorNewEntry method. Normally it is a VERY bad idea to invoke an overridden method from a pseudo-constructor (Effective Java Item 17). In this case it is unavoidable, and the init method provides a workaround.

Popular methods of HashMap

  • <init>
    Constructs a new HashMap instance containing the mappings from the specified map.
  • put
    Maps the specified key to the specified value.
  • get
    Returns the value of the mapping with the specified key.
  • containsKey
    Returns whether this map contains the specified key.
  • keySet
    Returns a set of the keys contained in this map. The set is backed by this map so changes to one are
  • remove
  • entrySet
    Returns a set containing all of the mappings in this map. Each mapping is an instance of Map.Entry.
  • values
    Returns a collection of the values contained in this map. The collection is backed by this map so ch
  • size
    Returns the number of elements in this map.
  • clear
    Removes all mappings from this hash map, leaving it empty.
  • isEmpty
    Returns whether this map is empty.
  • putAll
    Copies all the mappings in the specified map to this map. These mappings will replace all mappings t
  • isEmpty,
  • putAll,
  • clone,
  • toString,
  • containsValue,
  • equals,
  • hashCode,
  • computeIfAbsent,
  • getOrDefault,
  • forEach

Popular in Java

  • Parsing JSON documents to java classes using gson
  • setRequestProperty (URLConnection)
  • getResourceAsStream (ClassLoader)
  • putExtra (Intent)
  • ConnectException (java.net)
    A ConnectException is thrown if a connection cannot be established to a remote host on a specific po
  • AtomicInteger (java.util.concurrent.atomic)
    An int value that may be updated atomically. See the java.util.concurrent.atomic package specificati
  • Manifest (java.util.jar)
    The Manifest class is used to obtain attribute information for a JarFile and its entries.
  • DataSource (javax.sql)
    An interface for the creation of Connection objects which represent a connection to a database. This
  • Response (javax.ws.rs.core)
    Defines the contract between a returned instance and the runtime when an application needs to provid
  • FileUtils (org.apache.commons.io)
    General file manipulation utilities. Facilities are provided in the following areas: * writing to a
  • Top plugins for WebStorm
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now