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:ru.codeinside.adm.parser.ServiceFixtureParser.java

public void loadFixtures(InputStream is, ServiceFixtureParser.PersistenceCallback callback) throws IOException {
    final Splitter propertySplitter = Splitter.on(':');
    final BufferedReader reader = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8")));
    String line;//from w  w  w . j  ava2  s  .  c o  m
    int lineNumber = 0;
    while ((line = reader.readLine()) != null) {
        lineNumber++;
        int level = startIndex(line);
        if (line.startsWith("#") || level < 0) {
            continue;
        }
        final ArrayList<String> props = Lists.newArrayList(propertySplitter.split(line.substring(level)));
        final String name = StringUtils.trimToNull(props.get(0)).replace("<br/>", "\n");
        if (name == null) {
            throw new IllegalStateException(" ?( ?:" + lineNumber + ")");
        }
        final Long regCode;
        try {
            regCode = Long.parseLong(props.get(1));
        } catch (NumberFormatException e) {
            throw new IllegalStateException(
                    "  ( ?:" + lineNumber + "): " + name);
        }
        final boolean isProc = level > 0;
        Row parent = getParentRow(level);
        if (!isProc) {
            long servId = callback.onServiceComplete(name, regCode);
            stack.addLast(new Row(level, servId));
        }
        if (isProc && parent != null) {
            callback.onProcedureComplete(name, regCode, parent.id);
        }
        if (isProc && parent == null) {
            throw new IllegalStateException(
                    "  ?( ?:" + lineNumber + "): " + name);
        }
    }
}

From source file:com.spotify.helios.common.PomVersion.java

public static PomVersion parse(final String s) {
    boolean isSnapshot = false;
    String version = s;/*from   w w w.  ja va  2  s  .c om*/
    if (s.endsWith("-SNAPSHOT")) {
        isSnapshot = true;
        version = version.substring(0, s.length() - 9);
    }

    final Iterable<String> bits = Splitter.on(".").split(version);
    if (size(bits) != 3) {
        throw new RuntimeException("Version string format is invalid");
    }
    try {
        final Integer newMajor = Integer.valueOf(get(bits, 0));
        final Integer newMinor = Integer.valueOf(get(bits, 1));
        final Integer newPatch = Integer.valueOf(get(bits, 2));
        return new PomVersion(isSnapshot, newMajor, newMinor, newPatch);
    } catch (NumberFormatException e) {
        throw new RuntimeException("Version portions are not numbers! " + s, e);
    }
}

From source file:com.google.api.codegen.go.GoContextCommon.java

/**
 * Converts the specified text into a comment block in the generated Go file.
 *//*www . ja va 2  s.  co  m*/
public Iterable<String> getCommentLines(String text) {
    List<String> result = new ArrayList<>();
    for (String line : Splitter.on(String.format("%n")).split(text)) {
        result.add(line.isEmpty() ? "//" : "// " + line);
    }
    return result;
}

From source file:com.facebook.presto.execution.resourceGroups.ResourceGroupIdTemplate.java

@JsonCreator
public ResourceGroupIdTemplate(String fullId) {
    List<String> segments = Splitter.on(".").splitToList(requireNonNull(fullId, "fullId is null"));
    checkArgument(!segments.isEmpty(), "Resource group id is empty");
    this.segments = segments.stream().map(ResourceGroupNameTemplate::new).collect(Collectors.toList());
}

From source file:io.scigraph.services.refine.RefineUtil.java

public static Vocabulary.Query getVocabularyQuery(RefineQuery refineQuery) {
    Vocabulary.Query.Builder builder = new Vocabulary.Query.Builder(refineQuery.getQuery());
    if (refineQuery.getLimit().isPresent()) {
        builder.limit(refineQuery.getLimit().get());
    }/*from   w  w  w.j  a  v a  2s.  c o  m*/
    if (refineQuery.getType().isPresent()) {
        builder.categories(Splitter.on(',').splitToList(refineQuery.getType().get()));
    }
    return builder.build();
}

From source file:org.locationtech.geogig.storage.postgresql.EnvironmentBuilder.java

private static Map<String, String> extractShortKeys(String rawQuery) {
    Map<String, String> shortKeys = new HashMap<>();
    for (String pair : Splitter.on('&').split(rawQuery)) {
        List<String> p = Splitter.on('=').splitToList(pair);
        // it should be the raw query, URL decode the values
        try {//w  ww  .ja va2s .c om
            shortKeys.put(p.get(0), URLDecoder.decode(p.get(1), StandardCharsets.UTF_8.name()));
        } catch (UnsupportedEncodingException uee) {
            Throwables.propagate(uee);
        }
    }
    return shortKeys;
}

From source file:com.orange.clara.tool.websocket.WebSocketOauthHandler.java

@Override
protected Principal determineUser(ServerHttpRequest request, WebSocketHandler wsHandler,
        Map<String, Object> attributes) {
    String query = request.getURI().toString().split("\\?")[1];
    final Map<String, String> params = Splitter.on('&').trimResults().withKeyValueSeparator("=").split(query);

    String token = "";
    if (params.get("token") != null) {
        token = params.get("token");
    }//  w  ww . j  av  a  2  s  . co m
    return (Principal) this.resourceServerTokenServices.loadAuthentication(token).getPrincipal();
}

From source file:io.v.impl.google.naming.EndpointImpl.java

public static Endpoint fromString(String s) {
    Matcher matcher = hostPortPattern.matcher(s);
    if (matcher.matches()) {
        List<String> blessings = new ArrayList<>(1);
        // If the endpoint does not end in a @, it must be in [blessing@]host:port format.
        HostAndPort hostPort = HostAndPort.fromString(matcher.group(matcher.groupCount()));
        if (matcher.group(1) != null) {
            blessings.add(matcher.group(1));
        }/*w ww  . ja v  a2s .c  om*/

        return new EndpointImpl("", hostPort.toString(), ImmutableList.<String>of(), RoutingId.NULL_ROUTING_ID,
                blessings, true, false);
    }

    if (s.endsWith("@@")) {
        s = s.substring(0, s.length() - 2);
    }
    if (s.startsWith("@")) {
        s = s.substring(1, s.length());
    }

    List<String> parts = Splitter.on('@').splitToList(s);
    int version = Integer.parseInt(parts.get(0));
    switch (version) {
    case 6:
        return fromV6String(parts);
    default:
        return null;
    }
}

From source file:org.jbpm.workbench.cm.client.util.CommaListValuesConverter.java

@Override
public List toModelValue(final String widgetValue) {
    if (isNullOrEmpty(widgetValue)) {
        return new ArrayList<String>();
    } else {//from  w w w .j  a  v  a  2  s  . c  o m
        return new ArrayList(Splitter.on(",").trimResults().omitEmptyStrings().splitToList(widgetValue));
    }
}

From source file:com.cloudera.exhibit.sql.SQLCalculator.java

public static SQLCalculator create(ObsDescriptor res, String sqlCode) {
    if (sqlCode == null) {
        return null;
    }// w ww. j a v  a  2 s.com
    List<String> ret = Lists.newArrayList();
    //TODO: sql comment filtering
    for (String q : Splitter.on(';').trimResults().omitEmptyStrings().split(sqlCode)) {
        ret.add(q);
    }
    SQLCalculator sc = new SQLCalculator(ret.toArray(new String[0]));
    return sc;
}