当前位置: 首页>>代码示例>>Java>>正文


Java ReferenceEntry类代码示例

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


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


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