Example usage for com.google.common.collect ClassToInstanceMap put

List of usage examples for com.google.common.collect ClassToInstanceMap put

Introduction

In this page you can find the example usage for com.google.common.collect ClassToInstanceMap put.

Prototype

V put(K key, V value);

Source Link

Document

Associates the specified value with the specified key in this map (optional operation).

Usage

From source file:com.google.devtools.build.lib.skyframe.BuildConfigurationFunction.java

@Override
public SkyValue compute(SkyKey skyKey, Environment env)
        throws InterruptedException, BuildConfigurationFunctionException {
    BuildConfigurationValue.Key key = (BuildConfigurationValue.Key) skyKey.argument();
    Set<Fragment> fragments;
    try {/*from  www  .  j  a v a2 s.c  om*/
        fragments = getConfigurationFragments(key, env);
    } catch (InvalidConfigurationException e) {
        throw new BuildConfigurationFunctionException(e);
    }
    if (fragments == null) {
        return null;
    }

    ClassToInstanceMap<Fragment> fragmentsMap = MutableClassToInstanceMap.create();
    for (Fragment fragment : fragments) {
        fragmentsMap.put(fragment.getClass(), fragment);
    }

    BuildConfiguration config = new BuildConfiguration(directories, fragmentsMap, key.getBuildOptions(),
            !key.actionsEnabled());
    // Unlike static configurations, dynamic configurations don't need to embed transition logic
    // within the configuration itself. However we still use this interface to provide a mapping
    // between Transition types (e.g. HOST) and the dynamic transitions that apply those
    // transitions. Once static configurations are cleaned out we won't need this interface
    // any more (all the centralized logic that maintains the transition logic can be distributed
    // to the actual rule code that uses it).
    config.setConfigurationTransitions(collectionFactory.getDynamicTransitionLogic(config));

    return new BuildConfigurationValue(config);
}

From source file:org.opendaylight.controller.sal.binding.test.util.BindingTestContext.java

private void startDomBroker() {
    checkState(executor != null);/*from w  w  w.j  a  va  2  s  .  c  o  m*/

    domRouter = new DOMRpcRouter();
    mockSchemaService.registerSchemaContextListener(domRouter);

    final ClassToInstanceMap<BrokerService> services = MutableClassToInstanceMap.create();
    services.put(DOMRpcService.class, domRouter);

    biBrokerImpl = new BrokerImpl(domRouter, services);

}

From source file:com.google.devtools.build.lib.analysis.config.BuildConfiguration.java

/**
 * Returns a copy of this configuration only including the given fragments (which the current
 * configuration is assumed to have).//from   w w  w  .j a  va 2s . c om
 */
public BuildConfiguration clone(Set<Class<? extends BuildConfiguration.Fragment>> fragmentClasses,
        RuleClassProvider ruleClassProvider) {

    ClassToInstanceMap<Fragment> fragmentsMap = MutableClassToInstanceMap.create();
    for (Fragment fragment : fragments.values()) {
        if (fragmentClasses.contains(fragment.getClass())) {
            fragmentsMap.put(fragment.getClass(), fragment);
        }
    }
    BuildOptions options = buildOptions.trim(getOptionsClasses(fragmentsMap.keySet(), ruleClassProvider));
    BuildConfiguration newConfig = new BuildConfiguration(directories, fragmentsMap, options, !actionsEnabled);
    newConfig.setConfigurationTransitions(this.transitions);
    return newConfig;
}