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

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

Introduction

In this page you can find the example usage for com.google.common.base Splitter onPattern.

Prototype

@CheckReturnValue
@GwtIncompatible("java.util.regex")
public static Splitter onPattern(String separatorPattern) 

Source Link

Document

Returns a splitter that considers any subsequence matching a given pattern (regular expression) to be a separator.

Usage

From source file:org.basinmc.maven.plugins.minecraft.patch.AbstractGitCommandMojo.java

/**
 * Executes a command as specified by the supplied process builder.
 *///from  w w w  .  j av  a 2  s .c  o  m
protected int execute(@Nonnull ProcessBuilder builder) throws IOException, InterruptedException {
    final Process process = builder.start();

    if (process.waitFor() != 0) {
        try (InputStream errorStream = process.getErrorStream()) {
            Splitter.onPattern("\r?\n").omitEmptyStrings().split(IOUtil.toString(errorStream))
                    .forEach(this.getLog()::error);
        }
    }

    return process.exitValue();
}

From source file:de.ii.xtraplatform.feature.transformer.api.FeatureTypeMapping.java

private List<String> splitPath(String path) {
    Splitter splitter = path.contains("http://") ? Splitter.onPattern("\\/(?=http)") : Splitter.on("/");
    return splitter.omitEmptyStrings().splitToList(path);
}

From source file:com.byteatebit.nbserver.task.ReadDelimitedMessageTask.java

public ReadDelimitedMessageTask(ObjectBuilder builder) {
    this.byteBuffer = builder.byteBuffer;
    this.maxMessageSize = builder.maxMessageSize;
    this.charset = builder.charset;
    this.splitter = Splitter.onPattern(builder.delimiter);
    this.messageBuffer = new ByteArrayOutputStream(byteBuffer.capacity());
}

From source file:org.asoem.greyfish.utils.math.ImmutableMarkovChain.java

public static ImmutableMarkovChain<String> parse(final String rule) {
    final ChainBuilder<String> builder = builder();

    final Splitter splitter = Splitter.onPattern("\r?\n|;").trimResults();
    final Iterable<String> lines = splitter.split(rule);

    final Pattern pattern = Pattern.compile("^(.+)->(.+):(.+)$");
    for (final String line : lines) {
        if (line.isEmpty()) {
            continue;
        }/*from ww  w . ja  va 2  s  .co m*/
        final Matcher matcher = pattern.matcher(line);
        if (matcher.matches()) {
            final String state1 = matcher.group(1).trim();
            final String state2 = matcher.group(2).trim();
            final String p = matcher.group(3).trim();

            builder.put(state1, state2, Double.parseDouble(p));
        } else {
            throw new IllegalArgumentException("Rule has errors at " + line);
        }
    }

    return builder.build();
}

From source file:cherry.foundation.querydsl.CustomizingConfigurationFactoryBean.java

@Override
public void afterPropertiesSet() throws Exception {
    if (listeners != null) {
        for (SQLListener l : listeners) {
            configuration.addListener(l);
        }// ww w .j a  va2 s . co m
    }
    if (customTypes != null) {
        for (Type<?> t : customTypes) {
            configuration.register(t);
        }
    }
    if (numericTypeSpecs != null) {
        for (String spec : numericTypeSpecs) {
            List<String> l = Splitter.onPattern(",").trimResults().splitToList(spec);
            if (l.size() != 3) {
                throw new IllegalArgumentException(
                        "numericTypeSpecs must be \"{total},{decimal},{javaType}\" or \"{beginTotal}-{endTotal},{beginDecimal}-{endDecimal},{javaType}\"");
            }
            Pair<Integer, Integer> total = parsePair(l.get(0));
            Pair<Integer, Integer> decimal = parsePair(l.get(1));
            configuration.registerNumeric(total.getLeft(), total.getRight(), decimal.getLeft(),
                    decimal.getRight(), Class.forName(l.get(2)));
        }
    }
}

From source file:org.apache.james.transport.matchers.RecipientDomainIs.java

@VisibleForTesting
Collection<Domain> parseDomainsList(String condition) {
    return Splitter.onPattern("(, |,| )").omitEmptyStrings().splitToList(condition).stream().map(Domain::of)
            .collect(ImmutableList.toImmutableList());
}

From source file:org.apache.james.transport.matchers.SenderHostIs.java

@VisibleForTesting
Collection<String> parseDomainsList(String condition) {
    return ImmutableSet.copyOf(Splitter.onPattern("(, |,| )").omitEmptyStrings().split(condition));
}

From source file:com.netflix.config.DynamicListProperty.java

/**
 * Create the dynamic list property. The guava Splitter used is created as
 * <code>Splitter.onPattern(delimiterRegex).omitEmptyStrings().trimResults()</code>. The default
 * list value will be transformed from list of strings after splitting. If defaultValue string is
 * null, the default list value will be an empty list.
 *//*w  ww.j  av a  2 s .  c  o  m*/
public DynamicListProperty(String propName, String defaultValue, String delimiterRegex) {
    this.splitter = Splitter.onPattern(delimiterRegex).omitEmptyStrings().trimResults();
    setup(propName, transform(split(defaultValue)), splitter);
}

From source file:com.google.jenkins.plugins.manage.TemplatedCloudDeployment.java

/**
 * Converts a comma-separated list of strings into a list of strings.
 *
 * @param commaSeparated a comma-separated string
 * @return a list of strings corresponding to the input comma-separated string
 *//*  ww w.ja v a  2  s.  co  m*/
static Iterable<String> commaSeparatedToList(String commaSeparated) {
    if (commaSeparated.matches("\\s*")) {
        return new ArrayList<String>();
    }
    return Splitter.onPattern("\\s*,\\s*").split(commaSeparated);
}

From source file:com.mattc.argus2.io.ListFile.java

@Override
public void load(File file) {
    StringWriter writer = null;/*  w  ww  . ja v  a  2  s  .  c o  m*/
    FileReader reader = null;

    try {
        final Splitter splitter = Splitter.onPattern("\r?\n").omitEmptyStrings().trimResults();
        String result = null;
        final char[] buf = new char[1024];
        writer = new StringWriter();
        reader = new FileReader(file);

        for (int c = reader.read(buf); c != -1; c = reader.read(buf)) {
            writer.write(buf, 0, c);
        }

        // Assemble defaults
        result = writer.toString();
        this.defaults.clear();

        // Ensure that Comments are not included.
        for (final String s : splitter.split(result)) {
            if (!s.startsWith("#")) {
                this.defaults.add(s);
            }
        }
        // --

    } catch (final IOException e) {
        Console.exception(e);
    } finally {
        IOUtils.closeSilently(writer);
        IOUtils.closeSilently(reader);
    }

    this.items.addAll(this.defaults);
    Configs.ensureFilesExist(this);
}