Example usage for com.google.common.collect ImmutableSortedMap copyOf

List of usage examples for com.google.common.collect ImmutableSortedMap copyOf

Introduction

In this page you can find the example usage for com.google.common.collect ImmutableSortedMap copyOf.

Prototype

public static <K, V> ImmutableSortedMap<K, V> copyOf(
            Iterable<? extends Entry<? extends K, ? extends V>> entries) 

Source Link

Usage

From source file:com.mastfrog.acteur.server.EventImpl.java

@Override
public synchronized Map<String, String> getParametersAsMap() {
    if (paramsMap == null) {
        QueryStringDecoder queryStringDecoder = new QueryStringDecoder(req.getUri());
        Map<String, List<String>> params = queryStringDecoder.parameters();
        Map<String, String> result = new HashMap<>();
        for (Map.Entry<String, List<String>> e : params.entrySet()) {
            if (e.getValue().isEmpty()) {
                continue;
            }//from w w  w .  j a v  a 2  s  .  c om
            result.put(e.getKey(), e.getValue().get(0));
        }
        paramsMap = ImmutableSortedMap.copyOf(result);
    }
    return paramsMap;
}

From source file:co.cask.cdap.internal.app.runtime.adapter.PluginRepository.java

/**
 * Returns a {@link Map.Entry} represents the plugin information for the plugin being requested.
 *
 * @param template name of the template//from w  ww . j a v  a 2  s  . c o m
 * @param pluginType plugin type name
 * @param pluginName plugin name
 * @param selector for selecting which plugin to use
 * @return the entry found or {@code null} if none was found
 */
@Nullable
public Map.Entry<PluginInfo, PluginClass> findPlugin(String template, final String pluginType,
        final String pluginName, PluginSelector selector) {
    // Transform by matching type, name. If there is no match, the map value is null.
    // We then filter out null value
    SortedMap<PluginInfo, PluginClass> plugins = ImmutableSortedMap.copyOf(Maps.filterValues(
            Maps.transformValues(getPlugins(template), new Function<Collection<PluginClass>, PluginClass>() {
                @Nullable
                @Override
                public PluginClass apply(Collection<PluginClass> input) {
                    for (PluginClass pluginClass : input) {
                        if (pluginClass.getType().equals(pluginType)
                                && pluginClass.getName().equals(pluginName)) {
                            return pluginClass;
                        }
                    }
                    return null;
                }
            }), Predicates.notNull()));

    return plugins.isEmpty() ? null : selector.select(plugins);
}

From source file:io.airlift.bootstrap.Bootstrap.java

public Injector initialize() throws Exception {
    Preconditions.checkState(!initialized, "Already initialized");
    initialized = true;/*from   www .  ja  v  a 2 s .c  om*/

    Logging logging = null;
    if (initializeLogging) {
        logging = Logging.initialize();
    }

    Thread.currentThread().setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
        @Override
        public void uncaughtException(Thread t, Throwable e) {
            log.error(e, "Uncaught exception in thread %s", t.getName());
        }
    });

    Map<String, String> requiredProperties;
    ConfigurationFactory configurationFactory;
    if (requiredConfigurationProperties == null) {
        // initialize configuration
        log.info("Loading configuration");
        ConfigurationLoader loader = new ConfigurationLoader();

        requiredProperties = Collections.emptyMap();
        String configFile = System.getProperty("config");
        if (configFile != null) {
            requiredProperties = loader.loadPropertiesFrom(configFile);
        }
    } else {
        requiredProperties = requiredConfigurationProperties;
    }
    SortedMap<String, String> properties = Maps.newTreeMap();
    if (optionalConfigurationProperties != null) {
        properties.putAll(optionalConfigurationProperties);
    }
    properties.putAll(requiredProperties);
    properties.putAll(fromProperties(System.getProperties()));
    properties = ImmutableSortedMap.copyOf(properties);

    configurationFactory = new ConfigurationFactory(properties);

    if (logging != null) {
        // initialize logging
        log.info("Initializing logging");
        LoggingConfiguration configuration = configurationFactory.build(LoggingConfiguration.class);
        logging.configure(configuration);
    }

    // create warning logger now that we have logging initialized
    final WarningsMonitor warningsMonitor = new WarningsMonitor() {
        @Override
        public void onWarning(String message) {
            log.warn(message);
        }
    };

    // initialize configuration factory
    for (Module module : modules) {
        if (module instanceof ConfigurationAwareModule) {
            ConfigurationAwareModule configurationAwareModule = (ConfigurationAwareModule) module;
            configurationAwareModule.setConfigurationFactory(configurationFactory);
        }
    }

    // Validate configuration
    ConfigurationValidator configurationValidator = new ConfigurationValidator(configurationFactory,
            warningsMonitor);
    List<Message> messages = configurationValidator.validate(modules);

    // at this point all config file properties should be used
    // so we can calculate the unused properties
    final TreeMap<String, String> unusedProperties = Maps.newTreeMap();
    unusedProperties.putAll(requiredProperties);
    unusedProperties.keySet().removeAll(configurationFactory.getUsedProperties());

    // Log effective configuration
    if (!quiet) {
        logConfiguration(configurationFactory, unusedProperties);
    }

    // system modules
    Builder<Module> moduleList = ImmutableList.builder();
    moduleList.add(new LifeCycleModule());
    moduleList.add(new ConfigurationModule(configurationFactory));
    if (!messages.isEmpty()) {
        moduleList.add(new ValidationErrorModule(messages));
    }
    moduleList.add(new Module() {
        @Override
        public void configure(Binder binder) {
            binder.bind(WarningsMonitor.class).toInstance(warningsMonitor);
        }
    });

    moduleList.add(new Module() {
        @Override
        public void configure(Binder binder) {
            binder.disableCircularProxies();
            if (requireExplicitBindings) {
                binder.requireExplicitBindings();
            }
        }
    });

    // todo this should be part of the ValidationErrorModule
    if (strictConfig) {
        moduleList.add(new Module() {
            @Override
            public void configure(Binder binder) {
                for (Entry<String, String> unusedProperty : unusedProperties.entrySet()) {
                    binder.addError("Configuration property '%s=%s' was not used", unusedProperty.getKey(),
                            unusedProperty.getValue());
                }
            }
        });
    }
    moduleList.addAll(modules);

    // create the injector
    Injector injector = Guice.createInjector(Stage.PRODUCTION, moduleList.build());

    // Create the life-cycle manager
    LifeCycleManager lifeCycleManager = injector.getInstance(LifeCycleManager.class);

    // Start services
    if (lifeCycleManager.size() > 0) {
        lifeCycleManager.start();
    }

    return injector;
}

From source file:com.opengamma.strata.basics.currency.MultiCurrencyAmountArray.java

@ImmutableConstructor
private MultiCurrencyAmountArray(int size, Map<Currency, DoubleArray> values) {
    this.values = ImmutableSortedMap.copyOf(values);
    this.size = size;
}

From source file:com.opengamma.strata.calc.runner.function.result.MultiCurrencyValuesArray.java

@ImmutableConstructor
private MultiCurrencyValuesArray(Map<Currency, DoubleArray> values) {
    this.values = ImmutableSortedMap.copyOf(values);

    if (values.isEmpty()) {
        size = 0;/*w ww. j a va 2 s .  c  om*/
    } else {
        // All currencies must have the same number of values so we can just take the size of the first
        size = values.values().iterator().next().size();
    }
}

From source file:com.facebook.buck.core.build.engine.buildinfo.DefaultOnDiskBuildInfo.java

@Override
public ImmutableSortedMap<String, String> getMetadataForArtifact() throws IOException {
    ImmutableSortedMap<String, String> metadata = ImmutableSortedMap
            .copyOf(buildInfoStore.getAllMetadata(buildTarget));

    Preconditions.checkState(metadata.containsKey(BuildInfo.MetadataKey.ORIGIN_BUILD_ID),
            "Cache artifact for build target %s is missing metadata %s.", buildTarget,
            BuildInfo.MetadataKey.ORIGIN_BUILD_ID);

    return metadata;
}

From source file:com.facebook.buck.util.config.Config.java

private HashCode computeOrderIndependentHashCode() {
    ImmutableMap<String, ImmutableMap<String, String>> rawValues = rawConfig.getValues();
    ImmutableSortedMap.Builder<String, ImmutableSortedMap<String, String>> expanded = ImmutableSortedMap
            .naturalOrder();/*  ww  w .  j  a  v a  2  s .  c o  m*/
    for (String section : rawValues.keySet()) {
        expanded.put(section, ImmutableSortedMap.copyOf(get(section)));
    }

    ImmutableSortedMap<String, ImmutableSortedMap<String, String>> sortedConfigMap = expanded.build();

    Hasher hasher = Hashing.sha256().newHasher();
    for (Entry<String, ImmutableSortedMap<String, String>> entry : sortedConfigMap.entrySet()) {
        hasher.putString(entry.getKey(), StandardCharsets.UTF_8);
        for (Entry<String, String> nestedEntry : entry.getValue().entrySet()) {
            hasher.putString(nestedEntry.getKey(), StandardCharsets.UTF_8);
            hasher.putString(nestedEntry.getValue(), StandardCharsets.UTF_8);
        }
    }

    return hasher.hash();
}

From source file:com.google.template.soy.passes.IndirectParamsCalculator.java

public IndirectParamsInfo calculateIndirectParams(TemplateMetadata template) {

    visitedCallSituations = Sets.newHashSet();
    indirectParams = Maps.newHashMap();// www  . j a  va 2  s . com
    paramKeyToCalleesMultimap = HashMultimap.create();
    indirectParamTypes = LinkedHashMultimap.create();
    mayHaveIndirectParamsInExternalCalls = false;
    mayHaveIndirectParamsInExternalDelCalls = false;
    visit(template, new HashSet<>(), new HashSet<>());

    return new IndirectParamsInfo(ImmutableSortedMap.copyOf(indirectParams),
            ImmutableMultimap.copyOf(paramKeyToCalleesMultimap), ImmutableMultimap.copyOf(indirectParamTypes),
            mayHaveIndirectParamsInExternalCalls, mayHaveIndirectParamsInExternalDelCalls);
}

From source file:com.google.devtools.build.lib.rules.config.ConfigFeatureFlagOptions.java

/**
 * Replaces the set of flag-value pairs with the given mapping of flag-value pairs.
 *
 * <p>Flags not present in the new {@code flagValues} will return to being unset! To set flags
 * while still retaining the values already set, call {@link #getFlagValues()} and build a map
 * containing both the old values and the new ones. Note that when {@link #isTrimmed()} is true,
 * it's not possible to know the values of ALL flags.
 *
 * <p>Because this method replaces the entire set of flag values, all flag values for this
 * configuration are known, and thus knownValues is set to null, and unknownFlags is cleared.
 * After this method is called, isTrimmed will return false.
 *//* w w w. j a  v  a 2s  .c  o m*/
public void replaceFlagValues(Map<Label, String> flagValues) {
    this.flagValues = ImmutableSortedMap.copyOf(flagValues);
    this.knownDefaultFlags = null;
    this.unknownFlags = ImmutableSortedSet.of();
}

From source file:com.linecorp.armeria.internal.metric.PrometheusMetricRequestDecorator.java

private String[] getLabelValues(RequestLog log) {
    return ImmutableSortedMap.copyOf(labelingFunction.apply(log)).values().stream().toArray(String[]::new);
}