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:co.cask.cdap.api.common.RuntimeArguments.java

/**
 * Converts a POSIX compliant program argument array to a String-to-String Map.
 * @param args Array of Strings where each element is a POSIX compliant program argument (Ex: "--os=Linux" ).
 * @return Map of argument Keys and Values (Ex: Key = "os" and Value = "Linux").
 *//*from  w w  w.j a  v  a  2 s  .  c  om*/
public static Map<String, String> fromPosixArray(String[] args) {
    Map<String, String> kvMap = Maps.newHashMap();
    for (String arg : args) {
        kvMap.putAll(Splitter.on("--").omitEmptyStrings().trimResults().withKeyValueSeparator("=").split(arg));
    }
    return kvMap;
}

From source file:com.xebialabs.deployit.ci.util.Strings2.java

public static List<String> commaSeparatedListToList(String commaSeparatedList) {
    return ImmutableList.copyOf(Splitter.on(COMMA_SEPARATOR).trimResults().split(commaSeparatedList));
}

From source file:org.apache.james.backends.cassandra.init.CassandraNodeIpAndPort.java

public static CassandraNodeIpAndPort parseConfString(String ipAndPort) {
    Preconditions.checkNotNull(ipAndPort);
    Preconditions.checkArgument(!ipAndPort.isEmpty());

    List<String> parts = Splitter.on(':').trimResults().splitToList(ipAndPort);

    if (parts.size() < 1 || parts.size() > 2) {
        throw new IllegalArgumentException(ipAndPort + " is not a valid cassandra node");
    }//from w  ww. j a v  a  2  s  .com

    String ip = parts.get(0);
    int port = getPortFromConfPart(parts);

    return new CassandraNodeIpAndPort(ip, port);
}

From source file:org.locationtech.geogig.storage.impl.Blobs.java

public static List<String> readLines(Optional<byte[]> blob) {
    List<String> lines = ImmutableList.of();
    if (blob.isPresent()) {
        String contents = new String(blob.get(), Charsets.UTF_8);
        lines = Splitter.on("\n").splitToList(contents);
    }//www .  j a  v  a  2  s  .  c  o m
    return lines;
}

From source file:com.joshondesign.bespokeide.Util.java

public static TextArray codeToTextArray(CharSequence methodCode) {
    final Splitter splitter = Splitter.on('\n');
    final Iterable<String> lines = splitter.split(methodCode);
    String sep = "";

    for (String s : lines) {
        final String s2 = CharMatcher.WHITESPACE.trimLeadingFrom(s);
        if (s2.length() < s.length()) {
            sep = s.substring(0, (s.length() - s2.length()));
            break;
        }/* w w  w.  j av  a2  s. co  m*/
    }
    if ("".equals(sep)) {
        return new TextArray(new CharSequence[] { methodCode }, "");
    }
    return new TextArray(Splitter.on(sep).split(methodCode), sep);
}

From source file:com.lithium.flow.util.HostUtils.java

@Nonnull
public static List<String> expand(@Nonnull String expression) {
    checkNotNull(expression);//from  w w w .  ja va  2 s .co m

    int index1 = expression.indexOf("[");
    int index2 = expression.indexOf("]", index1);
    if (index1 > -1 && index2 > -1 && index2 < expression.length()) {
        String prefix = expression.substring(0, index1);
        String ranges = expression.substring(index1 + 1, index2);
        String postfix = expression.substring(index2 + 1);

        List<String> includes = Lists.newArrayList();
        List<String> excludes = Lists.newArrayList();

        for (String range : Splitter.on(',').split(ranges)) {
            List<String> list = range.startsWith("!") ? excludes : includes;
            range = range.replace("!", "");

            Iterator<String> it = Splitter.on('-').split(range).iterator();
            String first = it.next();
            String last = it.hasNext() ? it.next() : first;
            String format = "%0" + first.length() + "d";
            IntStream.rangeClosed(parseInt(first), parseInt(last))
                    .forEach(next -> list.add(prefix + String.format(format, next) + postfix));
        }

        includes.removeAll(excludes);
        return includes;
    } else {
        return Arrays.asList(expression);
    }
}

From source file:com.netflix.metacat.common.server.properties.PropertyUtils.java

/**
 * Convert a delimited string into a List of {@code QualifiedName}.
 *
 * @param names     The list of names to split
 * @param delimiter The delimiter to use for splitting
 * @return The list of qualified names//w  w w. ja v a2s  .c o m
 */
static List<QualifiedName> delimitedStringsToQualifiedNamesList(@Nonnull @NonNull final String names,
        final char delimiter) {
    if (StringUtils.isNotBlank(names)) {
        return Splitter.on(delimiter).omitEmptyStrings().splitToList(names).stream()
                .map(QualifiedName::fromString).collect(Collectors.toList());
    } else {
        return Lists.newArrayList();
    }
}

From source file:org.jclouds.docker.features.internal.Archives.java

public static File tar(File baseDir, File tarFile) throws IOException {
    // Check that the directory is a directory, and get its contents
    checkArgument(baseDir.isDirectory(), "%s is not a directory", baseDir);
    File[] files = baseDir.listFiles();
    String token = getLast(Splitter.on("/").split(baseDir.getAbsolutePath()));
    TarArchiveOutputStream tos = new TarArchiveOutputStream(new FileOutputStream(tarFile));
    tos.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);
    try {/*from  w w w .j a  va 2s  . c o  m*/
        for (File file : files) {
            TarArchiveEntry tarEntry = new TarArchiveEntry(file);
            tarEntry.setName("/" + getLast(Splitter.on(token).split(file.toString())));
            tos.putArchiveEntry(tarEntry);
            if (!file.isDirectory()) {
                Files.asByteSource(file).copyTo(tos);
            }
            tos.closeArchiveEntry();
        }
    } finally {
        tos.close();
    }
    return tarFile;
}

From source file:com.github.arven.auth.UserManager.java

public static void create(String id, String name, String pass, Collection<String> roles) {
    String first = "John";
    String last = "Anonymous";
    Iterator<String> split = Splitter.on(" ").omitEmptyStrings().trimResults().split(name).iterator();

    if (split.hasNext()) {
        first = split.next();/*from w  ww.  j  a v  a2 s  .c  o  m*/
    }

    if (split.hasNext()) {
        last = split.next();
    }

    try {
        InitialDirContext context = new InitialDirContext(PROPERTIES);
        Attributes attributes = new BasicAttributes();
        attributes.put(new BasicAttribute("objectClass", "inetOrgPerson"));
        attributes.put(new BasicAttribute("uid", id));
        attributes.put(new BasicAttribute("cn", first));
        attributes.put(new BasicAttribute("sn", last));
        attributes.put(new BasicAttribute("userPassword", pass));
        context.createSubcontext("uid=" + id + "," + USER_CONTEXT, attributes);

        for (String role : roles) {
            ModificationItem[] mods = { new ModificationItem(DirContext.ADD_ATTRIBUTE,
                    new BasicAttribute("uniqueMember", "uid=" + id + "," + USER_CONTEXT)) };
            context.modifyAttributes("cn=" + role + "," + GROUP_CONTEXT, mods);
        }
    } catch (NamingException ex) {
        Logger.getLogger(UserManager.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.google.caliper.runner.worker.ProxyWorkerException.java

private static String formatMessage(String stackTrace) {
    StringBuilder builder = new StringBuilder(stackTrace.length() + 512)
            .append("An exception occurred in a worker process. The stack trace is as follows:\n\t");
    Joiner.on("\n\t").appendTo(builder, Splitter.on('\n').split(stackTrace));
    return builder.toString();
}