本文整理汇总了Java中com.google.common.cache.LocalCache.Strength类的典型用法代码示例。如果您正苦于以下问题:Java Strength类的具体用法?Java Strength怎么用?Java Strength使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Strength类属于com.google.common.cache.LocalCache包,在下文中一共展示了Strength类的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: cacheFactory
import com.google.common.cache.LocalCache.Strength; //导入依赖的package包/类
private CacheBuilderFactory cacheFactory() {
return new CacheBuilderFactory()
.withKeyStrengths(ImmutableSet.of(Strength.STRONG, Strength.WEAK))
.withValueStrengths(ImmutableSet.copyOf(Strength.values()))
.withConcurrencyLevels(ImmutableSet.of(1, 4, 16, 64))
.withMaximumSizes(ImmutableSet.of(0, 1, 10, 100, 1000))
.withInitialCapacities(ImmutableSet.of(0, 1, 10, 100, 1000))
.withExpireAfterWrites(ImmutableSet.of(
DurationSpec.of(0, SECONDS),
DurationSpec.of(1, SECONDS),
DurationSpec.of(1, DAYS)))
.withExpireAfterAccesses(ImmutableSet.of(
DurationSpec.of(0, SECONDS),
DurationSpec.of(1, SECONDS),
DurationSpec.of(1, DAYS)))
.withRefreshes(ImmutableSet.of(
DurationSpec.of(1, SECONDS),
DurationSpec.of(1, DAYS)));
}
开发者ID:zugzug90,项目名称:guava-mock,代码行数:20,代码来源:EmptyCachesTest.java
示例2: testEntryFactory
import com.google.common.cache.LocalCache.Strength; //导入依赖的package包/类
public void testEntryFactory() {
assertSame(EntryFactory.STRONG,
EntryFactory.getFactory(Strength.STRONG, false, false));
assertSame(EntryFactory.STRONG_ACCESS,
EntryFactory.getFactory(Strength.STRONG, true, false));
assertSame(EntryFactory.STRONG_WRITE,
EntryFactory.getFactory(Strength.STRONG, false, true));
assertSame(EntryFactory.STRONG_ACCESS_WRITE,
EntryFactory.getFactory(Strength.STRONG, true, true));
assertSame(EntryFactory.WEAK,
EntryFactory.getFactory(Strength.WEAK, false, false));
assertSame(EntryFactory.WEAK_ACCESS,
EntryFactory.getFactory(Strength.WEAK, true, false));
assertSame(EntryFactory.WEAK_WRITE,
EntryFactory.getFactory(Strength.WEAK, false, true));
assertSame(EntryFactory.WEAK_ACCESS_WRITE,
EntryFactory.getFactory(Strength.WEAK, true, true));
}
开发者ID:zugzug90,项目名称:guava-mock,代码行数:19,代码来源:LocalCacheTest.java
示例3: cacheFactory
import com.google.common.cache.LocalCache.Strength; //导入依赖的package包/类
private CacheBuilderFactory cacheFactory() {
// This is trickier than expected. We plan to put 15 values in each of these (WARMUP_MIN to
// WARMUP_MAX), but the tests assume no values get evicted. Even with a maximumSize of 100, one
// of the values gets evicted. With weak keys, we use identity equality, which means using
// System.identityHashCode, which means the assignment of keys to segments is nondeterministic,
// so more than (maximumSize / #segments) keys could get assigned to the same segment, which
// would cause one to be evicted.
return new CacheBuilderFactory()
.withKeyStrengths(ImmutableSet.of(Strength.STRONG, Strength.WEAK))
.withValueStrengths(ImmutableSet.copyOf(Strength.values()))
.withConcurrencyLevels(ImmutableSet.of(1, 4, 16, 64))
.withMaximumSizes(ImmutableSet.of(400, 1000))
.withInitialCapacities(ImmutableSet.of(0, 1, 10, 100, 1000))
.withExpireAfterWrites(ImmutableSet.of(
// DurationSpec.of(500, MILLISECONDS),
DurationSpec.of(1, SECONDS),
DurationSpec.of(1, DAYS)))
.withExpireAfterAccesses(ImmutableSet.of(
// DurationSpec.of(500, MILLISECONDS),
DurationSpec.of(1, SECONDS),
DurationSpec.of(1, DAYS)))
.withRefreshes(ImmutableSet.of(
// DurationSpec.of(500, MILLISECONDS),
DurationSpec.of(1, SECONDS),
DurationSpec.of(1, DAYS)));
}
开发者ID:zugzug90,项目名称:guava-mock,代码行数:27,代码来源:PopulatedCachesTest.java
示例4: testParse_multipleKeys
import com.google.common.cache.LocalCache.Strength; //导入依赖的package包/类
public void testParse_multipleKeys() {
CacheBuilderSpec spec = parse("initialCapacity=10,maximumSize=20,concurrencyLevel=30,"
+ "weakKeys,weakValues,expireAfterAccess=10m,expireAfterWrite=1h");
assertEquals(10, spec.initialCapacity.intValue());
assertEquals(20, spec.maximumSize.intValue());
assertNull(spec.maximumWeight);
assertEquals(30, spec.concurrencyLevel.intValue());
assertEquals(Strength.WEAK, spec.keyStrength);
assertEquals(Strength.WEAK, spec.valueStrength);
assertEquals(TimeUnit.HOURS, spec.writeExpirationTimeUnit);
assertEquals(TimeUnit.MINUTES, spec.accessExpirationTimeUnit);
assertEquals(1L, spec.writeExpirationDuration);
assertEquals(10L, spec.accessExpirationDuration);
CacheBuilder<?, ?> expected = CacheBuilder.newBuilder()
.initialCapacity(10)
.maximumSize(20)
.concurrencyLevel(30)
.weakKeys()
.weakValues()
.expireAfterAccess(10L, TimeUnit.MINUTES)
.expireAfterWrite(1L, TimeUnit.HOURS);
assertCacheBuilderEquivalence(expected, CacheBuilder.from(spec));
}
开发者ID:zugzug90,项目名称:guava-mock,代码行数:24,代码来源:CacheBuilderSpecTest.java
示例5: testParse_whitespaceAllowed
import com.google.common.cache.LocalCache.Strength; //导入依赖的package包/类
public void testParse_whitespaceAllowed() {
CacheBuilderSpec spec = parse(" initialCapacity=10,\nmaximumSize=20,\t\r"
+ "weakKeys \t ,softValues \n , \r expireAfterWrite \t = 15s\n\n");
assertEquals(10, spec.initialCapacity.intValue());
assertEquals(20, spec.maximumSize.intValue());
assertNull(spec.maximumWeight);
assertNull(spec.concurrencyLevel);
assertEquals(Strength.WEAK, spec.keyStrength);
assertEquals(Strength.SOFT, spec.valueStrength);
assertEquals(TimeUnit.SECONDS, spec.writeExpirationTimeUnit);
assertEquals(15L, spec.writeExpirationDuration);
assertNull(spec.accessExpirationTimeUnit);
CacheBuilder<?, ?> expected = CacheBuilder.newBuilder()
.initialCapacity(10)
.maximumSize(20)
.weakKeys()
.softValues()
.expireAfterWrite(15L, TimeUnit.SECONDS);
assertCacheBuilderEquivalence(expected, CacheBuilder.from(spec));
}
开发者ID:zugzug90,项目名称:guava-mock,代码行数:21,代码来源:CacheBuilderSpecTest.java
示例6: buildAllPermutations
import com.google.common.cache.LocalCache.Strength; //导入依赖的package包/类
Iterable<CacheBuilder<Object, Object>> buildAllPermutations() {
@SuppressWarnings("unchecked")
Iterable<List<Object>> combinations = buildCartesianProduct(concurrencyLevels,
initialCapacities, maximumSizes, expireAfterWrites, expireAfterAccesses, refreshes,
keyStrengths, valueStrengths);
return Iterables.transform(combinations,
new Function<List<Object>, CacheBuilder<Object, Object>>() {
@Override public CacheBuilder<Object, Object> apply(List<Object> combination) {
return createCacheBuilder(
(Integer) combination.get(0),
(Integer) combination.get(1),
(Integer) combination.get(2),
(DurationSpec) combination.get(3),
(DurationSpec) combination.get(4),
(DurationSpec) combination.get(5),
(Strength) combination.get(6),
(Strength) combination.get(7));
}
});
}
开发者ID:zugzug90,项目名称:guava-mock,代码行数:21,代码来源:CacheBuilderFactory.java
示例7: cacheFactory
import com.google.common.cache.LocalCache.Strength; //导入依赖的package包/类
private CacheBuilderFactory cacheFactory() {
// This is trickier than expected. We plan to put 15 values in each of these (WARMUP_MIN to
// WARMUP_MAX), but the tests assume no values get evicted. Even with a maximumSize of 100, one
// of the values gets evicted. With weak keys, we use identity equality, which means using
// System.identityHashCode, which means the assignment of keys to segments is nondeterministic,
// so more than (maximumSize / #segments) keys could get assigned to the same segment, which
// would cause one to be evicted.
return new CacheBuilderFactory()
.withKeyStrengths(ImmutableSet.of(Strength.STRONG, Strength.WEAK))
.withValueStrengths(ImmutableSet.copyOf(Strength.values()))
.withConcurrencyLevels(ImmutableSet.of(1, 4, 16, 64))
.withMaximumSizes(ImmutableSet.of(400, 1000))
.withInitialCapacities(ImmutableSet.of(0, 1, 10, 100, 1000))
.withExpireAfterWrites(
ImmutableSet.of(
// DurationSpec.of(500, MILLISECONDS),
DurationSpec.of(1, SECONDS), DurationSpec.of(1, DAYS)))
.withExpireAfterAccesses(
ImmutableSet.of(
// DurationSpec.of(500, MILLISECONDS),
DurationSpec.of(1, SECONDS), DurationSpec.of(1, DAYS)))
.withRefreshes(
ImmutableSet.of(
// DurationSpec.of(500, MILLISECONDS),
DurationSpec.of(1, SECONDS), DurationSpec.of(1, DAYS)));
}
开发者ID:google,项目名称:guava,代码行数:27,代码来源:PopulatedCachesTest.java
示例8: testParse_multipleKeys
import com.google.common.cache.LocalCache.Strength; //导入依赖的package包/类
public void testParse_multipleKeys() {
CacheBuilderSpec spec =
parse(
"initialCapacity=10,maximumSize=20,concurrencyLevel=30,"
+ "weakKeys,weakValues,expireAfterAccess=10m,expireAfterWrite=1h");
assertEquals(10, spec.initialCapacity.intValue());
assertEquals(20, spec.maximumSize.intValue());
assertNull(spec.maximumWeight);
assertEquals(30, spec.concurrencyLevel.intValue());
assertEquals(Strength.WEAK, spec.keyStrength);
assertEquals(Strength.WEAK, spec.valueStrength);
assertEquals(TimeUnit.HOURS, spec.writeExpirationTimeUnit);
assertEquals(TimeUnit.MINUTES, spec.accessExpirationTimeUnit);
assertEquals(1L, spec.writeExpirationDuration);
assertEquals(10L, spec.accessExpirationDuration);
CacheBuilder<?, ?> expected =
CacheBuilder.newBuilder()
.initialCapacity(10)
.maximumSize(20)
.concurrencyLevel(30)
.weakKeys()
.weakValues()
.expireAfterAccess(10L, TimeUnit.MINUTES)
.expireAfterWrite(1L, TimeUnit.HOURS);
assertCacheBuilderEquivalence(expected, CacheBuilder.from(spec));
}
开发者ID:google,项目名称:guava,代码行数:27,代码来源:CacheBuilderSpecTest.java
示例9: testParse_whitespaceAllowed
import com.google.common.cache.LocalCache.Strength; //导入依赖的package包/类
public void testParse_whitespaceAllowed() {
CacheBuilderSpec spec =
parse(
" initialCapacity=10,\nmaximumSize=20,\t\r"
+ "weakKeys \t ,softValues \n , \r expireAfterWrite \t = 15s\n\n");
assertEquals(10, spec.initialCapacity.intValue());
assertEquals(20, spec.maximumSize.intValue());
assertNull(spec.maximumWeight);
assertNull(spec.concurrencyLevel);
assertEquals(Strength.WEAK, spec.keyStrength);
assertEquals(Strength.SOFT, spec.valueStrength);
assertEquals(TimeUnit.SECONDS, spec.writeExpirationTimeUnit);
assertEquals(15L, spec.writeExpirationDuration);
assertNull(spec.accessExpirationTimeUnit);
CacheBuilder<?, ?> expected =
CacheBuilder.newBuilder()
.initialCapacity(10)
.maximumSize(20)
.weakKeys()
.softValues()
.expireAfterWrite(15L, TimeUnit.SECONDS);
assertCacheBuilderEquivalence(expected, CacheBuilder.from(spec));
}
开发者ID:google,项目名称:guava,代码行数:24,代码来源:CacheBuilderSpecTest.java
示例10: testDefaults
import com.google.common.cache.LocalCache.Strength; //导入依赖的package包/类
public void testDefaults() {
LocalCache<Object, Object> map = makeLocalCache(createCacheBuilder());
assertSame(Strength.STRONG, map.keyStrength);
assertSame(Strength.STRONG, map.valueStrength);
assertSame(map.keyStrength.defaultEquivalence(), map.keyEquivalence);
assertSame(map.valueStrength.defaultEquivalence(), map.valueEquivalence);
assertEquals(0, map.expireAfterAccessNanos);
assertEquals(0, map.expireAfterWriteNanos);
assertEquals(0, map.refreshNanos);
assertEquals(CacheBuilder.UNSET_INT, map.maxWeight);
assertSame(EntryFactory.STRONG, map.entryFactory);
assertSame(CacheBuilder.NullListener.INSTANCE, map.removalListener);
assertSame(DISCARDING_QUEUE, map.removalNotificationQueue);
assertSame(NULL_TICKER, map.ticker);
assertEquals(4, map.concurrencyLevel);
// concurrency level
assertThat(map.segments).hasLength(4);
// initial capacity / concurrency level
assertEquals(16 / map.segments.length, map.segments[0].table.length());
assertFalse(map.evictsBySize());
assertFalse(map.expires());
assertFalse(map.expiresAfterWrite());
assertFalse(map.expiresAfterAccess());
assertFalse(map.refreshes());
}
开发者ID:zugzug90,项目名称:guava-mock,代码行数:32,代码来源:LocalCacheTest.java
示例11: checkStrength
import com.google.common.cache.LocalCache.Strength; //导入依赖的package包/类
private static void checkStrength(
LocalCache<Object, Object> map, Strength keyStrength, Strength valueStrength) {
assertSame(keyStrength, map.keyStrength);
assertSame(valueStrength, map.valueStrength);
assertSame(keyStrength.defaultEquivalence(), map.keyEquivalence);
assertSame(valueStrength.defaultEquivalence(), map.valueEquivalence);
}
开发者ID:zugzug90,项目名称:guava-mock,代码行数:8,代码来源:LocalCacheTest.java
示例12: testParse_weakKeys
import com.google.common.cache.LocalCache.Strength; //导入依赖的package包/类
public void testParse_weakKeys() {
CacheBuilderSpec spec = parse("weakKeys");
assertNull(spec.initialCapacity);
assertNull(spec.maximumSize);
assertNull(spec.maximumWeight);
assertNull(spec.concurrencyLevel);
assertEquals(Strength.WEAK, spec.keyStrength);
assertNull(spec.valueStrength);
assertNull(spec.writeExpirationTimeUnit);
assertNull(spec.accessExpirationTimeUnit);
assertCacheBuilderEquivalence(
CacheBuilder.newBuilder().weakKeys(), CacheBuilder.from(spec));
}
开发者ID:zugzug90,项目名称:guava-mock,代码行数:14,代码来源:CacheBuilderSpecTest.java
示例13: testParse_softValues
import com.google.common.cache.LocalCache.Strength; //导入依赖的package包/类
public void testParse_softValues() {
CacheBuilderSpec spec = parse("softValues");
assertNull(spec.initialCapacity);
assertNull(spec.maximumSize);
assertNull(spec.maximumWeight);
assertNull(spec.concurrencyLevel);
assertNull(spec.keyStrength);
assertEquals(Strength.SOFT, spec.valueStrength);
assertNull(spec.writeExpirationTimeUnit);
assertNull(spec.accessExpirationTimeUnit);
assertCacheBuilderEquivalence(
CacheBuilder.newBuilder().softValues(), CacheBuilder.from(spec));
}
开发者ID:zugzug90,项目名称:guava-mock,代码行数:14,代码来源:CacheBuilderSpecTest.java
示例14: testParse_weakValues
import com.google.common.cache.LocalCache.Strength; //导入依赖的package包/类
public void testParse_weakValues() {
CacheBuilderSpec spec = parse("weakValues");
assertNull(spec.initialCapacity);
assertNull(spec.maximumSize);
assertNull(spec.maximumWeight);
assertNull(spec.concurrencyLevel);
assertNull(spec.keyStrength);
assertEquals(Strength.WEAK, spec.valueStrength);
assertNull(spec.writeExpirationTimeUnit);
assertNull(spec.accessExpirationTimeUnit);
assertCacheBuilderEquivalence(
CacheBuilder.newBuilder().weakValues(), CacheBuilder.from(spec));
}
开发者ID:zugzug90,项目名称:guava-mock,代码行数:14,代码来源:CacheBuilderSpecTest.java
示例15: createCacheBuilder
import com.google.common.cache.LocalCache.Strength; //导入依赖的package包/类
private CacheBuilder<Object, Object> createCacheBuilder(
Integer concurrencyLevel, Integer initialCapacity, Integer maximumSize,
DurationSpec expireAfterWrite, DurationSpec expireAfterAccess, DurationSpec refresh,
Strength keyStrength, Strength valueStrength) {
CacheBuilder<Object, Object> builder = CacheBuilder.newBuilder();
if (concurrencyLevel != null) {
builder.concurrencyLevel(concurrencyLevel);
}
if (initialCapacity != null) {
builder.initialCapacity(initialCapacity);
}
if (maximumSize != null) {
builder.maximumSize(maximumSize);
}
if (expireAfterWrite != null) {
builder.expireAfterWrite(expireAfterWrite.duration, expireAfterWrite.unit);
}
if (expireAfterAccess != null) {
builder.expireAfterAccess(expireAfterAccess.duration, expireAfterAccess.unit);
}
if (refresh != null) {
builder.refreshAfterWrite(refresh.duration, refresh.unit);
}
if (keyStrength != null) {
builder.setKeyStrength(keyStrength);
}
if (valueStrength != null) {
builder.setValueStrength(valueStrength);
}
return builder;
}
开发者ID:zugzug90,项目名称:guava-mock,代码行数:33,代码来源:CacheBuilderFactory.java
示例16: testDefaults
import com.google.common.cache.LocalCache.Strength; //导入依赖的package包/类
public void testDefaults() {
LocalCache<Object, Object> map = makeLocalCache(createCacheBuilder());
assertSame(Strength.STRONG, map.keyStrength);
assertSame(Strength.STRONG, map.valueStrength);
assertSame(map.keyStrength.defaultEquivalence(), map.keyEquivalence);
assertSame(map.valueStrength.defaultEquivalence(), map.valueEquivalence);
assertEquals(0, map.expireAfterAccessNanos);
assertEquals(0, map.expireAfterWriteNanos);
assertEquals(0, map.refreshNanos);
assertEquals(CacheBuilder.UNSET_INT, map.maxWeight);
assertSame(EntryFactory.STRONG, map.entryFactory);
assertSame(CacheBuilder.NullListener.INSTANCE, map.removalListener);
assertSame(DISCARDING_QUEUE, map.removalNotificationQueue);
assertSame(NULL_TICKER, map.ticker);
assertEquals(4, map.concurrencyLevel);
// concurrency level
assertEquals(4, map.segments.length);
// initial capacity / concurrency level
assertEquals(16 / map.segments.length, map.segments[0].table.length());
assertFalse(map.evictsBySize());
assertFalse(map.expires());
assertFalse(map.expiresAfterWrite());
assertFalse(map.expiresAfterAccess());
assertFalse(map.refreshes());
}
开发者ID:sander120786,项目名称:guava-libraries,代码行数:32,代码来源:LocalCacheTest.java
注:本文中的com.google.common.cache.LocalCache.Strength类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论