Example usage for java.util StringJoiner StringJoiner

List of usage examples for java.util StringJoiner StringJoiner

Introduction

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

Prototype

public StringJoiner(CharSequence delimiter, CharSequence prefix, CharSequence suffix) 

Source Link

Document

Constructs a StringJoiner with no characters in it using copies of the supplied prefix , delimiter and suffix .

Usage

From source file:Main.java

public static void main(String[] argv) {
    StringJoiner sj = new StringJoiner(":", "[", "]");
    sj.add("George").add("Sally").add("Fred");
    String desiredString = sj.toString();

    System.out.println(desiredString);
}

From source file:org.camunda.bpm.spring.boot.starter.property.CamundaBpmProperties.java

static StringJoiner joinOn(final Class<?> clazz) {
    return new StringJoiner(", ", clazz.getSimpleName() + "[", "]");
}

From source file:main.java.framework.java.measurement.MeasurementUtils.java

/**
 * Parses a {@link MethodTree} for it's id used in the database
 * @param tree/*from   w w w.j a v a  2s .  c  o  m*/
 * @return method's id in format classId->methodName(parameters)
 */
public static String getMethodID(MethodTree tree) {
    String name = tree.simpleName().name();
    StringJoiner methodDeclaration = new StringJoiner(",", name + "(", ")");
    tree.parameters().forEach(x -> methodDeclaration.add(x.simpleName().name()));
    return methodDeclaration.toString();
}

From source file:com.nike.cerberus.command.validator.UploadCertFilesPathValidator.java

@Override
public void validate(final String name, final Path value) throws ParameterException {

    if (value == null) {
        throw new ParameterException("Value must be specified.");
    }/*from  w ww .j a  v a 2 s  .c om*/

    final File certDirectory = value.toFile();
    final Set<String> filenames = Sets.newHashSet();

    if (!certDirectory.canRead()) {
        throw new ParameterException("Specified path is not readable.");
    }

    if (!certDirectory.isDirectory()) {
        throw new ParameterException("Specified path is not a directory.");
    }

    final FilenameFilter filter = new RegexFileFilter("^.*\\.pem$");
    final File[] files = certDirectory.listFiles(filter);
    Arrays.stream(files).forEach(file -> filenames.add(file.getName()));

    if (!filenames.containsAll(EXPECTED_FILE_NAMES)) {
        final StringJoiner sj = new StringJoiner(", ", "[", "]");
        EXPECTED_FILE_NAMES.stream().forEach(sj::add);
        throw new ParameterException("Not all expected files are present! Expected: " + sj.toString());
    }
}

From source file:net.straylightlabs.archivo.net.MindCommand.java

private String buildRequest() {
    failOnInvalidCommand();/*w  w w  .  jav  a 2 s. com*/

    List<String> headerLines = buildHeaderLines();

    bodyData.put("type", commandType.toString());
    String body = bodyData.toString();

    // The length is the number of characters plus two bytes for each \r\n line ending
    int headerLength = headerLines.stream().mapToInt(String::length).sum()
            + (headerLines.size() * MindRPC.LINE_ENDING.length());
    headerLines.add(0, String.format("MRPC/2 %d %d", headerLength, body.length()));

    StringJoiner joiner = new StringJoiner(MindRPC.LINE_ENDING, "", MindRPC.LINE_ENDING);
    headerLines.stream().forEach(joiner::add);
    joiner.add(body);
    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:info.archinnov.achilles.internals.statements.StatementWrapper.java

default void appendRowDataToBuilder(Row row, List<ColumnDefinitions.Definition> columnsDef,
        StringBuilder builder) {/*from   w w  w.java  2  s  .c o  m*/
    StringJoiner joiner = new StringJoiner(", ", "\t", "\n");
    IntStream.range(0, columnsDef.size()).forEach(index -> {
        final ColumnDefinitions.Definition def = columnsDef.get(index);
        final Object value = extractValueFromRow(row, index, def.getType());
        joiner.add(format("%s: %s", def.getName(), value));
    });
    builder.append(joiner.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);//from  w  ww.  j  a  va2 s  . c  o  m
    return joiner.toString();
}

From source file:edu.artic.geneva.sync.RowProcessor.java

/**
 *  Mint a URL for the given ID value, based on an MD5-based pairtree
 *///from  ww w . j a v  a 2  s .c o  m
private static String buildPath(final String prefix, final String id) {

    final StringBuilder path = new StringBuilder();
    final String md5 = md5Hex(id);

    final StringJoiner joiner = new StringJoiner("/", "", "/" + md5);

    IntStream.rangeClosed(0, DEFAULT_COUNT - 1)
            .forEach(x -> joiner.add(md5.substring(x * DEFAULT_LENGTH, (x + 1) * DEFAULT_LENGTH)));

    if (!prefix.startsWith("/")) {
        path.append("/");
    }

    if (prefix.length() > 0) {
        path.append(prefix);

        if (!prefix.endsWith("/")) {
            path.append("/");
        }
    }

    path.append(joiner.toString());
    return path.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 ww. jav  a2 s  .  com*/

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