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:org.sonar.server.ui.VersionFormatter.java

public static String format(String technicalVersion) {
    List<String> elements = Splitter.on(VERSION_SEQUENCE_SEPARATION).splitToList(technicalVersion);
    if (elements.size() != 4) {
        return technicalVersion;
    }/*from  w  ww  .  j av  a  2s .  c o m*/

    // version has the form 6.3.1.4563
    StringBuilder builder = new StringBuilder();
    builder.append(elements.get(0)).append(VERSION_SEQUENCE_SEPARATION).append(elements.get(1));
    if (!"0".equals(elements.get(2))) {
        builder.append(VERSION_SEQUENCE_SEPARATION).append(elements.get(2));
    }

    builder.append(" (build ").append(elements.get(3)).append(")");

    return builder.toString();
}

From source file:org.glowroot.container.ClassPath.java

private static @Nullable File getJarFile(String pattern) {
    String classpath = StandardSystemProperty.JAVA_CLASS_PATH.value();
    if (classpath == null) {
        return null;
    }/*from   ww  w . j av a 2s.  c  om*/
    for (String path : Splitter.on(File.pathSeparator).split(classpath)) {
        File file = new File(path);
        if (file.getName().matches(pattern)) {
            return file;
        }
    }
    return null;
}

From source file:com.teradata.tempto.fulfillment.table.TableHandle.java

public static TableHandle parse(String value) {
    if (value.contains(".")) {
        List<String> parts = Splitter.on('.').splitToList(value);
        checkArgument(parts.size() <= 3,
                "Invalid table name syntax. Expected at most two occurrences of '.' in '%s'.", value);
        if (parts.size() == 2) {
            return tableHandle(parts.get(1)).inDatabase(parts.get(0));
        }//  w ww . j  ava  2  s.c om
        return tableHandle(parts.get(2)).inDatabase(parts.get(0)).inSchema(parts.get(1));
    } else {
        return tableHandle(value);
    }
}

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;
    }// 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:org.jclouds.googlecomputeengine.domain.SlashEncodedIds.java

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

From source file:com.facebook.presto.accumulo.MiniAccumuloConfigUtil.java

/**
 * MiniAccumuloClusterImpl will build the class path itself if not set,
 * but the code fails on Java 9 due to assumptions about URLClassLoader.
 *///from   w  w  w.  java  2s .  co m
public static void setConfigClassPath(MiniAccumuloConfig config) {
    List<String> items = Splitter.on(File.pathSeparatorChar).splitToList(getRuntimeMXBean().getClassPath());
    getConfigImpl(config).setClasspathItems(items.toArray(new String[0]));
}

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;
    }//from  w w w .  j  av a2s. 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.elb.domain.regionscoped.RegionAndName.java

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

From source file:org.jclouds.openstack.nova.v2_0.domain.zonescoped.ZoneAndId.java

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

From source file:org.jclouds.joyent.sdc.v6_5.domain.datacenterscoped.DatacenterAndId.java

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