Search in sources :

Example 76 with Splitter

use of com.google.common.base.Splitter in project gerrit by GerritCodeReview.

the class ChangeField method getDirectories.

public static Set<String> getDirectories(ChangeData cd) {
    List<String> paths = cd.currentFilePaths();
    Splitter s = Splitter.on('/').omitEmptyStrings();
    Set<String> r = new HashSet<>();
    for (String path : paths) {
        StringBuilder directory = new StringBuilder();
        r.add(directory.toString());
        String nextPart = null;
        for (String part : s.split(path.toLowerCase(Locale.US))) {
            if (nextPart != null) {
                r.add(nextPart);
                if (directory.length() > 0) {
                    directory.append("/");
                }
                directory.append(nextPart);
                String intermediateDir = directory.toString();
                int i = intermediateDir.indexOf('/');
                while (i >= 0) {
                    r.add(intermediateDir);
                    intermediateDir = intermediateDir.substring(i + 1);
                    i = intermediateDir.indexOf('/');
                }
            }
            nextPart = part;
        }
    }
    return r;
}
Also used : Splitter(com.google.common.base.Splitter) HashSet(java.util.HashSet)

Example 77 with Splitter

use of com.google.common.base.Splitter in project gerrit by GerritCodeReview.

the class SchemaUtil method getNameParts.

public static Set<String> getNameParts(String name, Iterable<String> emails) {
    Splitter at = Splitter.on('@');
    Splitter s = Splitter.on(CharMatcher.anyOf("@.- /_")).omitEmptyStrings();
    HashSet<String> parts = new HashSet<>();
    for (String email : emails) {
        if (email == null) {
            continue;
        }
        String lowerEmail = email.toLowerCase(Locale.US);
        parts.add(lowerEmail);
        Iterables.addAll(parts, at.split(lowerEmail));
        Iterables.addAll(parts, s.split(lowerEmail));
    }
    if (name != null) {
        Iterables.addAll(parts, s.split(name.toLowerCase(Locale.US)));
    }
    return parts;
}
Also used : Splitter(com.google.common.base.Splitter) HashSet(java.util.HashSet)

Example 78 with Splitter

use of com.google.common.base.Splitter in project gerrit by GerritCodeReview.

the class ChangeEmail method getDiffTemplateData.

/**
 * Generate a list of maps representing each line of the unified diff. The line maps will have a
 * 'type' key which maps to one of 'common', 'add' or 'remove' and a 'text' key which maps to the
 * line's content.
 *
 * @param sourceDiff the unified diff that we're converting to the map.
 * @return map of 'type' to a line's content.
 */
protected static ImmutableList<ImmutableMap<String, String>> getDiffTemplateData(String sourceDiff) {
    ImmutableList.Builder<ImmutableMap<String, String>> result = ImmutableList.builder();
    Splitter lineSplitter = Splitter.on(System.getProperty("line.separator"));
    for (String diffLine : lineSplitter.split(sourceDiff)) {
        ImmutableMap.Builder<String, String> lineData = ImmutableMap.builder();
        lineData.put("text", diffLine);
        // Skip empty lines and lines that look like diff headers.
        if (diffLine.isEmpty() || diffLine.startsWith("---") || diffLine.startsWith("+++")) {
            lineData.put("type", "common");
        } else {
            switch(diffLine.charAt(0)) {
                case '+':
                    lineData.put("type", "add");
                    break;
                case '-':
                    lineData.put("type", "remove");
                    break;
                default:
                    lineData.put("type", "common");
                    break;
            }
        }
        result.add(lineData.build());
    }
    return result.build();
}
Also used : Splitter(com.google.common.base.Splitter) ImmutableList(com.google.common.collect.ImmutableList) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 79 with Splitter

use of com.google.common.base.Splitter in project unleash-maven-plugin by shillner.

the class AbstractUnleashMojo method getReleaseArgs.

@MojoProduces
@Named("releaseArgs")
@MojoInject
private Properties getReleaseArgs(Log log) {
    Properties args = new Properties();
    Splitter splitter = Splitter.on('=');
    for (String arg : this.releaseArgs) {
        List<String> split = splitter.splitToList(arg);
        if (split.size() == 2) {
            args.put(split.get(0), split.get(1));
        } else {
            log.warn("Could not set '" + arg + "' as a Property for the Maven release build.");
        }
    }
    // Add default property indicating that the unleash plugin is triggering the build
    args.put("isUnleashBuild", "true");
    return args;
}
Also used : Splitter(com.google.common.base.Splitter) Properties(java.util.Properties) Named(javax.inject.Named) MojoProduces(com.itemis.maven.plugins.cdi.annotations.MojoProduces) MojoInject(com.itemis.maven.plugins.cdi.annotations.MojoInject)

Example 80 with Splitter

use of com.google.common.base.Splitter in project graylog2-server by Graylog2.

the class KeyValue method evaluate.

@Override
public Map<String, String> evaluate(FunctionArgs args, EvaluationContext context) {
    final String value = valueParam.required(args, context);
    if (Strings.isNullOrEmpty(value)) {
        return null;
    }
    final CharMatcher kvPairsMatcher = splitParam.optional(args, context).orElse(CharMatcher.whitespace());
    final CharMatcher kvDelimMatcher = valueSplitParam.optional(args, context).orElse(CharMatcher.anyOf("="));
    Splitter outerSplitter = Splitter.on(DelimiterCharMatcher.withQuoteHandling(kvPairsMatcher)).omitEmptyStrings().trimResults();
    final Splitter entrySplitter = Splitter.on(kvDelimMatcher).omitEmptyStrings().limit(2).trimResults();
    return new MapSplitter(outerSplitter, entrySplitter, ignoreEmptyValuesParam.optional(args, context).orElse(true), trimCharactersParam.optional(args, context).orElse(CharMatcher.none()), trimValueCharactersParam.optional(args, context).orElse(CharMatcher.none()), allowDupeKeysParam.optional(args, context).orElse(true), duplicateHandlingParam.optional(args, context).orElse("take_first")).split(value);
}
Also used : Splitter(com.google.common.base.Splitter) CharMatcher(com.google.common.base.CharMatcher)

Aggregations

Splitter (com.google.common.base.Splitter)86 ArrayList (java.util.ArrayList)19 IOException (java.io.IOException)12 HashSet (java.util.HashSet)10 File (java.io.File)7 HashMap (java.util.HashMap)7 Test (org.junit.Test)5 BufferedReader (java.io.BufferedReader)4 NonNull (com.android.annotations.NonNull)3 URI (java.net.URI)3 URL (java.net.URL)3 ItemStack (net.minecraft.item.ItemStack)3 StringColumn (tech.tablesaw.api.StringColumn)3 CharMatcher (com.google.common.base.CharMatcher)2 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 CharSource (com.google.common.io.CharSource)2 BufferedOutputStream (java.io.BufferedOutputStream)2 FileInputStream (java.io.FileInputStream)2 InputStreamReader (java.io.InputStreamReader)2