Example usage for com.google.common.collect Maps synchronizedBiMap

List of usage examples for com.google.common.collect Maps synchronizedBiMap

Introduction

In this page you can find the example usage for com.google.common.collect Maps synchronizedBiMap.

Prototype

public static <K, V> BiMap<K, V> synchronizedBiMap(BiMap<K, V> bimap) 

Source Link

Document

Returns a synchronized (thread-safe) bimap backed by the specified bimap.

Usage

From source file:com.yahoo.elide.core.EntityDictionary.java

/**
 * 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
 *//* w w  w .j  a v a  2s .c  o m*/
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);
}

From source file:com.github.rinde.rinsim.core.model.comm.CommModel.java

CommModel(RandomGenerator rng, Builder b) {
    defaultReliability = b.defaultReliability();
    defaultMaxRange = b.defaultMaxRange();
    usersHasChanged = false;//from ww  w  .j  a  v a2s .  c  o m
    usersDevices = Maps.synchronizedBiMap(LinkedHashBiMap.<CommUser, CommDevice>create());
    unregisteredUsersDevices = LinkedHashBiMap.<CommUser, CommDevice>create();
    usersDevicesSnapshot = ImmutableBiMap.of();
    eventDispatcher = new EventDispatcher(EventTypes.values());
    randomGenerator = rng;
}

From source file:org.n52.sos.cache.AbstractContentCache.java

/**
 * Creates a new synchronized map from the specified map.
 *
 * @param <K>/*www  . j  a v a 2 s.c  o  m*/
 *            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);
    }
}

From source file:org.pshow.ecm.content.metadata.DefaultContetntSchemaHolder.java

private <K, V> void putStoreSafe(String key, Map<K, V> value) {
    if (store.contains(key)) {
        Map<K, V> old_all = this.getRegisteredObject(key, Maps.synchronizedBiMap(HashBiMap.<K, V>create()));
        Map<K, V> new_all = Maps.synchronizedBiMap(HashBiMap.<K, V>create(value.size() + old_all.size()));
        new_all.putAll(value);
        new_all.putAll(old_all);
        store.put(key, new_all);
    } else {/*from  w w  w  .ja  va2 s.  c om*/
        store.put(key, value);
    }
}

From source file:org.pshow.ecm.content.metadata.DefaultContetntSchemaHolder.java

private void registNamespaces(List<NamespaceDef> list) {
    // namespace//w  w w .j av  a2 s  .  c  o  m
    List<NamespaceDef> exist_namespaces = loadNamespacesFromDB();
    if (list != null) {
        for (NamespaceDef psNamespace : list) {
            if (!exist_namespaces.contains(psNamespace)) {
                // ?namespace???namespace
                namespaceDao.save(new Namespace(psNamespace.getUri(), psNamespace.getPrefix()));
                exist_namespaces.add(psNamespace);
            }
        }
    }
    BiMap<String, String> namespaces = Maps.synchronizedBiMap(HashBiMap.<String, String>create());
    for (NamespaceDef psNamespace : exist_namespaces) {
        checkNamespace(namespaces, psNamespace);
        namespaces.put(psNamespace.getUri(), psNamespace.getPrefix());
    }
    putStoreSafe(ALL_NAMESPACE, namespaces);
}

From source file:org.geoserver.backuprestore.tasklet.CatalogBackupRestoreTasklet.java

/**
 * TODO: When Restoring//from   ww w  .j  a va  2 s .  c  o m
 * 
 * 1. the securityManager should issue the listeners 2. the GWCInitializer should be re-initialized
 * 
 * @param sourceRestoreFolder
 * @param baseDir
 * @throws Exception
 * @throws IOException
 */
private void restoreGWCSettings(Resource sourceRestoreFolder, Resource baseDir) throws Exception {
    // Restore configuration files form source and Test that everything went well
    try {

        // - Prepare folder
        GeoserverXMLResourceProvider gwcConfigProvider = (GeoserverXMLResourceProvider) GeoServerExtensions
                .bean("gwcXmlConfigResourceProvider");
        Resource targetGWCProviderRestoreDir = gwcConfigProvider.getConfigDirectory();
        Files.delete(targetGWCProviderRestoreDir.dir());

        // Restore GWC Providers Configurations
        for (GeoserverXMLResourceProvider gwcProvider : GeoServerExtensions
                .extensions(GeoserverXMLResourceProvider.class)) {
            Resource providerConfigFile = sourceRestoreFolder
                    .get(Paths.path(GeoserverXMLResourceProvider.DEFAULT_CONFIGURATION_DIR_NAME,
                            gwcProvider.getConfigFileName()));
            if (Resources.exists(providerConfigFile) && FileUtils.sizeOf(providerConfigFile.file()) > 0) {
                Resources.copy(providerConfigFile.in(), targetGWCProviderRestoreDir, providerConfigFile.name());
            }
        }

        // Restore GWC Layers Configurations
        // TODO: This should be done using the spring-batch item reader/writer, since it is not safe to save tons of single XML files.
        //       Nonetheless, given the default implementation of GWC Catalog does not have much sense to refactor this code now.
        final TileLayerCatalog gwcCatalog = (TileLayerCatalog) GeoServerExtensions
                .bean("GeoSeverTileLayerCatalog");
        BiMap<String, String> layersByName = null;

        if (gwcCatalog != null) {

            if (isDryRun()) {
                BiMap<String, String> baseBiMap = HashBiMap.create();
                layersByName = Maps.synchronizedBiMap(baseBiMap);
            }

            final XMLConfiguration gwcXmlPersisterFactory = (XMLConfiguration) GeoServerExtensions
                    .bean("gwcXmlConfig");
            final GeoServerResourceLoader resourceLoader = new GeoServerResourceLoader(
                    sourceRestoreFolder.dir());

            final DefaultTileLayerCatalog gwcRestoreCatalog = new DefaultTileLayerCatalog(resourceLoader,
                    gwcXmlPersisterFactory);

            for (String layerName : gwcRestoreCatalog.getLayerNames()) {
                GeoServerTileLayerInfo gwcLayerInfo = gwcRestoreCatalog.getLayerByName(layerName);

                LayerInfo layerInfo = getCatalog().getLayerByName(layerName);

                if (layerInfo != null) {

                    WorkspaceInfo ws = layerInfo.getResource() != null
                            && layerInfo.getResource().getStore() != null
                            && layerInfo.getResource().getStore().getWorkspace() != null
                                    ? getCatalog().getWorkspaceByName(
                                            layerInfo.getResource().getStore().getWorkspace().getName())
                                    : null;

                    if (!filteredResource(layerInfo, ws, true)) {
                        restoreGWCTileLayerInfo(gwcCatalog, layersByName, layerName, gwcLayerInfo,
                                layerInfo.getId());
                    }
                } else {
                    LayerGroupInfo layerGroupInfo = getCatalog().getLayerGroupByName(layerName);

                    if (layerGroupInfo != null) {

                        WorkspaceInfo ws = layerGroupInfo.getWorkspace() != null
                                ? getCatalog().getWorkspaceByName(layerGroupInfo.getWorkspace().getName())
                                : null;

                        if (!filteredResource(layerGroupInfo, ws, false)) {
                            restoreGWCTileLayerInfo(gwcCatalog, layersByName, layerName, gwcLayerInfo,
                                    layerGroupInfo.getId());
                        }
                    }
                }
            }
        }

    } catch (Exception e) {
        logValidationExceptions(null, e);
    }
}