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.ksa.myanmarlottery.util.PropertySplitter.java

private Map<String, String> map(String property, String splitter) {
    return Splitter.on(splitter).omitEmptyStrings().trimResults().withKeyValueSeparator(":").split(property);
}

From source file:io.prestosql.plugin.ml.LibSvmUtils.java

public static svm_parameter parseParameters(String paramString) {
    svm_parameter params = new svm_parameter();
    params.kernel_type = svm_parameter.LINEAR;
    params.degree = 3;//  ww w  .j  a  v a  2s.c o m
    params.gamma = 0;
    params.coef0 = 0;
    params.nu = 0.5;
    params.cache_size = 100;
    params.C = 1;
    params.eps = 0.1;
    params.p = 0.1;
    params.shrinking = 1;
    params.probability = 0;
    params.nr_weight = 0;
    params.weight_label = new int[0];
    params.weight = new double[0];

    for (String split : Splitter.on(',').omitEmptyStrings().split(paramString)) {
        String[] pair = split.split("=");
        checkArgument(pair.length == 2, "Invalid hyperparameters string for libsvm");
        String value = pair[1].trim();

        String key = pair[0].trim();
        switch (key) {
        case "kernel":
            params.kernel_type = parseKernelType(value);
            break;
        case "degree":
            params.degree = Integer.parseInt(value);
            break;
        case "gamma":
            params.gamma = Double.parseDouble(value);
            break;
        case "coef0":
            params.coef0 = Double.parseDouble(value);
            break;
        case "C":
            params.C = Double.parseDouble(value);
            break;
        case "nu":
            params.nu = Double.parseDouble(value);
            break;
        case "eps":
            params.eps = Double.parseDouble(value);
            break;
        default:
            throw new PrestoException(INVALID_FUNCTION_ARGUMENT, format("Unknown parameter %s", pair[0]));
        }
    }

    return params;
}

From source file:monasca.api.infrastructure.persistence.DimensionQueries.java

public static void bindDimensionsToQuery(Query<?> query, Map<String, String> dimensions) {

    if (dimensions != null) {
        int i = 0;
        for (Iterator<Map.Entry<String, String>> it = dimensions.entrySet().iterator(); it.hasNext(); i++) {
            Map.Entry<String, String> entry = it.next();
            query.bind("dname" + i, entry.getKey());
            if (!Strings.isNullOrEmpty(entry.getValue())) {
                List<String> values = Splitter.on('|').splitToList(entry.getValue());
                int j = 0;
                for (String value : values) {
                    query.bind("dvalue" + i + '_' + j, value);
                    j++;/*from  w w  w.j a  va  2  s . c  o m*/
                }
            }
        }
    }
}

From source file:com.google.api.codegen.util.php.PhpRenderingUtil.java

/**
 * Splits given text into lines and returns an list of strings, each one representing a line.
 * Performs escaping of '@' and '*' characters.
 *///from   w  w  w.j  a  v  a 2s.c o m
public static List<String> getDocLines(String text) {
    List<String> result = new ArrayList<>();
    text = PHP_ESCAPER.escape(text);
    for (String line : Splitter.on(String.format("%n")).split(text)) {
        result.add(line);
    }
    return result;
}

From source file:org.robotframework.ide.eclipse.main.plugin.project.library.ArgumentsDescriptor.java

public static ArgumentsDescriptor createDescriptor(final List<String> args) {
    if (args == null) {
        return new ArgumentsDescriptor(Lists.<Argument>newArrayList());
    }//from  w  w  w  .  j  a  v  a2 s . c  o m

    final List<Argument> arguments = newArrayList();
    for (final String arg : args) {
        if (arg.contains("=")) {
            final List<String> splitted = Splitter.on("=").splitToList(arg);
            arguments.add(new Argument(ArgumentType.DEFAULT, splitted.get(0), splitted.get(1)));
        } else if (arg.startsWith("**")) {
            arguments.add(new Argument(ArgumentType.KWARG, arg.substring(2)));
        } else if (arg.startsWith("*")) {
            arguments.add(new Argument(ArgumentType.VARARG, arg.substring(1)));
        } else {
            arguments.add(new Argument(ArgumentType.REQUIRED, arg));
        }
    }
    return new ArgumentsDescriptor(arguments);
}

From source file:com.dangdang.ddframe.rdb.sharding.api.rule.DataNode.java

/**
 * ????./* w  w w .ja v  a2s .c o  m*/
 * 
 * @param dataNodeStr 
 * @return ????
 */
public static boolean isValidDataNode(final String dataNodeStr) {
    return dataNodeStr.contains(DELIMITER) && 2 == Splitter.on(DELIMITER).splitToList(dataNodeStr).size();
}

From source file:co.cask.cdap.logging.gateway.handlers.FormattedLogEvent.java

public static LogOffset parseLogOffset(String offsetStr) {
    if (offsetStr.isEmpty()) {
        return LogOffset.LATEST_OFFSET;
    }//from   w w w  . j  a v  a2  s  . c o m

    Iterable<String> splits = Splitter.on(SEPARATOR).split(offsetStr);
    Preconditions.checkArgument(Iterables.size(splits) == 2, "Invalid offset provided: %s", offsetStr);

    return new LogOffset(Long.valueOf(Iterables.get(splits, 0)), Long.valueOf(Iterables.get(splits, 1)));
}

From source file:com.palantir.typescript.services.language.ScriptElementModifierKind.java

public static ImmutableList<ScriptElementModifierKind> parseList(String kindModifiers) {
    ImmutableList.Builder<ScriptElementModifierKind> kindModifiersBuilder = ImmutableList.builder();

    if (kindModifiers.length() > 0) {
        for (String kindModifier : Splitter.on(',').split(kindModifiers)) {
            kindModifiersBuilder.add(fromString(kindModifier));
        }//from  w w  w . j av  a  2s. c  o  m
    }

    return kindModifiersBuilder.build();
}

From source file:org.glowroot.storage.repo.helper.Gauges.java

public static String display(String mbeanObjectName) {
    // e.g. java.lang:name=PS Eden Space,type=MemoryPool
    List<String> parts = Splitter.on(CharMatcher.anyOf(":,")).splitToList(mbeanObjectName);
    StringBuilder name = new StringBuilder();
    name.append(parts.get(0));//from  ww  w  .  j  a v  a  2s . c  o m
    for (int i = 1; i < parts.size(); i++) {
        name.append('/');
        name.append(parts.get(i).split("=")[1]);
    }
    return name.toString();
}

From source file:org.dcache.macaroons.CaveatValues.java

public static void parseIdentityCaveatValue(MacaroonContext context, String value)
        throws InvalidCaveatException {
    List<String> idElements = Splitter.on(';').limit(3).splitToList(value);
    checkCaveat(idElements.size() == 3, "Missing elements");

    try {// w  w w . j  a v  a  2s  . c  om
        context.setUid(Long.valueOf(idElements.get(0)));
    } catch (NumberFormatException e) {
        throw InvalidCaveatException.wrap("Badly formatted uid", e);
    }

    List<String> gids = Splitter.on(',').splitToList(idElements.get(1));
    try {
        context.setGids(gids.stream().mapToLong(Long::valueOf).toArray());
    } catch (NumberFormatException e) {
        throw InvalidCaveatException.wrap("Badly formatted gid", e);
    }

    String username = idElements.get(2).trim();
    checkCaveat(!username.isEmpty(), "empty username not allowed");

    context.setUsername(username);
}