1362 }
1363
1364 private void expungeStaleElements() {
1365 Reference<? extends T> reference;
1366 while ((reference = stale.poll()) != null) {
1367 map.remove(reference);
1368 }
1369 }
1370
1371 private static class WeakEntry<T> extends WeakReference<T> {
1372
1373 public final int hashcode;
1374
1375 public WeakEntry(T key, ReferenceQueue<T> queue) {
1376 super(key, queue);
1377 hashcode = key.hashCode();
1378 }
1379
1380 /**
1381 * This implementation returns {@code true} if {@code obj} is another
1382 * {@code WeakEntry} whose referent is equals to this referent, or
1383 * if {@code obj} is equals to the referent of this. This allows
1384 * lookups to be made without wrapping in a {@code WeakEntry}.
1385 *
1386 * @param obj the object to compare
1387 * @return true if {@code obj} is equals to this or the referent of this
1388 * @see MethodType#equals(Object)
1389 * @see Object#equals(Object)
1390 */
1391 @Override
1392 public boolean equals(Object obj) {
1393 Object mine = get();
1394 if (obj instanceof WeakEntry) {
1395 Object that = ((WeakEntry) obj).get();
1396 return (that == null || mine == null) ? (this == obj) : mine.equals(that);
1397 }
1398 return (mine == null) ? (obj == null) : mine.equals(obj);
1399 }
1400
1401 @Override
1402 public int hashCode() {
1403 return hashcode;
1404 }
1405
1406 }
1407 }
|
1362 }
1363
1364 private void expungeStaleElements() {
1365 Reference<? extends T> reference;
1366 while ((reference = stale.poll()) != null) {
1367 map.remove(reference);
1368 }
1369 }
1370
1371 private static class WeakEntry<T> extends WeakReference<T> {
1372
1373 public final int hashcode;
1374
1375 public WeakEntry(T key, ReferenceQueue<T> queue) {
1376 super(key, queue);
1377 hashcode = key.hashCode();
1378 }
1379
1380 /**
1381 * This implementation returns {@code true} if {@code obj} is another
1382 * {@code WeakEntry} whose referent is equal to this referent, or
1383 * if {@code obj} is equal to the referent of this. This allows
1384 * lookups to be made without wrapping in a {@code WeakEntry}.
1385 *
1386 * @param obj the object to compare
1387 * @return true if {@code obj} is equal to this or the referent of this
1388 * @see MethodType#equals(Object)
1389 * @see Object#equals(Object)
1390 */
1391 @Override
1392 public boolean equals(Object obj) {
1393 Object mine = get();
1394 if (obj instanceof WeakEntry) {
1395 Object that = ((WeakEntry) obj).get();
1396 return (that == null || mine == null) ? (this == obj) : mine.equals(that);
1397 }
1398 return (mine == null) ? (obj == null) : mine.equals(obj);
1399 }
1400
1401 @Override
1402 public int hashCode() {
1403 return hashcode;
1404 }
1405
1406 }
1407 }
|