< prev index next >

src/java.base/share/classes/java/util/HashMap.java

Print this page




 484         this.loadFactor = DEFAULT_LOAD_FACTOR;
 485         putMapEntries(m, false);
 486     }
 487 
 488     /**
 489      * Implements Map.putAll and Map constructor.
 490      *
 491      * @param m the map
 492      * @param evict false when initially constructing this map, else
 493      * true (relayed to method afterNodeInsertion).
 494      */
 495     final void putMapEntries(Map<? extends K, ? extends V> m, boolean evict) {
 496         int s = m.size();
 497         if (s > 0) {
 498             if (table == null) { // pre-size
 499                 float ft = ((float)s / loadFactor) + 1.0F;
 500                 int t = ((ft < (float)MAXIMUM_CAPACITY) ?
 501                          (int)ft : MAXIMUM_CAPACITY);
 502                 if (t > threshold)
 503                     threshold = tableSizeFor(t);
 504             }
 505             else if (s > threshold)



 506                 resize();


 507             for (Map.Entry<? extends K, ? extends V> e : m.entrySet()) {
 508                 K key = e.getKey();
 509                 V value = e.getValue();
 510                 putVal(hash(key), key, value, false, evict);
 511             }
 512         }
 513     }
 514 
 515     /**
 516      * Returns the number of key-value mappings in this map.
 517      *
 518      * @return the number of key-value mappings in this map
 519      */
 520     public int size() {
 521         return size;
 522     }
 523 
 524     /**
 525      * Returns {@code true} if this map contains no key-value mappings.
 526      *




 484         this.loadFactor = DEFAULT_LOAD_FACTOR;
 485         putMapEntries(m, false);
 486     }
 487 
 488     /**
 489      * Implements Map.putAll and Map constructor.
 490      *
 491      * @param m the map
 492      * @param evict false when initially constructing this map, else
 493      * true (relayed to method afterNodeInsertion).
 494      */
 495     final void putMapEntries(Map<? extends K, ? extends V> m, boolean evict) {
 496         int s = m.size();
 497         if (s > 0) {
 498             if (table == null) { // pre-size
 499                 float ft = ((float)s / loadFactor) + 1.0F;
 500                 int t = ((ft < (float)MAXIMUM_CAPACITY) ?
 501                          (int)ft : MAXIMUM_CAPACITY);
 502                 if (t > threshold)
 503                     threshold = tableSizeFor(t);
 504             } else {
 505                 // Because of linked-list buckets constraints, we cannot
 506                 // expand all at once, but can reduce total resize
 507                 // effort by repeated doubling now vs later
 508                 while (table.length <  MAXIMUM_CAPACITY && s > threshold) {
 509                     resize();
 510                 }
 511             }
 512             for (Map.Entry<? extends K, ? extends V> e : m.entrySet()) {
 513                 K key = e.getKey();
 514                 V value = e.getValue();
 515                 putVal(hash(key), key, value, false, evict);
 516             }
 517         }
 518     }
 519 
 520     /**
 521      * Returns the number of key-value mappings in this map.
 522      *
 523      * @return the number of key-value mappings in this map
 524      */
 525     public int size() {
 526         return size;
 527     }
 528 
 529     /**
 530      * Returns {@code true} if this map contains no key-value mappings.
 531      *


< prev index next >