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.google.devtools.moe.client.repositories.PublicSectionMetadataScrubber.java

@Override
public RevisionMetadata execute(RevisionMetadata rm, MetadataScrubberConfig unused) {
    List<String> lines = Splitter.on('\n').splitToList(rm.description);
    int startPublicSection = -1;
    int endPublicSection = -1;
    int currentLine = 0;
    for (String line : lines) {
        if (PUBLIC_SECTION_PATTERN.matcher(line).matches()) {
            startPublicSection = currentLine;
            endPublicSection = lines.size();
        } else if (startPublicSection >= 0 && END_PUBLIC_SECTION_PATTERN.matcher(line).matches()) {
            endPublicSection = currentLine;
        }/* w  w w. ja  v  a  2s .c  o m*/
        ++currentLine;
    }

    String newDesc = (startPublicSection >= 0)
            ? Joiner.on("\n").join(lines.subList(startPublicSection + 1, endPublicSection))
            : rm.description;
    return new RevisionMetadata(rm.id, rm.author, rm.date, newDesc, rm.parents);
}

From source file:com.spotify.helios.common.descriptors.ServiceEndpoint.java

public ServiceEndpoint(final String s) {
    final List<String> parts = Splitter.on('/').splitToList(s);
    if (parts.size() < 1 || parts.size() > 2) {
        throw new IllegalArgumentException();
    }//from  ww  w.ja va 2 s .c o m
    name = parts.get(0);
    protocol = parts.size() > 1 ? parts.get(1) : HTTP;
}

From source file:org.autobet.CsvFileReader.java

private ImmutableList<String> split(Optional<String> headerLine) {
    if (!headerLine.isPresent()) {
        return ImmutableList.of();
    } else {// w  ww .  j a v  a 2s. c  o m
        return ImmutableList.copyOf(Splitter.on(",").split(headerLine.get()));
    }
}

From source file:net.holmes.core.common.MimeType.java

/**
 * Instantiates a new mime type.//from   w  w w . j  a  v  a  2s . c o  m
 *
 * @param mimeType mime type
 */
private MimeType(final String mimeType) {
    this.mimeType = mimeType;
    Iterable<String> iterable = Splitter.on('/').split(mimeType);
    this.type = MediaType.getByValue(Iterables.getFirst(iterable, ""));
    this.subType = Iterables.getLast(iterable, "");
}

From source file:com.google.api.codegen.transformer.ruby.RubyPackageMetadataNamer.java

@Override
public String getMetadataIdentifier() {
    // strip out the string before the first v0 part of the path
    Matcher m = RubyUtil.getVersionMatcher(packageName);
    List<String> names = Splitter.on("::").splitToList(m.matches() ? m.group(1) : packageName);

    // drop last if not a versioned id
    if (!m.matches() && names.size() > 0) {
        names = names.subList(0, names.size() - 1);
    }/*  w  w w. j  a  va2s.  c o m*/

    // convert case and replace :: with -
    return names.stream().map(x -> Name.upperCamel(x).toLowerUnderscore()).reduce("",
            (x, y) -> x.length() > 0 ? x + METADATA_IDENTIFIER_SEPARATOR + y : y);
}

From source file:com.notifier.desktop.transport.usb.impl.Adb.java

public List<Device> devices() throws IOException, InterruptedException {
    Preconditions.checkNotNull(sdkHome, "Android SDK home has not been set");
    String output = runAdb("devices");
    Iterator<String> lines = Splitter.on('\n').trimResults().split(output).iterator();
    for (; lines.next().startsWith("*");) {
        ; // Ignore daemon messages
    }//  w  w  w  . j a v  a2s .  com
    List<Device> devices = Lists.newArrayList();
    Splitter lineSplitter = Splitter.on('\t').trimResults();
    while (lines.hasNext()) {
        String line = lines.next();
        if (!line.isEmpty()) {
            Iterator<String> parts = lineSplitter.split(line).iterator();
            String serialNumber = parts.next();
            Device.Type type = Device.Type.parse(parts.next());
            devices.add(new Device(serialNumber, type));
        }
    }
    return devices;
}

From source file:com.tngtech.archunit.testutils.ExpectedViolation.java

private ExpectedViolation(String ruleText) {
    this(new MessageAssertionChain());

    LinkedList<String> ruleLines = new LinkedList<>(Splitter.on(lineSeparator()).splitToList(ruleText));
    checkArgument(!ruleLines.isEmpty(), "Rule text may not be empty");
    if (ruleLines.size() == 1) {
        addSingleLineRuleAssertion(getOnlyElement(ruleLines));
    } else {/*from   www.  jav  a 2 s .c  o  m*/
        addMultiLineRuleAssertion(ruleLines);
    }
}

From source file:com.dangdang.ddframe.rdb.sharding.config.common.internal.parser.InlineParser.java

/**
 * ?.
 * 
 * @return ???
 */
public List<String> split() {
    return Splitter.on(SPLITTER).trimResults().splitToList(inlineExpression);
}

From source file:com.github.tomakehurst.wiremock.common.Urls.java

public static String urlToPathParts(URI uri) {
    Iterable<String> uriPathNodes = Splitter.on("/").omitEmptyStrings().split(uri.getPath());
    int nodeCount = Iterables.size(uriPathNodes);

    return nodeCount > 0 ? Joiner.on("-").join(from(uriPathNodes).skip(nodeCount - Math.min(nodeCount, 2)))
            : "";
}

From source file:io.pengyuc.jackson.versioning.Version.java

@JsonCreator
public static Version fromString(String versionStr) {
    Preconditions.checkArgument(!Strings.isNullOrEmpty(versionStr));
    Preconditions.checkArgument(!versionStr.startsWith("."), "Version string must not start with dot: {}",
            versionStr);/* w  w w  .  ja  v  a  2  s.  c  om*/

    List<String> subVersionStrs = Splitter.on(".").omitEmptyStrings().trimResults().splitToList(versionStr);
    List<Integer> subVersionNumbers = Lists.newArrayListWithExpectedSize(subVersionStrs.size());
    for (String subVersionStr : subVersionStrs) {
        Integer integer = Integer.valueOf(subVersionStr);
        if (integer < 0)
            throw new IllegalArgumentException("Input string value cannot be negative: " + subVersionStr);
        subVersionNumbers.add(integer);
    }
    if (subVersionNumbers.size() == 0) {
        throw new IllegalArgumentException("Cannot convert the version correctly: " + versionStr);
    }
    return new Version(subVersionNumbers);
}