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:org.jclouds.compute.util.AutomaticHardwareIdSpec.java

public static AutomaticHardwareIdSpec parseId(String hardwareId) {
    AutomaticHardwareIdSpec spec = new AutomaticHardwareIdSpec();
    String hardwareSpec = hardwareId.substring(10);
    Map<String, String> specValues = Splitter.on(';').trimResults().omitEmptyStrings()
            .withKeyValueSeparator('=').split(hardwareSpec);
    if (!specValues.containsKey("ram") || !specValues.containsKey("cores")) {
        throw new IllegalArgumentException(String.format(
                "Omitted keys on hardwareId: %s. Please set number " + "of cores and ram amount.", hardwareId));
    }/*w w  w  .  j a  va  2  s . c o m*/
    if (specValues.containsKey("disk")) {
        float disk = Float.parseFloat(specValues.get("disk"));
        if (disk > 0.0f) {
            spec.disk = Optional.of(disk);
        } else {
            throw new IllegalArgumentException(String.format("Invalid disk value: %s", hardwareId));
        }
    }
    spec.ram = Integer.parseInt(specValues.get("ram"));
    spec.cores = Double.parseDouble(specValues.get("cores"));
    return spec;
}

From source file:org.dllearner.algorithms.qtl.experiments.BenchmarkDescriptionGeneratorHTML.java

public static void main(String[] args) throws Exception {
    OptionParser parser = new OptionParser();
    OptionSpec<File> benchmarkDirectorySpec = parser.accepts("d", "base directory").withRequiredArg()
            .ofType(File.class).required();
    OptionSpec<File> queriesFileSpec = parser.accepts("i", "input queries file").withRequiredArg()
            .ofType(File.class).required();
    OptionSpec<File> outputFileSpec = parser.accepts("o", "target output file").withRequiredArg()
            .ofType(File.class).required();
    OptionSpec<URL> endpointURLSpec = parser.accepts("e", "endpoint URL").withRequiredArg().ofType(URL.class)
            .required();// w  ww  .j ava  2 s .  c o m
    OptionSpec<String> defaultGraphSpec = parser.accepts("g", "default graph").withRequiredArg()
            .ofType(String.class);
    OptionSpec<Boolean> useCacheSpec = parser.accepts("cache", "use cache").withOptionalArg()
            .ofType(Boolean.class).defaultsTo(Boolean.TRUE);
    OptionSpec<Boolean> queriesHaveIdSpec = parser.accepts("id", "input file contains ID, SPARQL query")
            .withOptionalArg().ofType(Boolean.class).defaultsTo(Boolean.TRUE);
    OptionSpec<String> cbdSpec = parser.accepts("cbd", "CBD structure tree string").withRequiredArg()
            .ofType(String.class).required();
    OptionSpec<String> queriesToOmitTokensSpec = parser
            .accepts("omitTokens",
                    "comma-separated list of tokens such that queries containing any of them will be omitted")
            .withRequiredArg().ofType(String.class).defaultsTo("");
    OptionSpec<Boolean> workaroundSpec = parser.accepts("workaround", "Virtuoso parse error workaround enabled")
            .withRequiredArg().ofType(Boolean.class).defaultsTo(Boolean.FALSE);

    OptionSet options = parser.parse(args);

    File benchmarkDirectory = options.valueOf(benchmarkDirectorySpec);
    File inputFile = options.valueOf(queriesFileSpec);
    File outputFile = options.valueOf(outputFileSpec);

    URL endpointURL = options.valueOf(endpointURLSpec);
    List<String> defaultGraphs = options.has(defaultGraphSpec)
            ? Lists.newArrayList(options.valueOf(defaultGraphSpec))
            : Collections.emptyList();
    SparqlEndpoint endpoint = SparqlEndpoint.create(endpointURL.toString(), defaultGraphs);

    //      SparqlEndpointKS ks = new SparqlEndpointKS(endpoint);
    //      ks.setUseCache(options.valueOf(useCacheSpec));
    //      ks.setCacheDir(benchmarkDirectory.getPath());
    //      ks.setQueryDelay(1000);
    //      ks.setRetryCount(0);
    //      ks.init();

    QueryExecutionFactory qef = buildQueryExecutionFactory(endpoint, options.valueOf(useCacheSpec),
            benchmarkDirectory.getPath(), TimeUnit.DAYS.toMillis(30), 0, 60);

    CBDStructureTree cbdStructureTree = CBDStructureTree.fromTreeString(options.valueOf(cbdSpec).trim());

    List<String> omitTokens = Splitter.on(",").omitEmptyStrings().trimResults()
            .splitToList(options.valueOf(queriesToOmitTokensSpec));

    BenchmarkDescriptionGeneratorHTML generator = new BenchmarkDescriptionGeneratorHTML(qef);
    generator.setDefaultCbdStructure(cbdStructureTree);
    generator.setSkipQueryTokens(omitTokens);
    generator.setEndpoint(endpoint);
    generator.setWorkaroundEnabled(options.valueOf(workaroundSpec));
    generator.generateBenchmarkDescription(inputFile, outputFile, options.valueOf(queriesHaveIdSpec));
}

From source file:com.github.steveash.jg2p.align.FilterWalkerDecorator.java

public static Set<Pair<String, String>> readFromFile(File file) throws IOException {
    Splitter splitter = Splitter.on('^').trimResults();
    List<String> lines = Files.readLines(file, Charsets.UTF_8);
    HashSet<Pair<String, String>> result = Sets.newHashSet();
    for (String line : lines) {
        if (isBlank(line)) {
            continue;
        }/*from  w  w w  . ja va 2  s  .  co  m*/
        Iterator<String> fields = splitter.split(line).iterator();
        String x = fields.next();
        String y = fields.next();
        result.add(Pair.of(x, y));
    }
    return result;
}

From source file:com.facebook.buck.rules.macros.StringWithMacrosUtils.java

/** @return a {@link StringWithMacros} object built with the given format strings and macros. */
public static StringWithMacros format(String format, MacroContainer... macros) {
    ImmutableList.Builder<Either<String, MacroContainer>> partsBuilder = ImmutableList.builder();

    List<String> stringParts = Splitter.on("%s").splitToList(format);
    Preconditions.checkState(stringParts.size() == macros.length + 1);

    if (!stringParts.get(0).isEmpty()) {
        partsBuilder.add(Either.ofLeft(stringParts.get(0)));
    }/*w  w  w .j  av a 2  s . co  m*/

    for (int i = 0; i < macros.length; i++) {
        partsBuilder.add(Either.ofRight(macros[i]));
        if (!stringParts.get(i + 1).isEmpty()) {
            partsBuilder.add(Either.ofLeft(stringParts.get(i + 1)));
        }
    }

    return StringWithMacros.of(partsBuilder.build());
}

From source file:com.google.errorprone.refaster.UClassIdent.java

@VisibleForTesting
public static UClassIdent create(String qualifiedName) {
    List<String> topLevelPath = new ArrayList<>();
    for (String component : Splitter.on('.').split(qualifiedName)) {
        topLevelPath.add(component);//from  w  ww .  jav a  2  s  . co  m
        if (Character.isUpperCase(component.charAt(0))) {
            break;
        }
    }
    return create(Joiner.on('.').join(topLevelPath), qualifiedName);
}

From source file:com.android.tools.idea.gradle.structure.navigation.Places.java

@NotNull
public static Place deserialize(@NotNull String text) {
    Place place = new Place();
    List<String> entries = Splitter.on('|').omitEmptyStrings().splitToList(text);
    for (String entry : entries) {
        List<String> path = Splitter.on('=').splitToList(entry);
        place.putPath(path.get(0), path.get(1));
    }//from w w w  . ja v  a2s . co m
    return place;
}

From source file:org.apache.drill.exec.store.openTSDB.Util.java

/**
 * Parse FROM parameters to Map representation
 *
 * @param rowData with this syntax (metric=warp.speed.test)
 * @return Map with params key: metric, value: warp.speed.test
 *///from   w ww  . j  av  a 2s  . com
public static Map<String, String> fromRowData(String rowData) {
    try {
        String fromRowData = rowData.replaceAll("[()]", "");
        return Splitter.on(",").trimResults().omitEmptyStrings().withKeyValueSeparator("=").split(fromRowData);
    } catch (IllegalArgumentException e) {
        throw UserException.validationError().message(String.format("Syntax error in the query %s", rowData))
                .build(log);
    }
}

From source file:foo.domaintest.util.QueryStringHelper.java

public static Multimap<String, String> parseQuery(String query) {
    ImmutableListMultimap.Builder<String, String> params = new ImmutableListMultimap.Builder<>();
    for (String piece : Splitter.on('&').omitEmptyStrings().split(nullToEmpty(query))) {
        List<String> keyAndValue = Splitter.on('=').limit(2).splitToList(piece);
        try {/*from   w w  w . j  a v a2  s.c o m*/
            params.put(URLDecoder.decode(keyAndValue.get(0), UTF_8.name()),
                    URLDecoder.decode(Iterables.get(keyAndValue, 1, ""), UTF_8.name()));
        } catch (UnsupportedEncodingException e) {
            throw new AssertionError(e);
        }
    }
    return params.build();
}

From source file:org.apache.isis.security.shiro.util.Util.java

public static Map<String, List<String>> parse(String permissionsByRoleStr) {
    Map<String, List<String>> perms = Maps.newHashMap();
    for (String roleAndPermsStr : Splitter.on(";").split(permissionsByRoleStr)) {
        final Iterable<String> split = Splitter.on("=").split(roleAndPermsStr);
        final String[] roleAndPerms = Iterables.toArray(split, String.class);
        if (roleAndPerms.length != 2) {
            continue;
        }/*from w w  w.  j  a  va  2 s  .c o  m*/
        final String role = roleAndPerms[0].trim();
        final String permStr = roleAndPerms[1].trim();
        perms.put(role, Lists.newArrayList(Iterables.transform(Splitter.on(",").split(permStr), TRIM)));
    }
    return perms;
}

From source file:cpw.mods.fml.common.asm.transformers.DeobfuscationTransformer.java

private static List<String> getForcedPrefixes() {
    if (forcedPrefixes == null) {
        String prefixList = System.getProperty("fml.forcedDeobfuscationPrefixes");
        if (prefixList != null && FMLDeobfuscatingRemapper.INSTANCE.isDeobfuscationDataLoaded()) {
            forcedPrefixes = ImmutableList.copyOf(Splitter.on(';').split(prefixList));
            FMLRelaunchLog.fine("Prefixes selected for deobfuscation: " + prefixList);
        } else {/*ww  w  . ja  v a  2s  .  co m*/
            forcedPrefixes = ImmutableList.of();
        }
    }

    return forcedPrefixes;
}