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

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

Introduction

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

Prototype

@GwtIncompatible("NavigableMap")
public static <K, V1, V2> NavigableMap<K, V2> transformValues(NavigableMap<K, V1> fromMap,
        Function<? super V1, V2> function) 

Source Link

Document

Returns a view of a navigable map where each value is transformed by a function.

Usage

From source file:org.apache.fluo.api.client.AbstractSnapshotBase.java

@Override
public Map<Column, String> gets(CharSequence row, Set<Column> columns) {
    Map<Column, Bytes> values = get(s2bConv(row), columns);
    return Maps.transformValues(values, b -> b.toString());
}

From source file:org.lanternpowered.server.inject.impl.SimpleModule.java

@SuppressWarnings({ "unchecked", "rawtypes" })
public SimpleModule(List<Binding<?>> bindings, Map<Class<?>, Supplier<?>> suppliers,
        List<MethodSpec<?>> methodBindings) {
    Map<Class<?>, List<Binding<?>>> map = Maps.newConcurrentMap();
    for (Binding<?> binding : bindings) {
        map.computeIfAbsent(binding.getParameterSpec().getType(), type -> Lists.newCopyOnWriteArrayList())
                .add(binding);//  www .ja  va  2  s .  co m
    }
    this.methodBindings = ImmutableList.copyOf(methodBindings);
    this.bindings = (Map) ImmutableMap.copyOf(Maps.transformValues(map, ImmutableList::copyOf));
    this.suppliers = ImmutableMap.copyOf(suppliers);
}

From source file:org.apache.brooklyn.util.core.config.ResolvingConfigBag.java

@Override
public Map<String, Object> getUnusedConfig() {
    // Lazily transform copy of map
    return Maps.transformValues(super.getUnusedConfig(), getTransformer());
}

From source file:org.n52.iceland.util.JSONUtils.java

public static ObjectNode toJSON(Map<String, ?> map) {
    ObjectNode node = nodeFactory().objectNode();
    if (map != null) {
        node.setAll(Maps.transformValues(map, TO_JSON_STRING));
    }//w  w  w .  ja  v a 2  s . c  om
    return node;
}

From source file:com.google.gerrit.util.http.testutil.FakeHttpServletRequest.java

@Override
public Map<String, String[]> getParameterMap() {
    return Collections
            .unmodifiableMap(Maps.transformValues(parameters.asMap(), vs -> vs.toArray(new String[0])));
}

From source file:com.isotrol.impe3.pms.core.obj.PortalObject.java

public static Map<String, String> fromNullName(Map<String, String> map) {
    return Maps.transformValues(map, new Function<String, String>() {
        public String apply(String from) {
            return NULL_NAME.equals(from) ? null : from;
        }//from   w w w. j ava 2s . com
    });
}

From source file:grakn.core.daemon.executor.Storage.java

private void initialiseConfig() {
    try {//from   ww w.  j a  va 2 s . co m
        ObjectMapper mapper = new ObjectMapper(new YAMLFactory().enable(YAMLGenerator.Feature.MINIMIZE_QUOTES));
        TypeReference<Map<String, Object>> reference = new TypeReference<Map<String, Object>>() {
        };
        ByteArrayOutputStream outputstream = new ByteArrayOutputStream();

        // Read the original Cassandra config from services/cassandra/cassandra.yaml into a String
        byte[] oldConfigBytes = Files.readAllBytes(Paths.get(STORAGE_CONFIG_PATH, STORAGE_CONFIG_NAME));
        String oldConfig = new String(oldConfigBytes, StandardCharsets.UTF_8);

        // Convert the String of config values into a Map
        Map<String, Object> oldConfigMap = mapper.readValue(oldConfig, reference);
        oldConfigMap = Maps.transformValues(oldConfigMap, value -> value == null ? EMPTY_VALUE : value);

        // Set the original config as the starting point of the new config values
        Map<String, Object> newConfigMap = new HashMap<>(oldConfigMap);

        // Read the Grakn config which is available to the user
        Config inputConfig = Config
                .read(Paths.get(Objects.requireNonNull(SystemProperty.CONFIGURATION_FILE.value())));

        // Set the new data directories for Cassandra
        String newDataDir = inputConfig.getProperty(ConfigKey.DATA_DIR);
        newConfigMap.put(DATA_FILE_DIR_CONFIG_KEY, Collections.singletonList(newDataDir + DATA_SUBDIR));
        newConfigMap.put(SAVED_CACHES_DIR_CONFIG_KEY, newDataDir + SAVED_CACHES_SUBDIR);
        newConfigMap.put(COMMITLOG_DIR_CONFIG_KEY, newDataDir + COMMITLOG_SUBDIR);

        // Overwrite Cassandra config values with values provided in the Grakn config
        inputConfig.properties().stringPropertyNames().stream().filter(key -> key.contains(CONFIG_PARAM_PREFIX))
                .forEach(key -> newConfigMap.put(key.replaceAll(CONFIG_PARAM_PREFIX, ""),
                        inputConfig.properties().getProperty(key)));

        // Write the new Cassandra config into the original file: services/cassandra/cassandra.yaml
        mapper.writeValue(outputstream, newConfigMap);
        String newConfigStr = outputstream.toString(StandardCharsets.UTF_8.name());
        Files.write(Paths.get(STORAGE_CONFIG_PATH, STORAGE_CONFIG_NAME),
                newConfigStr.getBytes(StandardCharsets.UTF_8));

    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:jflowmap.data.CsvFlowMapGraphReader.java

private Map<String, String> asAttrValuesMap(final String[] csvLine, Map<String, Integer> colsByName) {
    return Maps.transformValues(colsByName, new Function<Integer, String>() {
        public String apply(Integer col) {
            return csvLine[col];
        }/*from   w w w .j ava2 s .c o  m*/
    });
}

From source file:com.exoplatform.iversion.Merge.java

public Map<K, V> getProperties() {
    return filterValues(Maps.transformValues(mergedProperties, getVersionPropertyValue), notNull());
}

From source file:com.google.gitiles.FakeHttpServletRequest.java

@Override
public Map<String, String[]> getParameterMap() {
    return Collections.unmodifiableMap(Maps.transformValues(parameters.asMap(), STRING_COLLECTION_TO_ARRAY));
}