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

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

Introduction

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

Prototype

public static <K, V> BiMap<K, V> unmodifiableBiMap(BiMap<? extends K, ? extends V> bimap) 

Source Link

Document

Returns an unmodifiable view of the specified bimap.

Usage

From source file:org.eclipse.b3.enums.TriStateEnumHelper.java

private static BiMap<TriState, String> createEnumMap() {
    BiMap<TriState, String> map = new EnumHashBiMap<TriState, String>(TriState.class);
    map.put(TriState.DEFAULT, DEFAULT_STR);
    map.put(TriState.TRUE, TRUE_STR);/*  w w w .  j av a  2 s. co m*/
    map.put(TriState.FALSE, FALSE_STR);

    return Maps.unmodifiableBiMap(map);
}

From source file:org.eclipse.b3.enums.MergeConflictStrategyEnumHelper.java

private static BiMap<MergeConflictStrategy, String> createEnumMap() {
    BiMap<MergeConflictStrategy, String> map = new EnumHashBiMap<MergeConflictStrategy, String>(
            MergeConflictStrategy.class);
    map.put(MergeConflictStrategy.DEFAULT, BRANCH_POINT_DEFAULT_STR);
    map.put(MergeConflictStrategy.FAIL, FAIL_STR);
    map.put(MergeConflictStrategy.USE_WORKSPACE, USE_WORKSPACE_STR);
    map.put(MergeConflictStrategy.USE_SCM, USE_SCM_STR);

    return Maps.unmodifiableBiMap(map);
}

From source file:com.addthis.codec.jackson.CodecTypeIdResolver.java

public CodecTypeIdResolver(PluginMap pluginMap, JavaType baseType, TypeFactory typeFactory,
        Collection<NamedType> subtypes, PluginRegistry pluginRegistry) {
    super(baseType, typeFactory);
    this.pluginRegistry = pluginRegistry;
    if (!subtypes.isEmpty()) {
        BiMap<String, Class<?>> mutableExtraSubTypes = HashBiMap.create(subtypes.size());
        for (NamedType namedType : subtypes) {
            if (namedType.hasName()) {
                mutableExtraSubTypes.put(namedType.getName(), namedType.getType());
            }/*from  w w  w .j ava2s. c o  m*/
        }
        this.extraSubTypes = Maps.unmodifiableBiMap(mutableExtraSubTypes);
    } else {
        this.extraSubTypes = ImmutableBiMap.of();
    }
    this.pluginMap = pluginMap;
}

From source file:org.biokoframework.systema.injection.SystemAMainModule.java

@Override
protected void configureMain() {
    bindProperty("systemName").to("system-a");
    bindProperty("systemVersion").to("1.0");

    bindProperty("Commands").to(SystemACommands.class);
    bind(IHandlerLocator.class).to(AnnotationHandlerLocator.class);

    BiMap<String, String> headerToFieldMap = HashBiMap.create();
    headerToFieldMap.put("Engaged-Auth-Token", "authToken");
    headerToFieldMap.put("Engaged-Auth-Token-Expire", "authTokenExpire");
    headerToFieldMap = Maps.unmodifiableBiMap(headerToFieldMap);
    bind(new TypeLiteral<Map<String, String>>() {
    }).annotatedWith(Names.named("httpHeaderToFieldsMap")).toInstance(headerToFieldMap);
    bind(new TypeLiteral<Map<String, String>>() {
    }).annotatedWith(Names.named("fieldsHttpHeaderToMap")).toInstance(headerToFieldMap.inverse());
}

From source file:com.addthis.codec.plugins.PluginRegistry.java

public PluginRegistry(@Nonnull Config config) {
    this.config = config;
    Config defaultPluginMapSettings = config.getConfig(PLUGIN_DEFAULTS_PATH);
    String pluginPath = config.getString(PLUGINS_PATH_PATH);
    Config pluginConfigs = config.getConfig(pluginPath);

    Set<String> categories = pluginConfigs.root().keySet();
    Map<String, PluginMap> mapsFromConfig = new HashMap<>(categories.size());
    BiMap<Class<?>, PluginMap> mapsFromConfigByClass = HashBiMap.create(categories.size());
    // Throwaway ObjectMapper to facilitate AnnotatedClass construction below
    ObjectMapper temp = new ObjectMapper();
    for (String category : categories) {
        Config pluginConfig = pluginConfigs.getConfig(category).withFallback(defaultPluginMapSettings);
        PluginMap pluginMap = new PluginMap(category, pluginConfig);
        mapsFromConfig.put(category, pluginMap);
        Class<?> baseClass = pluginMap.baseClass();
        if (baseClass != null) {
            // if two categories define _class, then ensure the annotated one (if any) is the canonical one
            if (mapsFromConfigByClass.containsKey(baseClass)) {
                AnnotatedClass annotatedClass = AnnotatedClass.construct(temp.constructType(baseClass),
                        temp.getDeserializationConfig());
                String existingCategory = mapsFromConfigByClass.get(baseClass).category();
                if (!annotatedClass.hasAnnotation(Pluggable.class)
                        || !annotatedClass.getAnnotation(Pluggable.class).value().equals(existingCategory)) {
                    mapsFromConfigByClass.put(pluginMap.baseClass(), pluginMap);
                }//from   w  ww.  j a va2s  . c  o m
            } else {
                mapsFromConfigByClass.put(pluginMap.baseClass(), pluginMap);
            }
        }
    }
    pluginMapsByCategory = Collections.unmodifiableMap(mapsFromConfig);
    pluginMapsByClass = Maps.unmodifiableBiMap(mapsFromConfigByClass);
}

From source file:com.addthis.codec.plugins.PluginMap.java

public PluginMap(@Nonnull String category, @Nonnull Config config) {
    this.config = config;
    this.category = checkNotNull(category);
    classField = config.getString("_field");
    boolean errorMissing = config.getBoolean("_strict");
    if (config.hasPath("_class")) {
        String baseClassName = config.getString("_class");
        try {/*from  w w w  .j  a  v a 2s.c  o m*/
            baseClass = Class.forName(baseClassName);
        } catch (ClassNotFoundException e) {
            log.error("could not find specified base class {} for category {}", baseClassName, category);
            throw new RuntimeException(e);
        }
    } else {
        baseClass = null;
    }
    Set<String> labels = config.root().keySet();
    BiMap<String, Class<?>> mutableMap = HashBiMap.create(labels.size());
    Map<String, String> mutableAliasMap = new HashMap<>();
    Set<String> mutableInlinedAliasSet = new HashSet<>();
    for (String label : labels) {
        if (!((label.charAt(0) != '_') || "_array".equals(label) || "_default".equals(label))) {
            continue;
        }
        ConfigValue configValue = config.root().get(label);
        String className;
        if (configValue.valueType() == ConfigValueType.STRING) {
            className = (String) configValue.unwrapped();
        } else if (configValue.valueType() == ConfigValueType.OBJECT) {
            ConfigObject configObject = (ConfigObject) configValue;
            className = configObject.toConfig().getString("_class");
            if (configObject.toConfig().hasPath("_inline") && configObject.toConfig().getBoolean("_inline")) {
                mutableInlinedAliasSet.add(label);
            }
        } else if (configValue.valueType() == ConfigValueType.NULL) {
            continue;
        } else {
            throw new ConfigException.WrongType(configValue.origin(), label, "STRING OR OBJECT",
                    configValue.valueType().toString());
        }
        if (labels.contains(className)) {
            // points to another alias
            mutableAliasMap.put(label, className);
        } else {
            try {
                Class<?> foundClass = findAndValidateClass(className);
                mutableMap.put(label, foundClass);
            } catch (ClassNotFoundException maybeSwallowed) {
                if (errorMissing) {
                    throw new RuntimeException(maybeSwallowed);
                } else {
                    log.warn("plugin category {} with alias {} is pointing to missing class {}", category,
                            label, className);
                }
            }
        }
    }
    map = Maps.unmodifiableBiMap(mutableMap);
    aliases = Collections.unmodifiableMap(mutableAliasMap);
    checkAliasesForCycles();
    inlinedAliases = Collections.unmodifiableSet(mutableInlinedAliasSet);
}

From source file:org.opendaylight.yangtools.sal.binding.generator.impl.ModuleContext.java

public BiMap<Type, AugmentationSchema> getTypeToAugmentation() {
    return Maps.unmodifiableBiMap(typeToAugmentation);
}

From source file:org.opendaylight.yangtools.sal.binding.generator.impl.ModuleContext.java

public BiMap<Type, ChoiceCaseNode> getCaseTypeToSchemas() {
    return Maps.unmodifiableBiMap(caseTypeToSchema);
}