Java example source code file (CacheReferencesTest.java)
This example Java source code file (CacheReferencesTest.java) is included in the alvinalexander.com
"Java Source Code
Warehouse" project. The intent of this project is to help you "Learn
Java by Example" TM.
The CacheReferencesTest.java Java example source code
/*
* Copyright (C) 2011 The Guava Authors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package com.google.common.cache;
import static com.google.common.cache.LocalCache.Strength.STRONG;
import static com.google.common.collect.Maps.immutableEntry;
import static com.google.common.truth.Truth.assertThat;
import com.google.common.base.Function;
import com.google.common.cache.LocalCache.Strength;
import com.google.common.cache.TestingRemovalListeners.CountingRemovalListener;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import junit.framework.TestCase;
import java.lang.ref.WeakReference;
/**
* Tests of basic {@link LoadingCache} operations with all possible combinations of key & value
* strengths.
*
* @author mike nonemacher
*/
public class CacheReferencesTest extends TestCase {
private static final CacheLoader<Key,String> KEY_TO_STRING_LOADER =
new CacheLoader<Key, String>() {
@Override public String load(Key key) {
return key.toString();
}
};
private CacheBuilderFactory factoryWithAllKeyStrengths() {
return new CacheBuilderFactory()
.withKeyStrengths(ImmutableSet.of(STRONG, Strength.WEAK))
.withValueStrengths(ImmutableSet.of(STRONG, Strength.WEAK, Strength.SOFT));
}
private Iterable<LoadingCache caches() {
CacheBuilderFactory factory = factoryWithAllKeyStrengths();
return Iterables.transform(factory.buildAllPermutations(),
new Function<CacheBuilder
Other Java examples (source code examples)
Here is a short list of links related to this Java CacheReferencesTest.java source code file: