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.wso2.siddhi.debs2016.graph.GraphAnalyzer.java

/**
 * Displays the friendship graph/*from  w w w . java  2 s . c o  m*/
 *
 * @param displayWhileLoading true will display while stream is processing
 * @param numberOfEventsToLoad will limit the number of events to load
 * @param updateRate speed at which graph grows
 */
private void loadFriendshipGraph(boolean displayWhileLoading, int numberOfEventsToLoad, int updateRate) {

    if (displayWhileLoading) {
        graph.display();
    }

    int count = 0;

    try {
        Splitter splitter = Splitter.on('|');
        BufferedReader br = new BufferedReader(
                new FileReader("/Users/malithjayasinghe/debs2016/DataSet/data" + "/friendships.dat"),
                10 * 1024 * 1024);
        String line = br.readLine();
        while (line != null) {
            Iterator<String> dataStrIterator = splitter.split(line).iterator();
            Long user1ID = Long.parseLong(dataStrIterator.next());
            Long user2ID = Long.parseLong(dataStrIterator.next());

            if (updateRate > 0) {
                try {
                    Thread.sleep(updateRate);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }

            addEdge(user1ID, user2ID);
            line = br.readLine();
            count++;

            if (count == numberOfEventsToLoad) {
                break;
            }

        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:org.sonar.batch.scan.LastLineHashes.java

public String[] getLineHashes(String fileKey) {
    String hashesFromWs = loadHashesFromWs(fileKey);
    return Iterators.toArray(Splitter.on('\n').split(hashesFromWs).iterator(), String.class);
}

From source file:org.usergrid.utils.TimeUtils.java

/**
 * Jira-style duration parser. Supported duration strings are:
 * <ul>//from  ww w .  j  a  va  2s  . c o  m
 *   <li>'S': milliseconds</li>
 *   <li>'s': seconds</li>
 *   <li>'m': minutes</li>
 *   <li>'h': hours</li>
 *   <li>'d': days</li>
 * </ul>
 *
 * Durations can be compound statements in any order as long as they are
 * separated by a ',' (comma). Eg. "1d,14h,3s" to get the millisecond
 * equivalent of one day, fourteen hours and 3 seconds.
 *
 * Numbers with no durations will be treated as raw millisecond values
 *
 * @param durationStr
 * @return the number of milliseconds representing the duration
 */
public static long millisFromDuration(String durationStr) {
    long total = 0;
    MultiplierToken mt;
    long dur;
    for (String val : Splitter.on(',').trimResults().omitEmptyStrings().split(durationStr)) {
        dur = Long.parseLong(CharMatcher.DIGIT.retainFrom(val));
        mt = MultiplierToken.from(val.charAt(val.length() - 1));
        total += (mt.multiplier * dur);
    }
    return total;
}

From source file:com.google.testing.security.firingrange.tests.reflected.Substrings.java

@Override
public void service(HttpServletRequest request, HttpServletResponse response) throws IOException {
    String echoedParam = Strings.nullToEmpty(request.getParameter(ECHOED_PARAM));
    String template = Templates.getTemplate(request, getClass());
    String restrictionModifier = Splitter.on('/').splitToList(request.getPathInfo()).get(2);
    String restrictedString = Splitter.on('/').splitToList(request.getPathInfo()).get(3);

    switch (restrictionModifier) {
    case "caseSensitive":
        if (containsSubstrings(echoedParam, restrictedString)) {
            Responses.sendError(response, "Invalid param.", 400);
            return;
        }//from  w  w w. ja va 2  s  .  co  m
        break;
    case "caseInsensitive":
        if (containsSubstrings(echoedParam.toLowerCase(), restrictedString.toLowerCase())) {
            Responses.sendError(response, "Invalid param.", 400);
            return;
        }
        break;
    default:
        Responses.sendError(response, "Invalid restriction.", 400);
        return;
    }
    Responses.sendXssed(response, Templates.replacePayload(template, echoedParam));
}

From source file:com.google.testing.security.firingrange.tests.reflected.Charsets.java

@Override
public void service(HttpServletRequest request, HttpServletResponse response) throws IOException {
    String echoedParam = Strings.nullToEmpty(request.getParameter(ECHOED_PARAM));
    String template = Templates.getTemplate(request, getClass());
    String restrictedCharsets = Splitter.on('/').splitToList(request.getPathInfo()).get(2);
    switch (restrictedCharsets) {
    case "SpaceDoubleQuoteSlashEquals":
        if (containsChars(echoedParam, '=', '\\', '"', ' ')) {
            Responses.sendError(response, "Invalid param.", 400);
            return;
        }//ww  w  . jav a 2 s  . c  o  m
        break;
    case "DoubleQuoteSinglequote":
        if (containsChars(echoedParam, '"', '\'')) {
            Responses.sendError(response, "Invalid param.", 400);
            return;
        }
        break;
    default:
        Responses.sendError(response, "Invalid charset.", 400);
        return;
    }
    Responses.sendXssed(response, Templates.replacePayload(template, echoedParam));
}

From source file:org.apache.whirr.service.jclouds.TakeLoginCredentialsFromWhirrProperties.java

@Override
public Credentials execute(Object resourceToAuthenticate) {
    if (System.getProperties().containsKey("whirr.login-user")
            && !"".equals(System.getProperty("whirr.login-user").trim())) {
        List<String> creds = Lists.newArrayList(Splitter.on(':').split(System.getProperty("whirr.login-user")));
        if (creds.size() == 2)
            return new Credentials(creds.get(0), creds.get(1));
        return new Credentials(creds.get(0), null);
    } else {//from  w  w w.  j  a v a  2 s.c  o  m
        return super.execute(resourceToAuthenticate);
    }
}

From source file:ezbakehelpers.ezconfigurationhelpers.elasticsearch.ElasticsearchConfigurationHelper.java

/**
 * This helper will return a list containing all of the elasticsearch hostnames.
 * @return a list of elasticsearch hostnames
 *///w  w w .jav a  2  s  .  c  om
public List<String> getElasticsearchHosts() {
    List<String> hostNames;
    String hosts = getElasticsearchHost();
    if (hosts != null) {
        hostNames = Splitter.on(",").omitEmptyStrings().trimResults().splitToList(hosts);
    } else {
        hostNames = Collections.emptyList();
    }
    return hostNames;
}

From source file:com.facebook.presto.execution.QueryId.java

static List<String> parseDottedId(String id, int expectedParts, String name) {
    requireNonNull(id, "id is null");
    checkArgument(expectedParts > 0, "expectedParts must be at least 1");
    requireNonNull(name, "name is null");

    ImmutableList<String> ids = ImmutableList.copyOf(Splitter.on('.').split(id));
    checkArgument(ids.size() == expectedParts, "Invalid %s %s", name, id);

    for (String part : ids) {
        checkArgument(!part.isEmpty(), "Invalid id %s", id);
        checkArgument(ID_PATTERN.matcher(part).matches(), "Invalid id %s", id);
    }/*  ww  w . j ava2s.  com*/
    return ids;
}

From source file:annis.gui.exporter.TextExporter.java

@Override
public void convertText(AnnisResultSet queryResult, List<String> keys, Map<String, String> args, Writer out,
        int offset) throws IOException {

    Map<String, Map<String, Annotation>> metadataCache = new HashMap<>();

    List<String> metaKeys = new LinkedList<>();
    if (args.containsKey("metakeys")) {
        Iterable<String> it = Splitter.on(",").trimResults().split(args.get("metakeys"));
        for (String s : it) {
            metaKeys.add(s);/*from   w ww  .java2 s. c  o m*/
        }
    }

    int counter = 0;
    for (AnnisResult annisResult : queryResult) {
        Set<Long> matchedNodeIds = annisResult.getGraph().getMatchedNodeIds();

        counter++;
        out.append((counter + offset) + ". ");
        List<AnnisNode> tok = annisResult.getGraph().getTokens();

        for (AnnisNode annisNode : tok) {
            Long tokID = annisNode.getId();
            if (matchedNodeIds.contains(tokID)) {
                out.append("[");
                out.append(annisNode.getSpannedText());
                out.append("]");
            } else {
                out.append(annisNode.getSpannedText());
            }

            for (Annotation annotation : annisNode.getNodeAnnotations()) {
                out.append("/" + annotation.getValue());
            }

            out.append(" ");

        }
        out.append("\n");

        if (!metaKeys.isEmpty()) {
            String[] path = annisResult.getPath();
            super.appendMetaData(out, metaKeys, path[path.length - 1], annisResult.getDocumentName(),
                    metadataCache);
        }
        out.append("\n");
    }
}

From source file:com.google.javascript.jscomp.parsing.parser.util.SourcePosition.java

private String shortSourceName() {
    if (source == null) {
        return "";
    }//w w w .  j a  v a 2s . c  o m

    return Iterables.getLast(Splitter.on('/').split(source.name));
}