Example usage for com.google.common.base Splitter.MapSplitter split

List of usage examples for com.google.common.base Splitter.MapSplitter split

Introduction

In this page you can find the example usage for com.google.common.base Splitter.MapSplitter split.

Prototype

@CheckReturnValue
public Iterable<String> split(final CharSequence sequence) 

Source Link

Document

Splits sequence into string components and makes them available through an Iterator , which may be lazily evaluated.

Usage

From source file:com.streamsets.pipeline.lib.el.StringEL.java

@ElFunction(prefix = "str", name = "splitKV", description = "Splits key value pairs into a map")
public static Map<String, Field> splitKV(@ElParam("string") String string,
        @ElParam("pairSeparator") String separator, @ElParam("kvSeparator") String kvSeparator) {
    if (Strings.isNullOrEmpty(string)) {
        return Collections.emptyMap();
    }//w  w w . ja va  2 s  .  c o m

    Splitter.MapSplitter splitter = Splitter.on(separator).trimResults().omitEmptyStrings()
            .withKeyValueSeparator(Splitter.on(kvSeparator).limit(2));

    return splitter.split(string).entrySet().stream()
            .collect(Collectors.toMap(Map.Entry::getKey, e -> Field.create(e.getValue())));
}