@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); } }
/** 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()); }
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; } }
/** * 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); } }
/** * 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); } }
public DimDim() { BiMap<String, Integer> biMap = Maps.synchronizedBiMap(HashBiMap.<String, Integer>create()); falseIds = biMap; falseIdsReverse = biMap.inverse(); }
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; }
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; } }); }
/** * 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>()); } }); }
/** * @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(); } })); }
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; } }); }
scaffoldCharacterMapping = Maps.synchronizedBiMap(HashBiMap.create()); for (Map.Entry<N, TreeNode> entry : source.scaffoldCharacterMapping.entrySet()) { N sourceNode;
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; } }
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; } }
@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); } }
/** * 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); }
/** 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()); }
/** * 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); }
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; }