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.n52.janmayen.Producers.java

public static <K, T> Map<K, T> produce(Map<K, Producer<T>> map) {
    return Maps.transformValues(map, Producer::get);
}

From source file:com.microsoftopentechnologies.intellij.helpers.EncodingHelper.java

public static Map<String, String> parseKeyValueList(String input, char delimiter, boolean urlDecode) {
    if (StringHelper.isNullOrWhiteSpace(input)) {
        return null;
    }//from  ww  w .  j a va 2  s .c om

    Map<String, String> response = Splitter.on(delimiter).trimResults().omitEmptyStrings()
            .withKeyValueSeparator('=').split(input);

    if (urlDecode) {
        return Maps.transformValues(response, new Function<String, String>() {
            @Override
            public String apply(String s) {
                try {
                    return URLDecoder.decode(s, Charsets.UTF_8.name());
                } catch (UnsupportedEncodingException e) {
                    return s;
                }
            }
        });
    } else {
        return response;
    }
}

From source file:org.jclouds.ec2.util.Tags.java

/**
 * maps the input on {@link Tag#getResourceId()} with a value of a map of its {@link Tag#getKey()} to
 * {@link Tag#getValue()}//w  w  w. ja  va  2 s. co  m
 */
public static Map<String, Map<String, String>> resourceToTagsAsMap(Iterable<Tag> tags) {
    return Maps.transformValues(index(tags, resourceIdFunction()).asMap(),
            new Function<Iterable<Tag>, Map<String, String>>() {
                @Override
                public Map<String, String> apply(Iterable<Tag> in) {
                    return Maps.transformValues(Maps.uniqueIndex(in, keyFunction()), valueFunction());
                }
            });
}

From source file:com.microsoftopentechnologies.auth.utils.EncodingHelper.java

public static Map<String, String> parseKeyValueList(String input, char delimiter, boolean urlDecode) {
    if (Strings.isNullOrEmpty(input)) {
        return null;
    }/* ww w  .j a  v  a 2s  .com*/

    Map<String, String> response = Splitter.on(delimiter).trimResults().omitEmptyStrings()
            .withKeyValueSeparator('=').split(input);

    if (urlDecode) {
        return Maps.transformValues(response, new Function<String, String>() {
            @Override
            public String apply(String s) {
                try {
                    return URLDecoder.decode(s, Charsets.UTF_8.name());
                } catch (UnsupportedEncodingException e) {
                    return s;
                }
            }
        });
    } else {
        return response;
    }
}

From source file:fr.dutra.confluence2wordpress.util.MapUtils.java

public static Map<String, String> split(String str, String entrySep, String keyValueSep) {
    if (StringUtils.isBlank(str)) {
        return null;
    }//  w  w  w .  j  a v  a 2s .  co m
    Splitter keyValueSplitter = Splitter.on(keyValueSep).trimResults();
    Splitter entrySplitter = Splitter.on(entrySep).trimResults().omitEmptyStrings();
    return Maps.transformValues(entrySplitter.withKeyValueSeparator(keyValueSplitter).split(str), TRIM_TO_NULL);
}

From source file:org.polarsys.reqcycle.jdt.traceability.JDTPreferences.java

public static Map<String, TType> getPreferences() {
    IConfigurationManager manager = ZigguratInject.make(IConfigurationManager.class);
    Map<String, Object> map = manager.getSimpleConfiguration(null, null, JDT_TYPES_CONSTANT, false);
    if (map == null) {
        return new HashMap<String, TType>();
    }/*from  w  w  w  .  j  a  v  a 2 s .c  o  m*/
    return new HashMap<String, TType>(Maps.transformValues(map, new MapFunction()));
}

From source file:com.google.api.codegen.config.Configs.java

static Map<TargetLanguage, VersionBound> createVersionMap(Map<String, Map<String, String>> inputMap) {
    Map<TargetLanguage, Map<String, String>> intermediate = buildMapWithDefault(inputMap);
    // Convert parsed YAML map into VersionBound object
    return Maps.transformValues(intermediate, new Function<Map<String, String>, VersionBound>() {
        @Override/*from w  w  w . j  a  v a 2  s .  c  o  m*/
        @Nullable
        public VersionBound apply(@Nullable Map<String, String> versionMap) {
            if (versionMap == null) {
                return null;
            }
            return VersionBound.create(versionMap.get("lower"), versionMap.get("upper"));
        }
    });
}

From source file:org.jclouds.rackspace.clouddns.v1.functions.RecordFunctions.java

/**
 * Take a Set of RecordDetails and return a Map of record id to the Record.
 *//*from w  w  w .  j  ava  2 s. c  om*/
public static Map<String, Record> toRecordMap(Set<RecordDetail> recordDetails) {
    Map<String, RecordDetail> idsToRecordDetails = Maps.uniqueIndex(recordDetails,
            RecordFunctions.GET_RECORD_ID);
    return Maps.transformValues(idsToRecordDetails, RecordFunctions.GET_RECORD);
}

From source file:pgentity.quest.SellPenguinsChecker.java

public SellPenguinsChecker(Map<String, Object> need) {
    requires = Maps.transformValues(need, new Function<Object, SellPenguinRequire>() {
        @Override/*  ww  w .ja v  a  2  s  .  c o m*/
        public SellPenguinRequire apply(Object data) {
            Map<String, Object> mData = (Map) data;
            return new SellPenguinRequire(PGHelper.toInteger((String) mData.get("number")),
                    PGHelper.toInteger((String) mData.get("level")));
        }
    });
}

From source file:org.trancecode.xml.saxon.SaxonMaps.java

public static Map<QName, String> attributes(final Iterable<XdmNode> attributes) {
    assert Iterables.all(attributes, SaxonPredicates.isAttribute());
    final Map<QName, XdmNode> nodeMap = Maps.uniqueIndex(attributes, SaxonFunctions.getNodeName());
    return Maps.transformValues(nodeMap, SaxonFunctions.getStringValue());
}