379 |
|
* <code>null</code>. |
380 |
|
* @see #put(Object, Object) |
381 |
|
*/ |
382 |
< |
public V get(Object key) { |
382 |
> |
public V get(K key) { |
383 |
|
int hash = hash(key); // throws null pointer exception if key null |
384 |
|
|
385 |
|
// Try first without locking... |
430 |
|
* @see #contains(Object) |
431 |
|
*/ |
432 |
|
public boolean containsKey(Object key) { |
433 |
< |
return get(key) != null; |
433 |
> |
// Annoyingly, for now, duplicate get, since can't call |
434 |
> |
// because different signatures. |
435 |
> |
|
436 |
> |
int hash = hash(key); // throws null pointer exception if key null |
437 |
> |
|
438 |
> |
// Try first without locking... |
439 |
> |
Entry<K,V>[] tab = table; |
440 |
> |
int index = hash & (tab.length - 1); |
441 |
> |
Entry<K,V> first = tab[index]; |
442 |
> |
Entry<K,V> e; |
443 |
> |
|
444 |
> |
for (e = first; e != null; e = e.next) { |
445 |
> |
if (e.hash == hash && eq(key, e.key)) { |
446 |
> |
V value = e.value; |
447 |
> |
if (value != null) |
448 |
> |
return true; |
449 |
> |
else |
450 |
> |
break; |
451 |
> |
} |
452 |
> |
} |
453 |
> |
|
454 |
> |
// Recheck under synch if key apparently not there or interference |
455 |
> |
Segment seg = segments[hash & SEGMENT_MASK]; |
456 |
> |
seg.lock(); |
457 |
> |
try { |
458 |
> |
tab = table; |
459 |
> |
index = hash & (tab.length - 1); |
460 |
> |
Entry<K,V> newFirst = tab[index]; |
461 |
> |
if (e != null || first != newFirst) { |
462 |
> |
for (e = newFirst; e != null; e = e.next) { |
463 |
> |
if (e.hash == hash && eq(key, e.key)) |
464 |
> |
return true; |
465 |
> |
} |
466 |
> |
} |
467 |
> |
return false; |
468 |
> |
} |
469 |
> |
finally { |
470 |
> |
seg.unlock(); |
471 |
> |
} |
472 |
|
} |
473 |
|
|
474 |
|
|