Example usage for java.util StringJoiner add

List of usage examples for java.util StringJoiner add

Introduction

In this page you can find the example usage for java.util StringJoiner add.

Prototype

public StringJoiner add(CharSequence newElement) 

Source Link

Document

Adds a copy of the given CharSequence value as the next element of the StringJoiner value.

Usage

From source file:com.github.wxiaoqi.gate.ratelimit.filters.RateLimitFilter.java

private String key(final HttpServletRequest request, final List<Type> types) {
    final Route route = route();
    final StringJoiner joiner = new StringJoiner(":");
    joiner.add(properties.getKeyPrefix());
    joiner.add(route.getId());/*from ww  w.ja  v  a 2 s .c  om*/
    if (!types.isEmpty()) {
        if (types.contains(Type.URL)) {
            joiner.add(route.getPath());
        }
        if (types.contains(Type.ORIGIN)) {
            joiner.add(getRemoteAddr(request));
        }
        if (types.contains(Type.USER)) {
            joiner.add(
                    userPrincipal.getName(request) != null ? userPrincipal.getName(request) : ANONYMOUS_USER);
        }
    }
    return joiner.toString();
}

From source file:it.polimi.diceH2020.SPACE4Cloud.shared.solution.Solution.java

public String toStringReduced() {
    StringJoiner sj = new StringJoiner("\t", "", "");
    sj.add("solID=" + id).add("solFeas=" + this.isFeasible().toString())
            .add("cost=" + BigDecimal.valueOf(this.getCost()).toString());
    sj.add("totalDuration=" + this.getOptimizationTime().toString());
    lstPhases.forEach(ph -> sj.add("phase=" + ph.getId().toString()).add("duration=" + ph.getDuration()));
    lstSolutions.forEach(s -> sj.add("jobClass=" + s.getId()).add("typeVM=" + s.getTypeVMselected().getId())
            .add("numVM=" + s.getNumberVM()).add("numReserved=" + s.getNumReservedVM())
            .add("numOnDemand=" + s.getNumOnDemandVM()).add("numSpot=" + s.getNumSpotVM())
            .add("jobFeas=" + s.getFeasible().toString()));
    return sj.toString();
}

From source file:org.rippleosi.search.patient.stats.search.PatientStatsQueryStrategy.java

@Override
public Object getRequestBody() {
    OpenEHRPatientStatsRequestBody body = new OpenEHRPatientStatsRequestBody();

    // create a CSV list of NHS Numbers for OpenEHR to query associated data
    StringJoiner csvBuilder = new StringJoiner(",");

    for (PatientSummary patient : patientSummaries) {
        csvBuilder.add(patient.getNhsNumber());
    }//w ww  .  jav  a  2  s.c om

    body.setExternalIds(csvBuilder.toString());
    body.setExternalNamespace(externalNamespace);
    return body;
}

From source file:com.cotrino.knowledgemap.db.Question.java

public String getExpectedAnswer() {

    StringJoiner sj = new StringJoiner(", ");
    for (String answer : answers) {
        sj.add("'" + answer + "'");
    }/*from   w w  w  . j a va2 s  .c om*/
    return sj.toString();

}

From source file:com.github.danzx.zekke.ws.rest.patch.jsonpatch.JsonObjectPatchTest.java

private String jsonPatchStr(StringBuilder... operations) {
    StringJoiner joiner = new StringJoiner(",", "[", "]");
    for (StringBuilder opt : operations)
        joiner.add(opt);
    return joiner.toString();
}

From source file:com.sri.ai.praise.sgsolver.solver.HOGMQueryError.java

@Override
public String toString() {
    StringJoiner sj = new StringJoiner("");

    if (context == Context.UNKNOWN) {
        sj.add("General Error: ");
    } else if (context == Context.QUERY) {
        sj.add("Error in Query ");
    } else if (context == Context.MODEL) {
        sj.add("Error in Model ");
    }//www  .jav a2s  . com

    if (context != Context.UNKNOWN) {
        sj.add("at Line " + line + ": ");
    }
    sj.add(errorMessage);

    if (throwable != null) {
        sj.add("\n");
        sj.add(ExceptionUtils.getStackTrace(throwable));
    }

    return sj.toString();
}

From source file:org.fcrepo.client.GetBuilder.java

private String buildPrefer(final String prefer, final List<URI> includeUris, final List<URI> omitUris) {
    final StringJoiner preferJoin = new StringJoiner("; ");
    preferJoin.add("return=" + prefer);

    if (includeUris != null) {
        final String include = includeUris.stream().map(URI::toString).collect(Collectors.joining(" "));
        if (include.length() > 0) {
            preferJoin.add("include=\"" + include + "\"");
        }/*  w  w w .  j  av a2 s.com*/
    }

    if (omitUris != null) {
        final String omit = omitUris.stream().map(URI::toString).collect(Collectors.joining(" "));
        if (omit.length() > 0) {
            preferJoin.add("omit=\"" + omit + "\"");
        }
    }

    return preferJoin.toString();
}

From source file:com.teradata.benchto.driver.execution.QueryExecutionDriver.java

private void logRow(int rowNumber, ResultSet resultSet) throws SQLException {
    ResultSetMetaData resultSetMetaData = resultSet.getMetaData();
    StringJoiner joiner = new StringJoiner("; ", "[", "]");
    for (int i = 1; i <= resultSetMetaData.getColumnCount(); ++i) {
        joiner.add(resultSetMetaData.getColumnName(i) + ": " + resultSet.getObject(i));
    }/* w w  w .ja  va  2 s .co m*/

    LOG.info("Row: " + rowNumber + ", column values: " + joiner.toString());
}

From source file:io.mapzone.arena.share.content.ArenaContentProvider.java

@Override
public ArenaContent get() {
    StringJoiner layers = new StringJoiner(",");
    for (SelectionDescriptor selection : context.selectionDescriptors.get()) {
        layers.add(selection.layer.get().label.get());
        // FIXME, if multilayers are working, remove this break!!!
        break;/*  w ww  .j a  va2 s  .c  om*/
    }

    Envelope envelope = context.boundingBox.get();
    StringJoiner extent = new StringJoiner(",");
    extent.add(String.valueOf((int) envelope.getMinX()));
    extent.add(String.valueOf((int) envelope.getMinY()));
    extent.add(String.valueOf((int) envelope.getMaxX()));
    extent.add(String.valueOf((int) envelope.getMaxY()));

    StringBuffer shareInfo = new StringBuffer(ArenaPlugin.instance().config().getProxyUrl());
    shareInfo.append(ShareServletsStarter.ALIAS_SHAREINFO).append("?");
    try {
        shareInfo.append(ShareInfoServlet.PARAMETER_LAYERS).append("=")
                .append(URLEncoder.encode(layers.toString(), "utf-8"));
        shareInfo.append("&").append(ShareInfoServlet.PARAMETER_BBOX).append("=")
                .append(URLEncoder.encode(extent.toString(), "utf-8"));
        if (!StringUtils.isBlank(ArenaPlugin.instance().config().getServiceAuthToken())) {
            shareInfo.append("&").append(ShareInfoServlet.PARAMETER_AUTHTOKEN).append("=")
                    .append(URLEncoder.encode(ArenaPlugin.instance().config().getServiceAuthToken(), "utf-8"));
        }
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException(e);
    }

    ArenaContent content = new ArenaContent();
    content.arena = ArenaPlugin.instance().config().getProxyUrl() + ArenaPlugin.ALIAS;
    content.shareInfo = shareInfo.toString();
    return content;
}

From source file:org.jhk.pulsing.sandbox.timeline.cli.CommandCli.java

private void processCommandLine(String command) {
    try {/*from  w  w  w  .  j  a  va  2s.  c  o  m*/
        // only support 3 args max
        String[] split = command.split(" ");
        if (split.length > 2) {
            // hacky for now...
            String[] temp = new String[3];
            temp[0] = split[0];
            temp[1] = split[1];

            StringJoiner joiner = new StringJoiner(" ");
            for (int loop = 2; loop < split.length; loop++) {
                joiner.add(split[loop]); // seriously why doesn't StringJoiner accept a List or Array...
            }
            temp[2] = joiner.toString();
            split = temp;
        }
        CommandLine commandLine = cliParser.parse(cliOptions, split);
        if (commandLine.hasOption("help")) {
            cliFormatter.printHelp("timeline", cliOptions);
        } else if (commandLine.hasOption("getTimeline")) {
            long timeLineId = Long.valueOf(commandLine.getOptionValue("getTimeline"));
            Optional<List<String>> tweets = timeLine.getTweets(timeLineId);

            if (tweets.isPresent()) {
                LOGGER.info("Tweets => {}", tweets.get());
            } else {
                LOGGER.info("Unable to retrieve tweets with id => {}", timeLineId);
            }

        } else if (commandLine.hasOption("tweet")) {
            String tweet = commandLine.getOptionValue("tweet");
            queue.publish(tweet);
        } else if (commandLine.hasOption("getUser")) {
            long userId = Long.valueOf(commandLine.getOptionValue("getUser"));
            Optional<User> user = userCache.getUser(userId);

            if (user.isPresent()) {
                LOGGER.info("Retrieved user => {}", user.get());
            } else {
                LOGGER.info("Unable to retrieve user with id => {}", userId);
            }
        } else if (commandLine.hasOption("getFollowers")) {
            long userId = Long.valueOf(commandLine.getOptionValue("getFollowers"));
            String userScreeNames = userCache.getFollowers(userId).stream().map(user -> user.getScreenName())
                    .collect(Collectors.joining(","));

            LOGGER.info("Retrieved followers => {}", userScreeNames);
        }

    } catch (Exception exp) {
        LOGGER.error(exp.getMessage(), exp);
    }
}