Example usage for java.util StringJoiner toString

List of usage examples for java.util StringJoiner toString

Introduction

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

Prototype

@Override
public String toString() 

Source Link

Document

Returns the current value, consisting of the prefix , the values added so far separated by the delimiter , and the suffix , unless no elements have been added in which case, the prefix + suffix or the emptyValue characters are returned.

Usage

From source file:com.microsoft.sqlserver.testframework.DBTable.java

/**
 * //from   w  ww.  j ava 2  s.  c  o m
 * @return query to create table
 */
String populateTableSql() {
    StringJoiner sb = new StringJoiner(SPACE_CHAR);

    sb.add("INSERT");
    sb.add("INTO");
    sb.add(escapedTableName);
    sb.add("VALUES");

    for (int i = 0; i < totalRows; i++) {
        if (i != 0) {
            sb.add(COMMA);
        }
        sb.add(OPEN_BRACKET);
        for (int colNum = 0; colNum < totalColumns; colNum++) {

            // TODO: consider how to enclose data in case of preparedStatemets
            if (passDataAsString(colNum)) {
                sb.add("'" + String.valueOf(getColumn(colNum).getRowValue(i)) + "'");
            } else if (passDataAsHex(colNum)) {
                sb.add("0X" + Hex.encodeHexString((byte[]) (getColumn(colNum).getRowValue(i))));
            } else {
                sb.add(String.valueOf(getColumn(colNum).getRowValue(i)));
            }

            if (colNum < totalColumns - 1) {
                sb.add(COMMA);
            }
        }
        sb.add(CLOSE_BRACKET);
    }

    return (sb.toString());
}

From source file:iterator.test.matchers.type.annotation.AnnotationMap.java

@Override
public String toString() {
    StringBuilder sb = new StringBuilder("@");
    sb.append(getAnnotationClass().getSimpleName());
    StringJoiner joiner = new StringJoiner(COMMA, "(", ")");
    joiner.setEmptyValue(EMPTY);// w  ww.  j  ava 2s.co m
    if (members.containsKey("value")) {
        MemberValue<?> mv = members.get("value");
        if (mv.isUndefined() || !mv.isDefault()) {
            if (members.size() > 1
                    && members.entrySet().stream().filter(entry -> !"value".equals(entry.getKey()))
                            .anyMatch(entry -> !entry.getValue().isDefault())) {
                joiner.add(String.format("value = %s", mv));
            } else {
                joiner.add(mv.toString());
            }
        }
    }
    members.entrySet().stream().filter(entry -> !"value".equals(entry.getKey())
            && (entry.getValue().isUndefined() || !entry.getValue().isDefault())).forEach(entry -> {
                joiner.add(String.format("%s = %s", entry.getKey(), entry.getValue()));
            });
    sb.append(joiner.toString());
    return sb.toString();
}

From source file:org.elasticsearch.client.RequestConvertersTests.java

public void testOpenIndex() {
    String[] indices = randomIndicesNames(1, 5);
    OpenIndexRequest openIndexRequest = new OpenIndexRequest(indices);
    openIndexRequest.indices(indices);/*w  w w . j av  a 2  s. co  m*/

    Map<String, String> expectedParams = new HashMap<>();
    setRandomTimeout(openIndexRequest::timeout, AcknowledgedRequest.DEFAULT_ACK_TIMEOUT, expectedParams);
    setRandomMasterTimeout(openIndexRequest, expectedParams);
    setRandomIndicesOptions(openIndexRequest::indicesOptions, openIndexRequest::indicesOptions, expectedParams);
    setRandomWaitForActiveShards(openIndexRequest::waitForActiveShards, expectedParams);

    Request request = RequestConverters.openIndex(openIndexRequest);
    StringJoiner endpoint = new StringJoiner("/", "/", "").add(String.join(",", indices)).add("_open");
    assertThat(endpoint.toString(), equalTo(request.getEndpoint()));
    assertThat(expectedParams, equalTo(request.getParameters()));
    assertThat(request.getMethod(), equalTo(HttpPost.METHOD_NAME));
    assertThat(request.getEntity(), nullValue());
}

From source file:org.elasticsearch.client.RequestConvertersTests.java

public void testCloseIndex() {
    String[] indices = randomIndicesNames(1, 5);
    CloseIndexRequest closeIndexRequest = new CloseIndexRequest(indices);

    Map<String, String> expectedParams = new HashMap<>();
    setRandomTimeout(closeIndexRequest::timeout, AcknowledgedRequest.DEFAULT_ACK_TIMEOUT, expectedParams);
    setRandomMasterTimeout(closeIndexRequest, expectedParams);
    setRandomIndicesOptions(closeIndexRequest::indicesOptions, closeIndexRequest::indicesOptions,
            expectedParams);// w w  w  .  ja  v  a2 s  .  c  o  m

    Request request = RequestConverters.closeIndex(closeIndexRequest);
    StringJoiner endpoint = new StringJoiner("/", "/", "").add(String.join(",", indices)).add("_close");
    assertThat(endpoint.toString(), equalTo(request.getEndpoint()));
    assertThat(expectedParams, equalTo(request.getParameters()));
    assertThat(request.getMethod(), equalTo(HttpPost.METHOD_NAME));
    assertThat(request.getEntity(), nullValue());
}

From source file:org.elasticsearch.client.RequestConvertersTests.java

public void testGetPipeline() {
    String pipelineId = "some_pipeline_id";
    Map<String, String> expectedParams = new HashMap<>();
    GetPipelineRequest request = new GetPipelineRequest("some_pipeline_id");
    setRandomMasterTimeout(request, expectedParams);
    Request expectedRequest = RequestConverters.getPipeline(request);
    StringJoiner endpoint = new StringJoiner("/", "/", "");
    endpoint.add("_ingest/pipeline");
    endpoint.add(pipelineId);// w w  w  .  ja  v  a  2s.c o m
    assertEquals(endpoint.toString(), expectedRequest.getEndpoint());
    assertEquals(HttpGet.METHOD_NAME, expectedRequest.getMethod());
    assertEquals(expectedParams, expectedRequest.getParameters());
}

From source file:org.elasticsearch.client.RequestConvertersTests.java

public void testDeletePipeline() {
    String pipelineId = "some_pipeline_id";
    Map<String, String> expectedParams = new HashMap<>();
    DeletePipelineRequest request = new DeletePipelineRequest(pipelineId);
    setRandomMasterTimeout(request, expectedParams);
    setRandomTimeout(request::timeout, AcknowledgedRequest.DEFAULT_ACK_TIMEOUT, expectedParams);
    Request expectedRequest = RequestConverters.deletePipeline(request);
    StringJoiner endpoint = new StringJoiner("/", "/", "");
    endpoint.add("_ingest/pipeline");
    endpoint.add(pipelineId);/*from  ww  w  . j  a  v a  2s . com*/
    assertEquals(endpoint.toString(), expectedRequest.getEndpoint());
    assertEquals(HttpDelete.METHOD_NAME, expectedRequest.getMethod());
    assertEquals(expectedParams, expectedRequest.getParameters());
}

From source file:org.elasticsearch.client.RequestConvertersTests.java

public void testPutPipeline() throws IOException {
    String pipelineId = "some_pipeline_id";
    PutPipelineRequest request = new PutPipelineRequest("some_pipeline_id",
            new BytesArray("{}".getBytes(StandardCharsets.UTF_8)), XContentType.JSON);
    Map<String, String> expectedParams = new HashMap<>();
    setRandomMasterTimeout(request, expectedParams);
    setRandomTimeout(request::timeout, AcknowledgedRequest.DEFAULT_ACK_TIMEOUT, expectedParams);

    Request expectedRequest = RequestConverters.putPipeline(request);
    StringJoiner endpoint = new StringJoiner("/", "/", "");
    endpoint.add("_ingest/pipeline");
    endpoint.add(pipelineId);/*from   w w w .  j ava  2  s.co m*/
    assertEquals(endpoint.toString(), expectedRequest.getEndpoint());
    assertEquals(HttpPut.METHOD_NAME, expectedRequest.getMethod());
    assertEquals(expectedParams, expectedRequest.getParameters());
}

From source file:org.elasticsearch.client.RequestConvertersTests.java

public void testIndexPutSettings() throws IOException {
    String[] indices = randomBoolean() ? null : randomIndicesNames(0, 2);
    UpdateSettingsRequest updateSettingsRequest = new UpdateSettingsRequest(indices);
    Map<String, String> expectedParams = new HashMap<>();
    setRandomMasterTimeout(updateSettingsRequest, expectedParams);
    setRandomTimeout(updateSettingsRequest::timeout, AcknowledgedRequest.DEFAULT_ACK_TIMEOUT, expectedParams);
    setRandomIndicesOptions(updateSettingsRequest::indicesOptions, updateSettingsRequest::indicesOptions,
            expectedParams);/*w w  w  .ja  va  2  s. c o  m*/
    if (randomBoolean()) {
        updateSettingsRequest.setPreserveExisting(randomBoolean());
        if (updateSettingsRequest.isPreserveExisting()) {
            expectedParams.put("preserve_existing", "true");
        }
    }

    Request request = RequestConverters.indexPutSettings(updateSettingsRequest);
    StringJoiner endpoint = new StringJoiner("/", "/", "");
    if (indices != null && indices.length > 0) {
        endpoint.add(String.join(",", indices));
    }
    endpoint.add("_settings");
    assertThat(endpoint.toString(), equalTo(request.getEndpoint()));
    assertEquals(HttpPut.METHOD_NAME, request.getMethod());
    assertToXContentBody(updateSettingsRequest, request.getEntity());
    assertEquals(expectedParams, request.getParameters());
}

From source file:org.elasticsearch.client.RequestConvertersTests.java

public void testRefresh() {
    String[] indices = randomBoolean() ? null : randomIndicesNames(0, 5);
    RefreshRequest refreshRequest;//from w  ww  . j a  v  a  2s  .co m
    if (randomBoolean()) {
        refreshRequest = new RefreshRequest(indices);
    } else {
        refreshRequest = new RefreshRequest();
        refreshRequest.indices(indices);
    }
    Map<String, String> expectedParams = new HashMap<>();
    setRandomIndicesOptions(refreshRequest::indicesOptions, refreshRequest::indicesOptions, expectedParams);
    Request request = RequestConverters.refresh(refreshRequest);
    StringJoiner endpoint = new StringJoiner("/", "/", "");
    if (indices != null && indices.length > 0) {
        endpoint.add(String.join(",", indices));
    }
    endpoint.add("_refresh");
    assertThat(request.getEndpoint(), equalTo(endpoint.toString()));
    assertThat(request.getParameters(), equalTo(expectedParams));
    assertThat(request.getEntity(), nullValue());
    assertThat(request.getMethod(), equalTo(HttpPost.METHOD_NAME));
}

From source file:org.elasticsearch.client.RequestConvertersTests.java

public void testRankEval() throws Exception {
    RankEvalSpec spec = new RankEvalSpec(
            Collections.singletonList(
                    new RatedRequest("queryId", Collections.emptyList(), new SearchSourceBuilder())),
            new PrecisionAtK());
    String[] indices = randomIndicesNames(0, 5);
    RankEvalRequest rankEvalRequest = new RankEvalRequest(spec, indices);
    Map<String, String> expectedParams = new HashMap<>();
    setRandomIndicesOptions(rankEvalRequest::indicesOptions, rankEvalRequest::indicesOptions, expectedParams);

    Request request = RequestConverters.rankEval(rankEvalRequest);
    StringJoiner endpoint = new StringJoiner("/", "/", "");
    String index = String.join(",", indices);
    if (Strings.hasLength(index)) {
        endpoint.add(index);//from ww  w.j a  v  a2s . c om
    }
    endpoint.add(RestRankEvalAction.ENDPOINT);
    assertEquals(endpoint.toString(), request.getEndpoint());
    assertEquals(3, request.getParameters().size());
    assertEquals(expectedParams, request.getParameters());
    assertToXContentBody(spec, request.getEntity());
}