Example usage for java.util.stream Collectors joining

List of usage examples for java.util.stream Collectors joining

Introduction

In this page you can find the example usage for java.util.stream Collectors joining.

Prototype

public static Collector<CharSequence, ?, String> joining(CharSequence delimiter) 

Source Link

Document

Returns a Collector that concatenates the input elements, separated by the specified delimiter, in encounter order.

Usage

From source file:org.apache.metron.maas.util.RESTUtil.java

public String getRESTJSONResults(URL endpointUrl, Map<String, String> getArgs)
        throws IOException, URISyntaxException {
    String encodedParams = encodeParams(getArgs);
    HttpGet get = new HttpGet(appendToUrl(endpointUrl, encodedParams).toURI());
    get.addHeader("accept", "application/json");
    HttpResponse response = CLIENT.get().execute(get);

    if (response.getStatusLine().getStatusCode() != 200) {
        throw new IllegalStateException(
                "Failed : HTTP error code : " + response.getStatusLine().getStatusCode());
    }/*  w  w  w .ja va2s.c  om*/

    return new BufferedReader(new InputStreamReader(response.getEntity().getContent())).lines()
            .collect(Collectors.joining("\n"));
}

From source file:de.rnd7.libtvdb.util.EpisodeUtil.java

public static String toName(final List<EpisodeInfo> episodeInfos) {
    return episodeInfos.stream().map(EpisodeInfo::toString).collect(Collectors.joining(", "));
}

From source file:hudson.os.WindowsUtil.java

/**
 * Executes a command and arguments using {@code cmd.exe /C ...}.
 *///from  w ww  .j a va  2  s.  c  o m
public static @Nonnull Process execCmd(String... argv) throws IOException {
    String command = Arrays.stream(argv).map(WindowsUtil::quoteArgumentForCmd).collect(Collectors.joining(" "));
    return Runtime.getRuntime().exec(new String[] { "cmd.exe", "/C", command });
}

From source file:com.spectralogic.ds3autogen.java.generators.responseparser.BaseResponseParserGenerator.java

/**
 * Creates a comma-separated list of all expected status codes
 *///from  w w w. j a  v  a 2s  . c  o  m
protected static String toStatusCodeList(final ImmutableList<ResponseCode> responseCodes) {
    if (isEmpty(responseCodes)) {
        return "";
    }
    return responseCodes.stream().map(code -> Integer.toString(code.getCode()))
            .collect(Collectors.joining(", "));
}

From source file:com.intuit.wasabi.tests.service.priority.BasicPriorityTest.java

@Test(groups = { "setup" }, dependsOnMethods = {
        "setup" }, dataProvider = "Application", dataProviderClass = PriorityDataProvider.class)
public void setupMutexAndPriority(String appName) {
    String exclusion = "{\"experimentIDs\": ["
            + validExperimentsLists.stream().map(s -> "\"" + s.id + "\"").collect(Collectors.joining(","))
            + "]}";
    response = apiServerConnector.doPost("experiments/" + validExperimentsLists.get(0).id + "/exclusions",
            exclusion);// w  ww. j  a  va2 s .  co m
    assertReturnCode(response, HttpStatus.SC_CREATED);
    response = apiServerConnector.doPut("applications/" + appName + "/priorities", exclusion);
    assertReturnCode(response, HttpStatus.SC_NO_CONTENT);
    response = apiServerConnector.doGet("applications/" + appName + "/priorities");
    LOGGER.info("retrieved priorities: " + response.asString());
    Type listType = new TypeToken<Map<String, ArrayList<Map<String, Object>>>>() {
    }.getType();
    Map<String, List<Map<String, Object>>> result = new Gson().fromJson(response.asString(), listType);
    List<Map<String, Object>> prioritizedExperiments = result.get("prioritizedExperiments");
    Assert.assertEquals(prioritizedExperiments.size(), validExperimentsLists.size());
    for (int i = 0; i < validExperimentsLists.size(); i++) {
        Assert.assertEquals(prioritizedExperiments.get(i).get("id"), validExperimentsLists.get(i).id);
    }
}

From source file:com.thinkbiganalytics.alerts.rest.AlertsModel.java

public String alertTypeDisplayName(String type) {
    String part = type;/*  ww w . j  av  a  2s  .  co  m*/
    if (part.startsWith(AlertConstants.KYLO_ALERT_TYPE_PREFIX + "/alert")) {
        part = StringUtils.substringAfter(part, AlertConstants.KYLO_ALERT_TYPE_PREFIX + "/alert");
    } else if (part.startsWith(AlertConstants.KYLO_ALERT_TYPE_PREFIX)) {
        part = StringUtils.substringAfter(part, AlertConstants.KYLO_ALERT_TYPE_PREFIX);
    } else {
        int idx = StringUtils.lastOrdinalIndexOf(part, "/", 2);
        part = StringUtils.substring(part, idx);
    }
    String[] parts = part.split("/");
    return Arrays.asList(parts).stream().map(s -> StringUtils.capitalize(s)).collect(Collectors.joining(" "));
}

From source file:com.yahoo.elide.core.filter.FilterPredicate.java

public FilterPredicate(Path path, Operator op, List<Object> values) {
    this.operator = op;
    this.path = new Path(path);
    this.values = ImmutableList.copyOf(values);
    this.field = path.lastElement().map(PathElement::getFieldName).orElse(null);
    this.fieldPath = path.getPathElements().stream().map(PathElement::getFieldName)
            .collect(Collectors.joining(PERIOD));
}

From source file:cop.raml.mocks.MockUtils.java

public static ExecutableElementMock createExecutable(Method method) {
    if (method == null)
        return null;

    boolean isStatic = Modifier.isStatic(method.getModifiers());
    String params = Arrays.stream(method.getParameterTypes()).map(Class::getSimpleName)
            .collect(Collectors.joining(","));
    String name = String.format("(%s)%s", params, method.getReturnType().getSimpleName());

    return new ExecutableElementMock(method.getName() + "()", createMethodElement(name).asType())
            .setStatic(isStatic).setSimpleName(method.getName());
}

From source file:fi.helsinki.opintoni.security.SecurityUtils.java

public String getWhitelistedIpAccess() {
    List<String> whitelistedIps = appConfiguration.getStringValues("whitelistedIps");
    return whitelistedIps.stream().map(ip -> "hasIpAddress('" + ip + "')").collect(Collectors.joining(" or "));
}

From source file:com.vsct.dt.hesperides.indexation.command.IndexNewModuleCommandBulk.java

@Override
public Void index(final ElasticSearchClient elasticSearchClient) {
    String body;//ww  w  .ja v  a 2 s  .  c om
    List<SingleToBulkMapper> propertiesAsString;

    LOGGER.info("Index {} modules.", modules.size());

    propertiesAsString = modules.stream().map(module -> {
        LOGGER.info("Index module with namespace {}.", module.getNamespace());

        try {
            return new SingleToBulkMapper(module.getId(),
                    ElasticSearchMappers.MODULE_WRITER.writeValueAsString(module));
        } catch (final JsonProcessingException e) {
            LOGGER.error("Could not serialize module " + module);
            throw new RuntimeException(e);
        }
    }).collect(Collectors.toList());

    if (propertiesAsString != null && propertiesAsString.size() > 0) {
        body = propertiesAsString.stream().map(module -> module.toString()).collect(Collectors.joining(""));
        ElasticSearchEntity<ModuleIndexation> entity = elasticSearchClient
                .withResponseReader(ElasticSearchMappers.ES_ENTITY_MODULE_READER).post("/modules/_bulk", body);

        LOGGER.info("Successfully indexed new modules {}", propertiesAsString.size());
    }

    return null;
}