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:com.ebay.pulsar.analytics.datasource.PulsarTableDimension.java

public void setAlias(String alias) {
    this.alias = alias;
    super.columnNames.addAll(Sets.newHashSet(Splitter.on(',').trimResults().split(alias)));
}

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

/**
 * Wrap some text/*from   w  w  w.  jav  a  2s  .co  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.android.tools.idea.avdmanager.SkinLayoutDefinition.java

@Nullable
public static SkinLayoutDefinition parseFile(@NotNull File file, @NotNull FileOp fop) {
    String contents;/*from  w w  w.j av  a  2  s .c  o  m*/
    try {
        contents = fop.toString(file, Charsets.UTF_8);
    } catch (IOException e) {
        return null;
    }
    return loadFromTokens(
            Splitter.on(ourWhitespacePattern).omitEmptyStrings().trimResults().split(contents).iterator());
}

From source file:com.greensopinion.finance.services.transaction.EntityReferences.java

private static ListMultimap<String, String> readEntityReferences() {
    ImmutableListMultimap.Builder<String, String> builder = ImmutableListMultimap.builder();
    try {//www.  ja  v  a2 s .  c om
        BufferedReader reader = new BufferedReader(new InputStreamReader(
                EntityReferences.class.getResourceAsStream("entity-references.txt"), Charsets.UTF_8)); //$NON-NLS-1$
        try {
            Splitter splitter = Splitter.on(CharMatcher.WHITESPACE).trimResults().omitEmptyStrings();

            String line;
            while ((line = reader.readLine()) != null) {
                List<String> lineItems = splitter.splitToList(line);
                checkState(lineItems.size() > 1);
                for (int x = 1; x < lineItems.size(); ++x) {
                    builder.put(lineItems.get(0), lineItems.get(x));
                }
            }
        } finally {
            reader.close();
        }
    } catch (IOException e) {
        throw Throwables.propagate(e);
    }
    return builder.build();
}

From source file:org.apache.james.transport.mailets.MappingArgument.java

public static ImmutableMap<String, String> parse(String mapping) throws MessagingException {
    Preconditions.checkArgument(mapping != null, "mapping should not be null");

    if (mapping.trim().isEmpty()) {
        return ImmutableMap.of();
    }/*from ww  w.  java  2s.c o m*/

    return Splitter.on(',').omitEmptyStrings().splitToList(mapping).stream().map(MappingArgument::parseKeyValue)
            .collect(Guavate.toImmutableMap(Pair::getLeft, Pair::getRight));
}

From source file:com.google.api.codegen.util.CommonRenderingUtil.java

/** Returns the input text split on newlines. */
public static List<String> getDocLines(String text) {
    // TODO: Convert markdown to language-specific doc format.
    // https://github.com/googleapis/toolkit/issues/331
    List<String> result = Splitter.on(String.format("%n")).splitToList(text);
    return result.size() == 1 && result.get(0).isEmpty() ? ImmutableList.<String>of() : result;
}

From source file:com.manymo.ListParser.java

@NonNull
Map<String, DeviceData> parseDevices(String data) {
    return parseDevices(Splitter.on('\n').split(data));
}

From source file:pl.otros.logview.loader.AutomaticMarkerLoader.java

public static ArrayList<AutomaticMarker> loadInternalMarkers() throws IOException {

    ArrayList<AutomaticMarker> markers = new ArrayList<AutomaticMarker>();
    Properties p = new Properties();
    p.load(AutomaticMarkerLoader.class.getClassLoader().getResourceAsStream("markers.properties"));
    final Iterable<String> defaultMarkers = Splitter.on(',').split(p.getProperty("defaultMarkers"));
    for (String line : defaultMarkers) {
        try {//from   w  ww .  j a va 2 s .  co  m
            Class<?> c = AutomaticMarkerLoader.class.getClassLoader().loadClass(line);
            AutomaticMarker am = (AutomaticMarker) c.newInstance();
            markers.add(am);
        } catch (ClassNotFoundException e) {
            LOGGER.log(Level.SEVERE, "Error loading class " + line, e);
        } catch (InstantiationException e) {
            LOGGER.log(Level.SEVERE, "Error loading class " + line, e);
        } catch (IllegalAccessException e) {
            LOGGER.log(Level.SEVERE, "Error loading class " + line, e);
        }
    }

    return markers;

}

From source file:com.facebook.presto.recordservice.RecordServiceConnectorConfig.java

public static ImmutableSet<HostAddress> parsePlannerHostPorts(String plannerHostPorts) {
    Splitter splitter = Splitter.on(',').omitEmptyStrings().trimResults();
    return ImmutableSet.copyOf(transform(splitter.split(plannerHostPorts),
            (value -> HostAddress.fromString(value).withDefaultPort(RECORDSERVICE_PLANNER_DEFAULT_PORT))));
}

From source file:net.minecraftforge.gradle.util.mcp.JavadocAdder.java

/**
 * Converts a raw javadoc string into a nicely formatted, indented, and wrapped string.
 * @param indent the indent to be inserted before every line.
 * @param javadoc The javadoc string to be processed
 * @param isMethod If this javadoc is for a method or a field
 * @return A fully formatted javadoc comment string complete with comment characters and newlines.
 *///from   ww  w  . j a v a 2  s.c o  m
public static String buildJavadoc(String indent, String javadoc, boolean isMethod) {
    StringBuilder builder = new StringBuilder();

    // split and wrap.
    List<String> list = new LinkedList<String>();
    for (String line : Splitter.on("\\n").splitToList(javadoc)) {
        list.addAll(wrapText(line, 120 - (indent.length() + 3)));
    }

    if (list.size() > 1 || isMethod) {
        builder.append(indent);
        builder.append("/**");
        builder.append(Constants.NEWLINE);

        for (String line : list) {
            builder.append(indent);
            builder.append(" * ");
            builder.append(line);
            builder.append(Constants.NEWLINE);
        }

        builder.append(indent);
        builder.append(" */");
        //builder.append(Constants.NEWLINE);

    }
    // one line
    else {
        builder.append(indent);
        builder.append("/** ");
        builder.append(javadoc);
        builder.append(" */");
        //builder.append(Constants.NEWLINE);
    }

    return builder.toString().replace(indent, indent);
}