1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
   | public V get(Object key) {      Node<K,V>[] tab; Node<K,V> e, p; int n, eh; K ek;      int h = spread(key.hashCode());      if ((tab = table) != null && (n = tab.length) > 0 &&          (e = tabAt(tab, (n - 1) & h)) != null) {          if ((eh = e.hash) == h) {              if ((ek = e.key) == key || (ek != null && key.equals(ek)))                  return e.val;          }          else if (eh < 0)              return (p = e.find(h, key)) != null ? p.val : null;          while ((e = e.next) != null) {              if (e.hash == h &&                  ((ek = e.key) == key || (ek != null && key.equals(ek))))                  return e.val;          }      }      return null;  }
         final V putVal(K key, V value, boolean onlyIfAbsent) {      if (key == null || value == null) throw new NullPointerException();      int hash = spread(key.hashCode());      int binCount = 0;      for (Node<K,V>[] tab = table;;) {          Node<K,V> f; int n, i, fh;          if (tab == null || (n = tab.length) == 0)              tab = initTable();          else if ((f = tabAt(tab, i = (n - 1) & hash)) == null) {              if (casTabAt(tab, i, null,                           new Node<K,V>(hash, key, value, null)))                  break;            }          else if ((fh = f.hash) == MOVED)              tab = helpTransfer(tab, f);          else {              V oldVal = null;              synchronized (f) {                  if (tabAt(tab, i) == f) {                      if (fh >= 0) {                          binCount = 1;                          for (Node<K,V> e = f;; ++binCount) {                              K ek;                              if (e.hash == hash &&                                  ((ek = e.key) == key ||                                   (ek != null && key.equals(ek)))) {                                  oldVal = e.val;                                  if (!onlyIfAbsent)                                      e.val = value;                                  break;                              }                              Node<K,V> pred = e;                              if ((e = e.next) == null) {                                  pred.next = new Node<K,V>(hash, key,                                                            value, null);                                  break;                              }                          }                      }                      else if (f instanceof TreeBin) {                          Node<K,V> p;                          binCount = 2;                          if ((p = ((TreeBin<K,V>)f).putTreeVal(hash, key,                                                         value)) != null) {                              oldVal = p.val;                              if (!onlyIfAbsent)                                  p.val = value;                          }                      }                  }              }              if (binCount != 0) {                  if (binCount >= TREEIFY_THRESHOLD)                      treeifyBin(tab, i);                  if (oldVal != null)                      return oldVal;                  break;              }          }      }      addCount(1L, binCount);      return null;  }
  |