• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java ReferenceEntry类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.google.common.collect.MapMakerInternalMap.ReferenceEntry的典型用法代码示例。如果您正苦于以下问题:Java ReferenceEntry类的具体用法?Java ReferenceEntry怎么用?Java ReferenceEntry使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ReferenceEntry类属于com.google.common.collect.MapMakerInternalMap包,在下文中一共展示了ReferenceEntry类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: intern

import com.google.common.collect.MapMakerInternalMap.ReferenceEntry; //导入依赖的package包/类
@Override
public E intern(E sample) {
  while (true) {
    // trying to read the canonical...
    ReferenceEntry<E, Dummy> entry = map.getEntry(sample);
    if (entry != null) {
      E canonical = entry.getKey();
      if (canonical != null) { // only matters if weak/soft keys are used
        return canonical;
      }
    }

    // didn't see it, trying to put it instead...
    Dummy sneaky = map.putIfAbsent(sample, Dummy.VALUE);
    if (sneaky == null) {
      return sample;
    } else {
      /* Someone beat us to it! Trying again...
       *
       * Technically this loop not guaranteed to terminate, so theoretically (extremely
       * unlikely) this thread might starve, but even then, there is always going to be another
       * thread doing progress here.
       */}
  }
}
 
开发者ID:antlr,项目名称:codebuff,代码行数:26,代码来源:Interners.java


示例2: intern

import com.google.common.collect.MapMakerInternalMap.ReferenceEntry; //导入依赖的package包/类
@Override
public E intern(E sample) {
  while (true) {
    // trying to read the canonical...
    ReferenceEntry<E, Dummy> entry = map.getEntry(sample);
    if (entry != null) {
      E canonical = entry.getKey();
      if (canonical != null) { // only matters if weak/soft keys are used
        return canonical;
      }
    }

    // didn't see it, trying to put it instead...
    Dummy sneaky = map.putIfAbsent(sample, Dummy.VALUE);
    if (sneaky == null) {
      return sample;
    } else {
      /* Someone beat us to it! Trying again...
       *
       * Technically this loop not guaranteed to terminate, so theoretically (extremely
       * unlikely) this thread might starve, but even then, there is always going to be another
       * thread doing progress here.
       */
    }
  }
}
 
开发者ID:antlr,项目名称:codebuff,代码行数:27,代码来源:Interners.java


示例3: intern

import com.google.common.collect.MapMakerInternalMap.ReferenceEntry; //导入依赖的package包/类
@Override public E intern(E sample) {
  while (true) {
    // trying to read the canonical...
    ReferenceEntry<E, Dummy> entry = map.getEntry(sample);
    if (entry != null) {
      E canonical = entry.getKey();
      if (canonical != null) { // only matters if weak/soft keys are used
        return canonical;
      }
    }

    // didn't see it, trying to put it instead...
    Dummy sneaky = map.putIfAbsent(sample, Dummy.VALUE);
    if (sneaky == null) {
      return sample;
    } else {
      /* Someone beat us to it! Trying again...
       *
       * Technically this loop not guaranteed to terminate, so theoretically (extremely
       * unlikely) this thread might starve, but even then, there is always going to be another
       * thread doing progress here.
       */
    }
  }
}
 
开发者ID:cplutte,项目名称:bts,代码行数:26,代码来源:Interners.java


示例4: testRemovalListener_collected

import com.google.common.collect.MapMakerInternalMap.ReferenceEntry; //导入依赖的package包/类
public void testRemovalListener_collected() {
  QueuingRemovalListener<Object, Object> listener =
      new QueuingRemovalListener<Object, Object>();
  MapMakerInternalMap<Object, Object> map = makeMap(createMapMaker()
      .concurrencyLevel(1)
      .softValues()
      .removalListener(listener));
  Segment<Object, Object> segment = map.segments[0];
  assertTrue(listener.isEmpty());

  Object one = new Object();
  Object two = new Object();
  Object three = new Object();

  map.put(one, two);
  map.put(two, three);
  assertTrue(listener.isEmpty());

  int hash = map.hash(one);
  ReferenceEntry<Object, Object> entry = segment.getEntry(one, hash);
  map.reclaimValue(entry.getValueReference());
  assertNotified(listener, one, two, RemovalCause.COLLECTED);

  assertTrue(listener.isEmpty());
}
 
开发者ID:sander120786,项目名称:guava-libraries,代码行数:26,代码来源:MapMakerInternalMapTest.java


示例5: testNewEntry

import com.google.common.collect.MapMakerInternalMap.ReferenceEntry; //导入依赖的package包/类
public void testNewEntry() {
  for (MapMaker maker : allEntryTypeMakers()) {
    MapMakerInternalMap<Object, Object> map = makeMap(maker);

    Object keyOne = new Object();
    Object valueOne = new Object();
    int hashOne = map.hash(keyOne);
    ReferenceEntry<Object, Object> entryOne = map.newEntry(keyOne, hashOne, null);
    ValueReference<Object, Object> valueRefOne = map.newValueReference(entryOne, valueOne);
    assertSame(valueOne, valueRefOne.get());
    entryOne.setValueReference(valueRefOne);

    assertSame(keyOne, entryOne.getKey());
    assertEquals(hashOne, entryOne.getHash());
    assertNull(entryOne.getNext());
    assertSame(valueRefOne, entryOne.getValueReference());

    Object keyTwo = new Object();
    Object valueTwo = new Object();
    int hashTwo = map.hash(keyTwo);
    ReferenceEntry<Object, Object> entryTwo = map.newEntry(keyTwo, hashTwo, entryOne);
    ValueReference<Object, Object> valueRefTwo = map.newValueReference(entryTwo, valueTwo);
    assertSame(valueTwo, valueRefTwo.get());
    entryTwo.setValueReference(valueRefTwo);

    assertSame(keyTwo, entryTwo.getKey());
    assertEquals(hashTwo, entryTwo.getHash());
    assertSame(entryOne, entryTwo.getNext());
    assertSame(valueRefTwo, entryTwo.getValueReference());
  }
}
 
开发者ID:sander120786,项目名称:guava-libraries,代码行数:32,代码来源:MapMakerInternalMapTest.java


示例6: testCopyEntry

import com.google.common.collect.MapMakerInternalMap.ReferenceEntry; //导入依赖的package包/类
public void testCopyEntry() {
  for (MapMaker maker : allEntryTypeMakers()) {
    MapMakerInternalMap<Object, Object> map = makeMap(maker);

    Object keyOne = new Object();
    Object valueOne = new Object();
    int hashOne = map.hash(keyOne);
    ReferenceEntry<Object, Object> entryOne = map.newEntry(keyOne, hashOne, null);
    entryOne.setValueReference(map.newValueReference(entryOne, valueOne));

    Object keyTwo = new Object();
    Object valueTwo = new Object();
    int hashTwo = map.hash(keyTwo);
    ReferenceEntry<Object, Object> entryTwo = map.newEntry(keyTwo, hashTwo, entryOne);
    entryTwo.setValueReference(map.newValueReference(entryTwo, valueTwo));
    if (map.evictsBySize()) {
      MapMakerInternalMap.connectEvictables(entryOne, entryTwo);
    }
    if (map.expires()) {
      MapMakerInternalMap.connectExpirables(entryOne, entryTwo);
    }
    assertConnected(map, entryOne, entryTwo);

    ReferenceEntry<Object, Object> copyOne = map.copyEntry(entryOne, null);
    assertSame(keyOne, entryOne.getKey());
    assertEquals(hashOne, entryOne.getHash());
    assertNull(entryOne.getNext());
    assertSame(valueOne, copyOne.getValueReference().get());
    assertConnected(map, copyOne, entryTwo);

    ReferenceEntry<Object, Object> copyTwo = map.copyEntry(entryTwo, copyOne);
    assertSame(keyTwo, copyTwo.getKey());
    assertEquals(hashTwo, copyTwo.getHash());
    assertSame(copyOne, copyTwo.getNext());
    assertSame(valueTwo, copyTwo.getValueReference().get());
    assertConnected(map, copyOne, copyTwo);
  }
}
 
开发者ID:sander120786,项目名称:guava-libraries,代码行数:39,代码来源:MapMakerInternalMapTest.java


示例7: assertConnected

import com.google.common.collect.MapMakerInternalMap.ReferenceEntry; //导入依赖的package包/类
private static <K, V> void assertConnected(
    MapMakerInternalMap<K, V> map, ReferenceEntry<K, V> one, ReferenceEntry<K, V> two) {
  if (map.evictsBySize()) {
    assertSame(two, one.getNextEvictable());
  }
  if (map.expires()) {
    assertSame(two, one.getNextExpirable());
  }
}
 
开发者ID:sander120786,项目名称:guava-libraries,代码行数:10,代码来源:MapMakerInternalMapTest.java


示例8: testSegmentReplace

import com.google.common.collect.MapMakerInternalMap.ReferenceEntry; //导入依赖的package包/类
public void testSegmentReplace() {
  MapMakerInternalMap<Object, Object> map =
      makeMap(createMapMaker().concurrencyLevel(1).expireAfterAccess(99999, SECONDS));
  Segment<Object, Object> segment = map.segments[0];
  // TODO(fry): check recency ordering

  Object key = new Object();
  int hash = map.hash(key);
  Object oldValue = new Object();
  Object newValue = new Object();
  AtomicReferenceArray<ReferenceEntry<Object, Object>> table = segment.table;
  int index = hash & (table.length() - 1);

  DummyEntry<Object, Object> entry = DummyEntry.create(key, hash, null);
  DummyValueReference<Object, Object> oldValueRef = DummyValueReference.create(oldValue, entry);
  entry.setValueReference(oldValueRef);

  // no entry
  assertNull(segment.replace(key, hash, newValue));
  assertEquals(0, segment.count);

  // same key
  table.set(index, entry);
  segment.count++;
  assertEquals(1, segment.count);
  assertSame(oldValue, segment.get(key, hash));
  assertSame(oldValue, segment.replace(key, hash, newValue));
  assertEquals(1, segment.count);
  assertSame(newValue, segment.get(key, hash));

  // cleared
  entry.setValueReference(oldValueRef);
  assertSame(oldValue, segment.get(key, hash));
  oldValueRef.clear(null);
  assertNull(segment.replace(key, hash, newValue));
  assertEquals(0, segment.count);
  assertNull(segment.get(key, hash));
}
 
开发者ID:sander120786,项目名称:guava-libraries,代码行数:39,代码来源:MapMakerInternalMapTest.java


示例9: testSegmentPut

import com.google.common.collect.MapMakerInternalMap.ReferenceEntry; //导入依赖的package包/类
public void testSegmentPut() {
  MapMakerInternalMap<Object, Object> map =
      makeMap(createMapMaker().concurrencyLevel(1).expireAfterAccess(99999, SECONDS));
  Segment<Object, Object> segment = map.segments[0];
  // TODO(fry): check recency ordering

  Object key = new Object();
  int hash = map.hash(key);
  Object oldValue = new Object();
  Object newValue = new Object();

  // no entry
  assertEquals(0, segment.count);
  assertNull(segment.put(key, hash, oldValue, false));
  assertEquals(1, segment.count);

  // same key
  assertSame(oldValue, segment.put(key, hash, newValue, false));
  assertEquals(1, segment.count);
  assertSame(newValue, segment.get(key, hash));

  // cleared
  ReferenceEntry<Object, Object> entry = segment.getEntry(key, hash);
  DummyValueReference<Object, Object> oldValueRef = DummyValueReference.create(oldValue, entry);
  entry.setValueReference(oldValueRef);
  assertSame(oldValue, segment.get(key, hash));
  oldValueRef.clear(null);
  assertNull(segment.put(key, hash, newValue, false));
  assertEquals(1, segment.count);
  assertSame(newValue, segment.get(key, hash));
}
 
开发者ID:sander120786,项目名称:guava-libraries,代码行数:32,代码来源:MapMakerInternalMapTest.java


示例10: testSegmentPutIfAbsent

import com.google.common.collect.MapMakerInternalMap.ReferenceEntry; //导入依赖的package包/类
public void testSegmentPutIfAbsent() {
  MapMakerInternalMap<Object, Object> map =
      makeMap(createMapMaker().concurrencyLevel(1).expireAfterAccess(99999, SECONDS));
  Segment<Object, Object> segment = map.segments[0];
  // TODO(fry): check recency ordering

  Object key = new Object();
  int hash = map.hash(key);
  Object oldValue = new Object();
  Object newValue = new Object();

  // no entry
  assertEquals(0, segment.count);
  assertNull(segment.put(key, hash, oldValue, true));
  assertEquals(1, segment.count);

  // same key
  assertSame(oldValue, segment.put(key, hash, newValue, true));
  assertEquals(1, segment.count);
  assertSame(oldValue, segment.get(key, hash));

  // cleared
  ReferenceEntry<Object, Object> entry = segment.getEntry(key, hash);
  DummyValueReference<Object, Object> oldValueRef = DummyValueReference.create(oldValue, entry);
  entry.setValueReference(oldValueRef);
  assertSame(oldValue, segment.get(key, hash));
  oldValueRef.clear(null);
  assertNull(segment.put(key, hash, newValue, true));
  assertEquals(1, segment.count);
  assertSame(newValue, segment.get(key, hash));
}
 
开发者ID:sander120786,项目名称:guava-libraries,代码行数:32,代码来源:MapMakerInternalMapTest.java


示例11: testSegmentRemove

import com.google.common.collect.MapMakerInternalMap.ReferenceEntry; //导入依赖的package包/类
public void testSegmentRemove() {
  MapMakerInternalMap<Object, Object> map = makeMap(createMapMaker().concurrencyLevel(1));
  Segment<Object, Object> segment = map.segments[0];

  Object key = new Object();
  int hash = map.hash(key);
  Object oldValue = new Object();
  AtomicReferenceArray<ReferenceEntry<Object, Object>> table = segment.table;
  int index = hash & (table.length() - 1);

  DummyEntry<Object, Object> entry = DummyEntry.create(key, hash, null);
  DummyValueReference<Object, Object> oldValueRef = DummyValueReference.create(oldValue, entry);
  entry.setValueReference(oldValueRef);

  // no entry
  assertEquals(0, segment.count);
  assertNull(segment.remove(key, hash));
  assertEquals(0, segment.count);

  // same key
  table.set(index, entry);
  segment.count++;
  assertEquals(1, segment.count);
  assertSame(oldValue, segment.get(key, hash));
  assertSame(oldValue, segment.remove(key, hash));
  assertEquals(0, segment.count);
  assertNull(segment.get(key, hash));

  // cleared
  table.set(index, entry);
  segment.count++;
  assertEquals(1, segment.count);
  assertSame(oldValue, segment.get(key, hash));
  oldValueRef.clear(null);
  assertNull(segment.remove(key, hash));
  assertEquals(0, segment.count);
  assertNull(segment.get(key, hash));
}
 
开发者ID:sander120786,项目名称:guava-libraries,代码行数:39,代码来源:MapMakerInternalMapTest.java


示例12: testExpand

import com.google.common.collect.MapMakerInternalMap.ReferenceEntry; //导入依赖的package包/类
public void testExpand() {
  MapMakerInternalMap<Object, Object> map =
      makeMap(createMapMaker().concurrencyLevel(1).initialCapacity(1));
  Segment<Object, Object> segment = map.segments[0];
  assertEquals(1, segment.table.length());

  // manually add elements to avoid expansion
  int originalCount = 1024;
  ReferenceEntry<Object, Object> entry = null;
  for (int i = 0; i < originalCount; i++) {
    Object key = new Object();
    Object value = new Object();
    int hash = map.hash(key);
    // chain all entries together as we only have a single bucket
    entry = map.newEntry(key, hash, entry);
    ValueReference<Object, Object> valueRef = map.newValueReference(entry, value);
    entry.setValueReference(valueRef);
  }
  segment.table.set(0, entry);
  segment.count = originalCount;
  ImmutableMap<Object, Object> originalMap = ImmutableMap.copyOf(map);
  assertEquals(originalCount, originalMap.size());
  assertEquals(originalMap, map);

  for (int i = 1; i <= originalCount * 2; i *= 2) {
    if (i > 1) {
      segment.expand();
    }
    assertEquals(i, segment.table.length());
    assertEquals(originalCount, countLiveEntries(map));
    assertEquals(originalCount, segment.count);
    assertEquals(originalMap, map);
  }
}
 
开发者ID:sander120786,项目名称:guava-libraries,代码行数:35,代码来源:MapMakerInternalMapTest.java


示例13: countLiveEntries

import com.google.common.collect.MapMakerInternalMap.ReferenceEntry; //导入依赖的package包/类
private static <K, V> int countLiveEntries(MapMakerInternalMap<K, V> map) {
  int result = 0;
  for (Segment<K, V> segment : map.segments) {
    AtomicReferenceArray<ReferenceEntry<K, V>> table = segment.table;
    for (int i = 0; i < table.length(); i++) {
      for (ReferenceEntry<K, V> e = table.get(i); e != null; e = e.getNext()) {
        if (map.isLive(e)) {
          result++;
        }
      }
    }
  }
  return result;
}
 
开发者ID:sander120786,项目名称:guava-libraries,代码行数:15,代码来源:MapMakerInternalMapTest.java


示例14: testClear

import com.google.common.collect.MapMakerInternalMap.ReferenceEntry; //导入依赖的package包/类
public void testClear() {
  MapMakerInternalMap<Object, Object> map = makeMap(createMapMaker()
      .concurrencyLevel(1)
      .initialCapacity(1)
      .maximumSize(SMALL_MAX_SIZE)
      .expireAfterWrite(99999, SECONDS));
  Segment<Object, Object> segment = map.segments[0];
  AtomicReferenceArray<ReferenceEntry<Object, Object>> table = segment.table;
  assertEquals(1, table.length());

  Object key = new Object();
  Object value = new Object();
  int hash = map.hash(key);
  DummyEntry<Object, Object> entry = createDummyEntry(key, hash, value, null);
  segment.recordWrite(entry);
  segment.table.set(0, entry);
  segment.readCount.incrementAndGet();
  segment.count = 1;

  assertSame(entry, table.get(0));
  assertSame(entry, segment.evictionQueue.peek());
  assertSame(entry, segment.expirationQueue.peek());

  segment.clear();
  assertNull(table.get(0));
  assertTrue(segment.evictionQueue.isEmpty());
  assertTrue(segment.expirationQueue.isEmpty());
  assertEquals(0, segment.readCount.get());
  assertEquals(0, segment.count);
}
 
开发者ID:sander120786,项目名称:guava-libraries,代码行数:31,代码来源:MapMakerInternalMapTest.java


示例15: testRemoveEntry

import com.google.common.collect.MapMakerInternalMap.ReferenceEntry; //导入依赖的package包/类
public void testRemoveEntry() {
  MapMakerInternalMap<Object, Object> map = makeMap(createMapMaker()
      .concurrencyLevel(1)
      .initialCapacity(1)
      .maximumSize(SMALL_MAX_SIZE)
      .expireAfterWrite(99999, SECONDS)
      .removalListener(new CountingRemovalListener<Object, Object>()));
  Segment<Object, Object> segment = map.segments[0];
  AtomicReferenceArray<ReferenceEntry<Object, Object>> table = segment.table;
  assertEquals(1, table.length());

  Object key = new Object();
  Object value = new Object();
  int hash = map.hash(key);
  DummyEntry<Object, Object> entry = createDummyEntry(key, hash, value, null);

  // remove absent
  assertFalse(segment.removeEntry(entry, hash, RemovalCause.COLLECTED));

  // remove live
  segment.recordWrite(entry);
  table.set(0, entry);
  segment.count = 1;
  assertTrue(segment.removeEntry(entry, hash, RemovalCause.COLLECTED));
  assertNotificationEnqueued(map, key, value);
  assertTrue(map.removalNotificationQueue.isEmpty());
  assertFalse(segment.evictionQueue.contains(entry));
  assertFalse(segment.expirationQueue.contains(entry));
  assertEquals(0, segment.count);
  assertNull(table.get(0));
}
 
开发者ID:sander120786,项目名称:guava-libraries,代码行数:32,代码来源:MapMakerInternalMapTest.java


示例16: checkAndDrainRecencyQueue

import com.google.common.collect.MapMakerInternalMap.ReferenceEntry; //导入依赖的package包/类
static <K, V> void checkAndDrainRecencyQueue(MapMakerInternalMap<K, V> map,
    Segment<K, V> segment, List<ReferenceEntry<K, V>> reads) {
  if (map.evictsBySize() || map.expiresAfterAccess()) {
    assertSameEntries(reads, ImmutableList.copyOf(segment.recencyQueue));
  }
  segment.drainRecencyQueue();
}
 
开发者ID:sander120786,项目名称:guava-libraries,代码行数:8,代码来源:MapMakerInternalMapTest.java


示例17: checkEvictionQueues

import com.google.common.collect.MapMakerInternalMap.ReferenceEntry; //导入依赖的package包/类
static <K, V> void checkEvictionQueues(MapMakerInternalMap<K, V> map,
    Segment<K, V> segment, List<ReferenceEntry<K, V>> readOrder,
    List<ReferenceEntry<K, V>> writeOrder) {
  if (map.evictsBySize()) {
    assertSameEntries(readOrder, ImmutableList.copyOf(segment.evictionQueue));
  }
  if (map.expiresAfterAccess()) {
    assertSameEntries(readOrder, ImmutableList.copyOf(segment.expirationQueue));
  }
  if (map.expiresAfterWrite()) {
    assertSameEntries(writeOrder, ImmutableList.copyOf(segment.expirationQueue));
  }
}
 
开发者ID:sander120786,项目名称:guava-libraries,代码行数:14,代码来源:MapMakerInternalMapTest.java


示例18: assertSameEntries

import com.google.common.collect.MapMakerInternalMap.ReferenceEntry; //导入依赖的package包/类
private static <K, V> void assertSameEntries(List<ReferenceEntry<K, V>> expectedEntries,
    List<ReferenceEntry<K, V>> actualEntries) {
  int size = expectedEntries.size();
  assertEquals(size, actualEntries.size());
  for (int i = 0; i < size; i++) {
    ReferenceEntry<K, V> expectedEntry = expectedEntries.get(0);
    ReferenceEntry<K, V> actualEntry = actualEntries.get(0);
    assertSame(expectedEntry.getKey(), actualEntry.getKey());
    assertSame(expectedEntry.getValueReference().get(), actualEntry.getValueReference().get());
  }
}
 
开发者ID:sander120786,项目名称:guava-libraries,代码行数:12,代码来源:MapMakerInternalMapTest.java


示例19: testEvictEntries

import com.google.common.collect.MapMakerInternalMap.ReferenceEntry; //导入依赖的package包/类
public void testEvictEntries() {
  int maxSize = 10;
  MapMakerInternalMap<Object, Object> map =
      makeMap(createMapMaker().concurrencyLevel(1).maximumSize(maxSize));
  Segment<Object, Object> segment = map.segments[0];

  // manually add elements to avoid eviction
  int originalCount = 1024;
  ReferenceEntry<Object, Object> entry = null;
  LinkedHashMap<Object, Object> originalMap = Maps.newLinkedHashMap();
  for (int i = 0; i < originalCount; i++) {
    Object key = new Object();
    Object value = new Object();
    AtomicReferenceArray<ReferenceEntry<Object, Object>> table = segment.table;
    int hash = map.hash(key);
    int index = hash & (table.length() - 1);
    ReferenceEntry<Object, Object> first = table.get(index);
    entry = map.newEntry(key, hash, first);
    ValueReference<Object, Object> valueRef = map.newValueReference(entry, value);
    entry.setValueReference(valueRef);
    segment.recordWrite(entry);
    table.set(index, entry);
    originalMap.put(key, value);
  }
  segment.count = originalCount;
  assertEquals(originalCount, originalMap.size());
  assertEquals(originalMap, map);

  for (int i = maxSize - 1; i < originalCount; i++) {
    assertTrue(segment.evictEntries());
    Iterator<Object> it = originalMap.keySet().iterator();
    it.next();
    it.remove();
    assertEquals(originalMap, map);
  }
  assertFalse(segment.evictEntries());
}
 
开发者ID:sander120786,项目名称:guava-libraries,代码行数:38,代码来源:MapMakerInternalMapTest.java


示例20: testDrainKeyReferenceQueueOnWrite

import com.google.common.collect.MapMakerInternalMap.ReferenceEntry; //导入依赖的package包/类
public void testDrainKeyReferenceQueueOnWrite() {
  for (MapMaker maker : allKeyValueStrengthMakers()) {
    MapMakerInternalMap<Object, Object> map =
        makeMap(maker.concurrencyLevel(1));
    if (map.usesKeyReferences()) {
      Segment<Object, Object> segment = map.segments[0];

      Object keyOne = new Object();
      int hashOne = map.hash(keyOne);
      Object valueOne = new Object();
      Object keyTwo = new Object();
      Object valueTwo = new Object();

      map.put(keyOne, valueOne);
      ReferenceEntry<Object, Object> entry = segment.getEntry(keyOne, hashOne);

      @SuppressWarnings("unchecked")
      Reference<Object> reference = (Reference) entry;
      reference.enqueue();

      map.put(keyTwo, valueTwo);
      assertFalse(map.containsKey(keyOne));
      assertFalse(map.containsValue(valueOne));
      assertNull(map.get(keyOne));
      assertEquals(1, map.size());
      assertNull(segment.keyReferenceQueue.poll());
    }
  }
}
 
开发者ID:sander120786,项目名称:guava-libraries,代码行数:30,代码来源:MapMakerInternalMapTest.java



注:本文中的com.google.common.collect.MapMakerInternalMap.ReferenceEntry类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java FTPFileFilter类代码示例发布时间:2022-05-22
下一篇:
Java RpcProgramMountd类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap