本文整理了Java中com.google.common.collect.Maps.synchronizedBiMap()
方法的一些代码示例,展示了Maps.synchronizedBiMap()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Maps.synchronizedBiMap()
方法的具体详情如下:
包路径:com.google.common.collect.Maps
类名称:Maps
方法名:synchronizedBiMap
[英]Returns a synchronized (thread-safe) bimap backed by the specified bimap. In order to guarantee serial access, it is critical that all access to the backing bimap is accomplished through the returned bimap.
It is imperative that the user manually synchronize on the returned map when accessing any of its collection views:
BiMap map = Maps.synchronizedBiMap(}}
Failure to follow this advice may result in non-deterministic behavior.
The returned bimap will be serializable if the specified bimap is serializable.
[中]返回指定bimap支持的同步(线程安全)bimap。为了保证串行访问,关键是通过返回的bimap完成对备份bimap的所有访问。
在访问其任何集合视图时,用户必须在返回的映射上手动同步:
BiMap map = Maps.synchronizedBiMap(}}
不遵循此建议可能会导致不确定性行为。
如果指定的bimap可序列化,则返回的bimap将可序列化。
代码示例来源:origin: google/guava
@Override
protected BiMap<String, String> create(Entry<String, String>[] entries) {
Object mutex = new Object();
BiMap<String, String> result = HashBiMap.create();
for (Entry<String, String> entry : entries) {
checkArgument(!result.containsKey(entry.getKey()));
result.put(entry.getKey(), entry.getValue());
}
return Maps.synchronizedBiMap(result);
}
}
代码示例来源:origin: google/guava
/** See {@link SynchronizedBiMapTest} for more tests. */
public void testSynchronizedBiMap() {
BiMap<String, Integer> bimap = HashBiMap.create();
bimap.put("one", 1);
BiMap<String, Integer> sync = Maps.synchronizedBiMap(bimap);
bimap.put("two", 2);
sync.put("three", 3);
assertEquals(ImmutableSet.of(1, 2, 3), bimap.inverse().keySet());
assertEquals(ImmutableSet.of(1, 2, 3), sync.inverse().keySet());
}
代码示例来源:origin: apache/incubator-gobblin
public GuidDatasetUrnStateStoreNameParser(FileSystem fs, Path jobStatestoreRootDir)
throws IOException {
this.fs = fs;
this.sanitizedNameToDatasetURNMap = Maps.synchronizedBiMap(HashBiMap.<String, String>create());
this.versionIdentifier = new Path(jobStatestoreRootDir, StateStoreNameVersion.V1.getDatasetUrnNameMapFile());
if (this.fs.exists(versionIdentifier)) {
this.version = StateStoreNameVersion.V1;
try (InputStream in = this.fs.open(versionIdentifier)) {
LineReader lineReader = new LineReader(new InputStreamReader(in, Charsets.UTF_8));
String shortenName = lineReader.readLine();
while (shortenName != null) {
String datasetUrn = lineReader.readLine();
this.sanitizedNameToDatasetURNMap.put(shortenName, datasetUrn);
shortenName = lineReader.readLine();
}
}
} else {
this.version = StateStoreNameVersion.V0;
}
}
代码示例来源:origin: 52North/SOS
/**
* Creates a new synchronized map from the specified map.
*
* @param <K> the key type
* @param <V> the value type
* @param map the map
*
* @return the synchronized map
*/
protected static <K, V> BiMap<K, V> newSynchronizedBiMap(BiMap<K, V> map) {
if (map == null) {
return Maps.synchronizedBiMap(HashBiMap.<K, V>create());
} else {
return Maps.synchronizedBiMap(map);
}
}
代码示例来源:origin: org.n52.sensorweb.sos/cache
/**
* Creates a new synchronized map from the specified map.
*
* @param <K> the key type
* @param <V> the value type
* @param map the map
*
* @return the synchronized map
*/
protected static <K, V> BiMap<K, V> newSynchronizedBiMap(BiMap<K, V> map) {
if (map == null) {
return Maps.synchronizedBiMap(HashBiMap.<K, V>create());
} else {
return Maps.synchronizedBiMap(map);
}
}
代码示例来源:origin: com.n3twork.druid/druid-processing
public DimDim()
{
BiMap<String, Integer> biMap = Maps.synchronizedBiMap(HashBiMap.<String, Integer>create());
falseIds = biMap;
falseIdsReverse = biMap.inverse();
}
代码示例来源:origin: org.geoserver/gwc
DefaultTileLayerCatalog(GeoServerResourceLoader resourceLoader, XStream configuredXstream)
throws IOException {
this.resourceLoader = resourceLoader;
this.serializer = configuredXstream;
this.baseDirectory = LAYERINFO_DIRECTORY;
BiMap<String, String> baseBiMap = HashBiMap.create();
this.layersById = Maps.synchronizedBiMap(baseBiMap);
this.layersByName = layersById.inverse();
this.initialized = false;
}
代码示例来源:origin: com.hortonworks.registries/schema-registry-common
public SchemaBranchCache(Integer size, Long expiryInSecs, final SchemaBranchFetcher schemaBranchFetcher) {
schemaBranchNameToIdMap = Maps.synchronizedBiMap(HashBiMap.create());
loadingCache = CacheBuilder.newBuilder()
.maximumSize(size)
.expireAfterAccess(expiryInSecs, TimeUnit.SECONDS)
.build(new CacheLoader<Key, SchemaBranch>() {
@Override
public SchemaBranch load(Key key) throws Exception {
SchemaBranch schemaBranch;
Key otherKey;
if (key.getSchemaBranchKey() != null) {
schemaBranch = schemaBranchFetcher.getSchemaBranch(key.getSchemaBranchKey());
otherKey = Key.of(schemaBranch.getId());
schemaBranchNameToIdMap.put(key.getSchemaBranchKey(), schemaBranch.getId());
} else if (key.getId() != null) {
schemaBranch = schemaBranchFetcher.getSchemaBranch(key.getId());
otherKey = Key.of(new SchemaBranchKey(schemaBranch.getName(), schemaBranch.getSchemaMetadataName()));
schemaBranchNameToIdMap.put(otherKey.schemaBranchKey, schemaBranch.getId());
} else {
throw new IllegalArgumentException("Given argument is not valid: " + key);
}
loadingCache.put(otherKey, schemaBranch);
return schemaBranch;
}
});
}
代码示例来源:origin: net.sf.jabb/jabb-core
/**
* Initialize internal data structure for adding state and transitions later.
*/
public void startDefinition(){
sequencer = new Sequencer();
states = Maps.synchronizedBiMap(HashBiMap.<S, Integer>create());
transitions = new ConcurrentHashMap<DoubleValueBean<S, T>, Transition<S>>();
validTransitions = new PutIfAbsentMap<S, Set<T>>(new HashMap<S, Set<T>>(), new MapValueFactory<S, Set<T>>(){
@Override
public Set<T> createValue(S key) {
return Collections.newSetFromMap(new ConcurrentHashMap<T, Boolean>());
}
});
}
代码示例来源:origin: rosjava/rosjava_core
/**
* @param nodeFactory
* {@link NodeFactory} to use for node creation.
* @param scheduledExecutorService
* {@link NodeMain}s will be executed using this
*/
private DefaultNodeMainExecutor(NodeFactory nodeFactory,
ScheduledExecutorService scheduledExecutorService) {
this.nodeFactory = nodeFactory;
this.scheduledExecutorService = scheduledExecutorService;
connectedNodes =
Multimaps.synchronizedMultimap(HashMultimap.<GraphName, ConnectedNode>create());
nodeMains = Maps.synchronizedBiMap(HashBiMap.<Node, NodeMain>create());
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
@Override
public void run() {
DefaultNodeMainExecutor.this.shutdown();
}
}));
}
代码示例来源:origin: hortonworks/registry
public SchemaBranchCache(Integer size, Long expiryInSecs, final SchemaBranchFetcher schemaBranchFetcher) {
schemaBranchNameToIdMap = Maps.synchronizedBiMap(HashBiMap.create());
loadingCache = CacheBuilder.newBuilder()
.maximumSize(size)
.expireAfterAccess(expiryInSecs, TimeUnit.SECONDS)
.build(new CacheLoader<Key, SchemaBranch>() {
@Override
public SchemaBranch load(Key key) throws Exception {
SchemaBranch schemaBranch;
Key otherKey;
if (key.getSchemaBranchKey() != null) {
schemaBranch = schemaBranchFetcher.getSchemaBranch(key.getSchemaBranchKey());
otherKey = Key.of(schemaBranch.getId());
schemaBranchNameToIdMap.put(key.getSchemaBranchKey(), schemaBranch.getId());
} else if (key.getId() != null) {
schemaBranch = schemaBranchFetcher.getSchemaBranch(key.getId());
otherKey = Key.of(new SchemaBranchKey(schemaBranch.getName(), schemaBranch.getSchemaMetadataName()));
schemaBranchNameToIdMap.put(otherKey.schemaBranchKey, schemaBranch.getId());
} else {
throw new IllegalArgumentException("Given argument is not valid: " + key);
}
loadingCache.put(otherKey, schemaBranch);
return schemaBranch;
}
});
}
代码示例来源:origin: de.unijena.bioinf.phylo/flipcut-core
scaffoldCharacterMapping = Maps.synchronizedBiMap(HashBiMap.create());
for (Map.Entry<N, TreeNode> entry : source.scaffoldCharacterMapping.entrySet()) {
N sourceNode;
代码示例来源:origin: com.linkedin.gobblin/gobblin-metastore
public GuidDatasetUrnStateStoreNameParser(FileSystem fs, Path jobStatestoreRootDir)
throws IOException {
this.fs = fs;
this.sanitizedNameToDatasetURNMap = Maps.synchronizedBiMap(HashBiMap.<String, String>create());
this.versionIdentifier = new Path(jobStatestoreRootDir, StateStoreNameVersion.V1.getDatasetUrnNameMapFile());
if (this.fs.exists(versionIdentifier)) {
this.version = StateStoreNameVersion.V1;
try (InputStream in = this.fs.open(versionIdentifier)) {
LineReader lineReader = new LineReader(new InputStreamReader(in, Charsets.UTF_8));
String shortenName = lineReader.readLine();
while (shortenName != null) {
String datasetUrn = lineReader.readLine();
this.sanitizedNameToDatasetURNMap.put(shortenName, datasetUrn);
shortenName = lineReader.readLine();
}
}
} else {
this.version = StateStoreNameVersion.V0;
}
}
代码示例来源:origin: org.apache.gobblin/gobblin-metastore
public GuidDatasetUrnStateStoreNameParser(FileSystem fs, Path jobStatestoreRootDir)
throws IOException {
this.fs = fs;
this.sanitizedNameToDatasetURNMap = Maps.synchronizedBiMap(HashBiMap.<String, String>create());
this.versionIdentifier = new Path(jobStatestoreRootDir, StateStoreNameVersion.V1.getDatasetUrnNameMapFile());
if (this.fs.exists(versionIdentifier)) {
this.version = StateStoreNameVersion.V1;
try (InputStream in = this.fs.open(versionIdentifier)) {
LineReader lineReader = new LineReader(new InputStreamReader(in, Charsets.UTF_8));
String shortenName = lineReader.readLine();
while (shortenName != null) {
String datasetUrn = lineReader.readLine();
this.sanitizedNameToDatasetURNMap.put(shortenName, datasetUrn);
shortenName = lineReader.readLine();
}
}
} else {
this.version = StateStoreNameVersion.V0;
}
}
代码示例来源:origin: com.google.guava/guava-tests
@Override
protected BiMap<String, String> create(Entry<String, String>[] entries) {
Object mutex = new Object();
BiMap<String, String> result = HashBiMap.create();
for (Entry<String, String> entry : entries) {
checkArgument(!result.containsKey(entry.getKey()));
result.put(entry.getKey(), entry.getValue());
}
return Maps.synchronizedBiMap(result);
}
}
代码示例来源:origin: yahoo/elide
/**
* Instantiate a new EntityDictionary with the provided set of checks. In addition all of the checks
* in {@link com.yahoo.elide.security.checks.prefab} are mapped to {@code Prefab.CONTAINER.CHECK}
* (e.g. {@code @ReadPermission(expression="Prefab.Role.All")}
* or {@code @ReadPermission(expression="Prefab.Common.UpdateOnCreate")})
* @param checks a map that links the identifiers used in the permission expression strings
* to their implementing classes
*/
public EntityDictionary(Map<String, Class<? extends Check>> checks) {
checkNames = Maps.synchronizedBiMap(HashBiMap.create(checks));
addPrefabCheck("Prefab.Role.All", Role.ALL.class);
addPrefabCheck("Prefab.Role.None", Role.NONE.class);
addPrefabCheck("Prefab.Collections.AppendOnly", AppendOnly.class);
addPrefabCheck("Prefab.Collections.RemoveOnly", RemoveOnly.class);
addPrefabCheck("Prefab.Common.UpdateOnCreate", Common.UpdateOnCreate.class);
}
代码示例来源:origin: com.google.guava/guava-tests
/** See {@link SynchronizedBiMapTest} for more tests. */
public void testSynchronizedBiMap() {
BiMap<String, Integer> bimap = HashBiMap.create();
bimap.put("one", 1);
BiMap<String, Integer> sync = Maps.synchronizedBiMap(bimap);
bimap.put("two", 2);
sync.put("three", 3);
assertEquals(ImmutableSet.of(1, 2, 3), bimap.inverse().keySet());
assertEquals(ImmutableSet.of(1, 2, 3), sync.inverse().keySet());
}
代码示例来源:origin: com.yahoo.elide/elide-core
/**
* Instantiate a new EntityDictionary with the provided set of checks. In addition all of the checks
* in {@link com.yahoo.elide.security.checks.prefab} are mapped to {@code Prefab.CONTAINER.CHECK}
* (e.g. {@code @ReadPermission(expression="Prefab.Role.All")}
* or {@code @ReadPermission(expression="Prefab.Common.UpdateOnCreate")})
* @param checks a map that links the identifiers used in the permission expression strings
* to their implementing classes
*/
public EntityDictionary(Map<String, Class<? extends Check>> checks) {
checkNames = Maps.synchronizedBiMap(HashBiMap.create(checks));
addPrefabCheck("Prefab.Role.All", Role.ALL.class);
addPrefabCheck("Prefab.Role.None", Role.NONE.class);
addPrefabCheck("Prefab.Collections.AppendOnly", AppendOnly.class);
addPrefabCheck("Prefab.Collections.RemoveOnly", RemoveOnly.class);
addPrefabCheck("Prefab.Common.UpdateOnCreate", Common.UpdateOnCreate.class);
}
代码示例来源:origin: rinde/RinSim
CommModel(RandomGenerator rng, Builder b) {
defaultReliability = b.defaultReliability();
defaultMaxRange = b.defaultMaxRange();
usersHasChanged = false;
usersDevices = Maps.synchronizedBiMap(
LinkedHashBiMap.<CommUser, CommDevice>create());
unregisteredUsersDevices = LinkedHashBiMap.<CommUser, CommDevice>create();
usersDevicesSnapshot = ImmutableBiMap.of();
eventDispatcher = new EventDispatcher(EventTypes.values());
randomGenerator = rng;
}
内容来源于网络,如有侵权,请联系作者删除!