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

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

Introduction

In this page you can find the example usage for com.google.common.base Splitter 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:fastcall.FStringUtils.java

/**
 * Return a list of split String using Guava splitter
 * @param line//ww  w . ja  v  a2s.  c o  m
 * @param splitS
 * @return 
 */
public static List<String> fastSplit(String line, String splitS) {
    List<String> ls = new ArrayList<String>();
    Splitter spl = Splitter.on(splitS);
    Iterator<String> it = spl.split(line).iterator();
    while (it.hasNext()) {
        ls.add(it.next());
    }
    return ls;
}

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

public static List<String> split(String str, String sep) {
    if (StringUtils.isBlank(str)) {
        return null;
    }/*from  w  ww .jav a2 s  .c om*/
    Splitter splitter = Splitter.on(sep).trimResults().omitEmptyStrings();
    List<String> list = new ArrayList<String>();
    for (String token : splitter.split(str)) {
        list.add(token);
    }
    if (list.isEmpty()) {
        return null;
    }
    return list;
}

From source file:com.sonyericsson.jenkins.plugins.bfa.tokens.TokenUtils.java

/**
 * Wrap some text/*from w  w  w .  j  av  a 2 s. c  o  m*/
 * @param text some text to wrap
 * @param width the text will be wrapped to this many characters
 * @return the text lines
 */
/* package private */ static List<String> wrap(final String text, final int width) {
    final List<String> lines = new ArrayList<String>();
    final Splitter lineSplitter = Splitter.on(Pattern.compile("\\r?\\n"));
    //Split the text into lines
    for (final String line : lineSplitter.split(text)) {
        if (width > 0) {
            final Pattern firstNonwhitespacePattern = Pattern.compile("[^\\s]");
            final Matcher firstNonwhiteSpaceMatcher = firstNonwhitespacePattern.matcher(line);
            String indent = "";
            if (firstNonwhiteSpaceMatcher.find()) {
                indent = line.substring(0, firstNonwhiteSpaceMatcher.start());
            }
            //Wrap each line
            final String wrappedLines = WordUtils.wrap(line, width - indent.length());
            //Split the wrapped line into lines and add those lines to the result
            for (final String wrappedLine : lineSplitter.split(wrappedLines)) {
                lines.add(indent + wrappedLine.trim());
            }
        } else {
            lines.add(line);
        }
    }
    return lines;
}

From source file:com.mapr.franz.hazel.HazelCatcher.java

private static HazelcastInstance setupHazelCast(String hosts) {
    Config config = new ClasspathXmlConfig("cluster.xml");

    Splitter onCommas = Splitter.on(",").omitEmptyStrings().trimResults();
    for (String host : onCommas.split(hosts)) {
        config.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false);
        config.getNetworkConfig().getJoin().getTcpIpConfig().setEnabled(true);
        config.getNetworkConfig().getJoin().getTcpIpConfig().addMember(host);
    }//from  w  w  w . ja va2s .  c  o m

    logger.warn("config = {}", config);
    return Hazelcast.newHazelcastInstance(config);
}

From source file:org.apache.blur.spark.util.JavaSparkUtil.java

public static void packProjectJars(SparkConf conf) throws IOException {
    String classPath = System.getProperty(JAVA_CLASS_PATH);
    String pathSeparator = System.getProperty(PATH_SEPARATOR);
    Splitter splitter = Splitter.on(pathSeparator);
    Iterable<String> split = splitter.split(classPath);
    List<String> list = toList(split);
    List<String> classPathThatNeedsToBeIncluded = removeSparkLibs(list);
    List<String> jars = new ArrayList<String>();
    for (String s : classPathThatNeedsToBeIncluded) {
        if (isJarFile(s)) {
            jars.add(s);//  ww w .j a va2 s .co m
        } else {
            jars.add(createJar(s));
        }
    }
    conf.setJars(jars.toArray(new String[jars.size()]));
}

From source file:yrun.YarnRunnerUtil.java

private static Path buildJar(URL url, String resourceName) throws IOException {
    String classPath = System.getProperty(JAVA_CLASS_PATH);
    String pathSeparator = System.getProperty(PATH_SEPARATOR);
    Splitter splitter = Splitter.on(pathSeparator);
    for (String path : splitter.split(classPath)) {
        File file = new File(new File(path), resourceName);
        if (file.exists()) {
            return buildJarFromClassFile(file, resourceName);
        }//from   w  ww . ja  v a2s  .c om
    }
    throw new IOException("Resource [" + resourceName + "] not found in classpath.");
}

From source file:io.prestosql.plugin.kafka.KafkaConnectorConfig.java

public static ImmutableSet<HostAddress> parseNodes(String nodes) {
    Splitter splitter = Splitter.on(',').omitEmptyStrings().trimResults();
    return ImmutableSet.copyOf(transform(splitter.split(nodes), KafkaConnectorConfig::toHostAddress));
}

From source file:com.bsiag.geneclipsetoc.internal.contexts.ContextUtility.java

public static String toXml(List<Context> contexts) {
    StringBuilder sb = new StringBuilder();
    sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
    sb.append(NEW_LINE);//from w w  w . j a v  a2 s .co m
    sb.append("<?NLS TYPE=\"org.eclipse.help.contexts\"?>");
    sb.append(NEW_LINE);
    sb.append("<contexts>");
    if (contexts != null) {
        for (Context context : contexts) {
            sb.append(NEW_LINE);
            sb.append(INDENTATION);
            sb.append("<context");
            appendAttr(sb, "id", context.getId());
            appendAttr(sb, "title", context.getTitle());
            sb.append(">");
            if (context.getDescription() != null && context.getDescription().length() > 0) {
                sb.append(NEW_LINE);
                sb.append(INDENTATION);
                sb.append(INDENTATION);
                sb.append("<description>");
                Splitter splitter = Splitter.onPattern("\r?\n");
                boolean needNewLine = false;
                for (String line : splitter.split(context.getDescription())) {
                    if (needNewLine) {
                        sb.append(NEW_LINE);
                    }
                    sb.append(XmlEscapers.xmlAttributeEscaper().escape(line));
                    needNewLine = true;
                }
                sb.append("</description>");
            }
            if (context.getTopics() != null) {
                for (Topic topic : context.getTopics()) {
                    sb.append(NEW_LINE);
                    sb.append(INDENTATION);
                    sb.append(INDENTATION);
                    sb.append("<topic");
                    appendAttr(sb, "label", topic.getLabel());
                    appendAttr(sb, "href", topic.getHref());
                    sb.append("/>");
                }
            }
            sb.append(NEW_LINE);
            sb.append(INDENTATION);
            sb.append("</context>");
        }
    }
    sb.append(NEW_LINE);
    sb.append("</contexts>");
    return sb.toString();
}

From source file:com.xebialabs.overthere.ssh.SshFile.java

static List<String> splitPath(String path, OperatingSystemFamily os) {
    Splitter s = os == WINDOWS ? WINDOWS_PATH_SPLITTER : UNIX_PATH_SPLITTER;
    return newArrayList(s.split(path));
}

From source file:com.google.publicalerts.cap.validator.ValidatorUtil.java

public static Set<CapProfile> parseProfiles(String profileStr) {
    if (CapUtil.isEmptyOrWhitespace(profileStr)) {
        return ImmutableSet.of();
    }/* www  . j a  v  a2  s.  c o m*/

    Splitter splitter = Splitter.on(",").trimResults().omitEmptyStrings();
    List<String> profileList = Lists.newArrayList(splitter.split(profileStr));
    Set<CapProfile> profiles = Sets.newHashSet();
    for (CapProfile profile : CapProfiles.getProfiles()) {
        for (String p : profileList) {
            if (profile.getCode().equals(p)) {
                profiles.add(profile);
            }
        }
    }
    return profiles;
}