Example usage for com.google.common.base Splitter on

List of usage examples for com.google.common.base Splitter on

Introduction

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

Prototype

@CheckReturnValue
@GwtIncompatible("java.util.regex")
public static Splitter on(final Pattern separatorPattern) 

Source Link

Document

Returns a splitter that considers any subsequence matching pattern to be a separator.

Usage

From source file:io.macgyver.test.RequestUtil.java

public static Map<String, String> parseFormBody(String body, String encoding) {

    try {//from   w ww .j a v a  2  s.  co m
        Map<String, String> m = Maps.newHashMap();

        for (String kv : Splitter.on("&").omitEmptyStrings().split(Strings.nullToEmpty(body))) {

            List<String> kvList = Splitter.on("=").omitEmptyStrings().splitToList(kv);

            if (kvList.size() == 2) {
                m.put(URLDecoder.decode(kvList.get(0), encoding), URLDecoder.decode(kvList.get(1), encoding));
            }

        }

        return m;
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException(e);
    }
}

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 ww .  j  a  v  a 2 s .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.jclouds.azurecompute.arm.compute.domain.LocationAndName.java

public static LocationAndName fromSlashEncoded(String id) {
    Iterable<String> parts = Splitter.on('/').split(checkNotNull(id, "id"));
    checkArgument(Iterables.size(parts) == 2, "id must be in format location/name");
    return new AutoValue_LocationAndName(Iterables.get(parts, 0), Iterables.get(parts, 1));
}

From source file:org.eclipse.buildship.core.util.collections.CollectionsUtils.java

/**
 * Splits the given string for each space that is found.
 *
 * @param string the string to split, can be null
 * @return the split string with each segment being an element of the returned list, never null
 *///from   ww  w.  j a  va  2  s  .c  o  m
public static ImmutableList<String> splitBySpace(String string) {
    return Strings.isNullOrEmpty(string) ? ImmutableList.<String>of()
            : ImmutableList.copyOf(Splitter.on(SPACE).omitEmptyStrings().splitToList(string));
}

From source file:com.stratio.ingestion.sink.cassandra.CassandraUtils.java

public static void executeCqlScript(final Session session, final String script) {
    if (script == null) {
        return;/*from   w  ww .  j ava2s . co  m*/
    }
    final List<String> lines = new ArrayList<String>();
    for (final String line : Splitter.on("\n").split(script)) {
        lines.add(line.trim());
    }
    for (String cql : Joiner.on(" ").join(lines).split(";")) {
        cql = cql.trim();
        if (cql.isEmpty()) {
            continue;
        }
        session.execute(cql);
    }
}

From source file:org.apache.isis.applib.util.Enums.java

public static String getFriendlyNameOf(String anEnumName) {
    return Joiner.on(" ")
            .join(Iterables.transform(Splitter.on("_").split(anEnumName), LOWER_CASE_THEN_CAPITALIZE));
}

From source file:com.intel.podm.common.utils.StringRepresentation.java

public static Map<String, String> toMap(String stringToSplit, boolean trimResults, boolean omitEmptyStrings) {
    Splitter splitter = Splitter.on(ELEMENT_SEPARATOR);

    if (trimResults) {
        splitter = splitter.trimResults();
    }//from w  ww .  j a  v a 2  s  .  c  o m

    if (omitEmptyStrings) {
        splitter = splitter.omitEmptyStrings();
    }

    Map<String, String> resultMap = splitter.withKeyValueSeparator(KEY_VALUE_SEPARATOR).split(stringToSplit);
    resultMap = new HashMap<>(resultMap);
    convertStringNullValues(resultMap);
    return resultMap;
}

From source file:org.jclouds.azurecompute.arm.compute.domain.ResourceGroupAndName.java

public static ResourceGroupAndName fromSlashEncoded(String id) {
    Iterable<String> parts = Splitter.on('/').split(checkNotNull(id, "id"));
    checkArgument(Iterables.size(parts) == 2, "id must be in format resourcegroup/name");
    return new AutoValue_ResourceGroupAndName(Iterables.get(parts, 0), Iterables.get(parts, 1));
}

From source file:annis.service.objects.FrequencyTableEntry.java

/**
 * A constructor that takes the raw definition as argument.
 * /*ww  w. ja  v  a2s . c  o m*/
 * A definition consists of two parts: the referenced node and the annotation 
 * name or "tok" separated by ":" 
 * @param definition 
 * @return 
 */
public static FrequencyTableEntry parse(String definition) {
    List<String> splitted = Splitter.on(':').trimResults().omitEmptyStrings().limit(2).splitToList(definition);
    if (splitted.size() == 2) {
        FrequencyTableEntry entry = new FrequencyTableEntry();

        if ("meta".equals(splitted.get(0))) {
            entry.setReferencedNode(null);
            entry.setType(FrequencyTableEntryType.meta);
            entry.setKey(splitted.get(1));
        } else {
            entry.setReferencedNode(splitted.get(0));
            if ("tok".equals(splitted.get(1))) {
                entry.setType(FrequencyTableEntryType.span);
            } else {
                entry.setType(FrequencyTableEntryType.annotation);
                entry.setKey(splitted.get(1));
            }
        }
        return entry;
    }
    return null;
}

From source file:org.apache.sling.tracer.internal.PrefixExcludeFilter.java

public static PrefixExcludeFilter from(String filter) {
    List<String> prefixes = Splitter.on('|').omitEmptyStrings().trimResults().splitToList(filter);
    return new PrefixExcludeFilter(prefixes);
}