Example usage for java.lang String join

List of usage examples for java.lang String join

Introduction

In this page you can find the example usage for java.lang String join.

Prototype

public static String join(CharSequence delimiter, Iterable<? extends CharSequence> elements) 

Source Link

Document

Returns a new String composed of copies of the CharSequence elements joined together with a copy of the specified delimiter .

Usage

From source file:com.solace.labs.spring.cloud.cloudfoundry.SolaceMessagingInfoCreator.java

@SuppressWarnings("unchecked")
@Override/*from w ww  .j ava2  s . c  o  m*/
public SolaceMessagingInfo createServiceInfo(Map<String, Object> serviceData) {
    String id = getId(serviceData);

    String clientUsername = null;
    String clientPassword = null;
    String msgVpnName = null;
    List<String> smfHosts = null;
    List<String> smfTlsHosts = null;
    List<String> smfZipHosts = null;
    List<String> jmsJndiUris = null;
    List<String> jmsJndiTlsUris = null;
    List<String> restUris = null;
    List<String> restTlsUris = null;
    List<String> mqttUris = null;
    List<String> mqttTlsUris = null;
    List<String> mqttWsUris = null;
    List<String> mqttWssUris = null;
    List<String> managementHostnames = null;
    String managementPassword = null;
    String managementUsername = null;

    Map<String, Object> credentials = getCredentials(serviceData);

    if (credentials == null) {
        throw new IllegalArgumentException("Received null credentials during object creation");
    }

    // Populate this the quick and dirty way for now. Can improve later as
    // we harden. As a start, we'll be tolerant of missing attributes and
    // just leave fields set to null.
    for (Map.Entry<String, Object> entry : credentials.entrySet()) {
        String key = entry.getKey();
        Object value = entry.getValue();

        switch (key) {
        case "clientUsername":
            clientUsername = (String) value;
            break;
        case "clientPassword":
            clientPassword = (String) value;
            break;
        case "msgVpnName":
            msgVpnName = (String) value;
            break;
        case "smfHosts":
            smfHosts = (List<String>) value;
            break;
        case "smfTlsHosts":
            smfTlsHosts = (List<String>) value;
            break;
        case "smfZipHosts":
            smfZipHosts = (List<String>) value;
            break;
        case "jmsJndiUris":
            jmsJndiUris = (List<String>) value;
            break;
        case "jmsJndiTlsUris":
            jmsJndiTlsUris = (List<String>) value;
            break;
        case "managementUsername":
            managementUsername = (String) value;
            break;
        case "managementPassword":
            managementPassword = (String) value;
            break;
        case "restUris":
            restUris = (List<String>) value;
            break;
        case "restTlsUris":
            restTlsUris = (List<String>) value;
            break;
        case "mqttUris":
            mqttUris = (List<String>) value;
            break;
        case "mqttTlsUris":
            mqttTlsUris = (List<String>) value;
            break;
        case "mqttWsUris":
            mqttWsUris = (List<String>) value;
            break;
        case "mqttWssUris":
            mqttWssUris = (List<String>) value;
            break;
        case "managementHostnames":
            managementHostnames = (List<String>) value;
            break;
        }
    }

    // Convert Lists to comma-separated strings on these properties, to be compatible with  the JCSMP Java client library.
    String smfHost = null;
    String smfTlsHost = null;
    String smfZipHost = null;
    String jmsJndiUri = null;
    String jmsJndiTlsUri = null;

    if (smfHosts != null)
        smfHost = String.join(",", smfHosts);
    if (smfTlsHosts != null)
        smfTlsHost = String.join(",", smfTlsHosts);
    if (smfZipHosts != null)
        smfZipHost = String.join(",", smfZipHosts);
    if (jmsJndiUris != null)
        jmsJndiUri = String.join(",", jmsJndiUris);
    if (jmsJndiTlsUris != null)
        jmsJndiTlsUri = String.join(",", jmsJndiTlsUris);

    SolaceMessagingInfo solMessagingInfo = new SolaceMessagingInfo(id, clientUsername, clientPassword,
            msgVpnName, smfHost, smfTlsHost, smfZipHost, jmsJndiUri, jmsJndiTlsUri, restUris, restTlsUris,
            mqttUris, mqttTlsUris, mqttWsUris, mqttWssUris, managementHostnames, managementPassword,
            managementUsername);

    return solMessagingInfo;
}

From source file:ijfx.core.imagedb.DefaultMetaDataExtractionService.java

@Override
public MetaDataSet extractMetaData(File file) {

    MetaDataSet metadataset = new MetaDataSet();
    Timer t = timerService.getTimer("MetaData Extraction");
    try {/*from w  w  w  . ja  v a2  s.com*/
        // ReaderFilter reader = getReaderFilter(file);
        t.start();
        Metadata metadata = getSCIFIO().format().getFormat(file.getAbsolutePath()).createParser()
                .parse(file.getAbsolutePath());
        t.elapsed("Metadata parser creation");
        long serieCount, timeCount, zCount, channelCount, width, height, imageSize, bitsPerPixel;
        String dimensionOrder;

        serieCount = metadata.getImageCount();
        width = metadata.get(0).getAxisLength(Axes.X);
        height = metadata.get(0).getAxisLength(Axes.Y);
        timeCount = metadata.get(0).getAxisLength(Axes.TIME);
        zCount = metadata.get(0).getAxisLength(Axes.Z);
        channelCount = metadata.get(0).getAxisLength(Axes.CHANNEL);
        bitsPerPixel = metadata.get(0).getBitsPerPixel();
        imageSize = metadata.getDatasetSize();
        //dimensionOrder = metadata.get

        metadataset.putGeneric(MetaData.WIDTH, width);
        metadataset.putGeneric(MetaData.HEIGHT, height);
        metadataset.putGeneric(MetaData.ZSTACK_NUMBER, zCount);
        metadataset.putGeneric(MetaData.TIME_COUNT, timeCount);
        metadataset.putGeneric(MetaData.BITS_PER_PIXEL, bitsPerPixel);
        metadataset.put(new FileSizeMetaData(file.length()));
        metadataset.putGeneric(MetaData.SERIE_COUNT, serieCount);
        metadataset.putGeneric(MetaData.CHANNEL_COUNT, channelCount);
        metadataset.putGeneric(MetaData.FILE_NAME, file.getName());
        metadataset.putGeneric(MetaData.ABSOLUTE_PATH, file.getAbsolutePath());

        // creating array containing the axes and axe lengths other than x an y
        long[] dims = new long[metadata.get(0).getAxesLengths().length - 2];
        CalibratedAxis[] axes = new CalibratedAxis[dims.length];
        if (dims.length > 0) {
            System.arraycopy(
                    metadata.get(0).getAxes().toArray(new CalibratedAxis[metadata.get(0).getAxes().size()]), 2,
                    axes, 0, axes.length);
            System.arraycopy(metadata.get(0).getAxesLengths(), 2, dims, 0, dims.length);

            NDimensionalArray ndarray = new NDimensionalArray(dims);

            String[] dimNames = new String[dims.length];

            for (int i = 0; i != dimNames.length; i++) {
                dimNames[i] = metadata.get(0).getAxis(i + 2).type().getLabel();
            }

            metadataset.putGeneric(MetaData.DIMENSION_ORDER, String.join(",", dimNames));
            metadataset.putGeneric(MetaData.DIMENSION_LENGHS, Arrays.toString(dims));
        }

        return metadataset;

    } catch (FormatException ex) {
        logger.log(Level.SEVERE, String.format(WRONG_FORMAT, file.getName()), ex);
    } catch (IOException ex) {
        logger.log(Level.SEVERE, String.format(ACCESS_PROBLEM, file.getName()), ex);
    }

    return metadataset;

}

From source file:org.ops4j.pax.web.itest.base.client.HttpComponentsTestClient.java

@SuppressWarnings("unchecked")
private void doAssertion(HttpResponse httpResponse) throws Exception {

    final Collection<String> assertionErrors = new ArrayList<>();

    if (returnCode != null) {
        final boolean assertionResult = assertTrue(httpResponse.getStatusLine().getStatusCode(),
                status -> returnCode.equals(status));
        if (!assertionResult) {
            assertionErrors.add(String.format("Unexpected HttpStatusCode returned! Expected '%s', but was '%s'",
                    returnCode, httpResponse.getStatusLine().getStatusCode()));
        }/*  w  ww.j  av  a 2s .c  om*/
    }

    final String responseContent;
    // handle No-Content-Responses
    if (httpResponse.getEntity() == null) {
        responseContent = "";
    } else {
        responseContent = EntityUtils.toString(httpResponse.getEntity());
    }

    for (@SuppressWarnings("rawtypes")
    AssertionWrapper wrapper : responseAssertion) {
        final boolean assertionResult = assertTrue(responseContent, wrapper.predicate);
        if (!assertionResult) {
            assertionErrors.add("Response mismatch: " + wrapper.message);
        }
    }

    if (!assertionErrors.isEmpty()) {
        throw new AssertionError(
                "Result is not conforming to expected definitions!\n" + String.join("\n\t", assertionErrors));
    }

}

From source file:com.spankingrpgs.util.LoadStateUtils.java

/**
 * Given a Loader, and a path to data files, loads the data from the files into the game using the loader.
 *
 * @param loader  The loader to use to load data into the game
 * @param dataPath  The path containing the files containing the data to load
 * @param fileGlob  A glob that describes the kinds of files to load
 * @param newLineMarker  The String to use to represent new lines
 *///from   w  w w  . j  av  a  2 s .c  om
public static void loadData(Loader loader, Path dataPath, String fileGlob, String newLineMarker) {
    LOG.info(String.format("Loading %s", dataPath));
    try {
        PathMatcher jsonMatcher = FileSystems.getDefault().getPathMatcher(fileGlob);
        Collection<String> data = StreamSupport.stream(Files.newDirectoryStream(dataPath).spliterator(), false)
                .peek(path -> LOG.fine(String.format("Loading data from %s", path)))
                .filter(jsonMatcher::matches).map((Path path) -> {
                    try {
                        return String.join(newLineMarker, Files.readAllLines(path));
                    } catch (IOException e) {
                        String msg = String.format("Problem reading file: %s", path);
                        LOG.log(Level.SEVERE, String.format("%s with exception:%s", msg, e), e);
                        throw new RuntimeException(msg);
                    }
                }).collect(Collectors.toList());
        loader.load(data, GameState.getCleanInstance());
    } catch (IOException exception) {
        String msg = String.format("Problem reading files in: %s", dataPath);
        LOG.log(Level.SEVERE, String.format("%s with exception: %s", msg, exception), exception);
        throw new RuntimeException(msg);
    }
}

From source file:io.paradoxical.cassieq.ServiceConfigurator.java

private void enableCors(ServiceConfiguration config, Environment environment) {
    FilterRegistration.Dynamic filter = environment.servlets().addFilter("CORS", CrossOriginFilter.class);

    filter.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), false,
            environment.getApplicationContext().getContextPath() + "*");
    filter.setInitParameter("allowedOrigins", String.join(",", config.getWeb().getAllowedOrigins())); // allowed origins comma separated
    filter.setInitParameter("allowedHeaders",
            "Content-Type,Authorization,X-Requested-With,Content-Length,Accept,Origin");
    filter.setInitParameter("allowedMethods", "GET,PUT,POST,DELETE,OPTIONS");
}

From source file:com.docdoku.core.util.Tools.java

public static String getPathAsString(List<PartLink> path) {
    List<String> ids = new ArrayList<>();
    for (PartLink link : path) {
        ids.add(link.getFullId());/*from www . j  av  a2s.c o  m*/
    }
    return String.join("-", ids); // java 8
}

From source file:no.ssb.jsonstat.v2.DatasetTest.java

@Test
public void testGetRows() throws Exception {

    Dataset dataset = Dataset.create("test")
            .withDimensions(Dimension.create("A").withCategories("A1", "A2", "A3"),
                    Dimension.create("B").withCategories("B1", "B2"),
                    Dimension.create("C").withCategories("C1", "C2", "C3", "C4"))
            .withMapper(strings -> String.join("", strings).hashCode()).build();

    List<Object> result = StreamSupport.stream(dataset.getRows().spliterator(), false)
            .collect(Collectors.toList());

    List<Integer> expected = Lists.transform(
            newArrayList("A1B1C1", "A1B1C2", "A1B1C3", "A1B1C4", "A1B2C1", "A1B2C2", "A1B2C3", "A1B2C4",

                    "A2B1C1", "A2B1C2", "A2B1C3", "A2B1C4", "A2B2C1", "A2B2C2", "A2B2C3", "A2B2C4",

                    "A3B1C1", "A3B1C2", "A3B1C3", "A3B1C4", "A3B2C1", "A3B2C2", "A3B2C3", "A3B2C4"),
            String::hashCode);/*from www. j a v a2s. co m*/

    assertThat(result).containsExactlyElementsOf(expected);

}

From source file:com.jeanchampemont.notedown.note.NoteService.java

private String generateDiff(String original, String revised) {
    List<String> originalLinesList = Arrays.asList(original.split("\n"));
    List<String> revisedLinesList = Arrays.asList(revised.split("\n"));

    Patch<String> patch = DiffUtils.diff(originalLinesList, revisedLinesList);

    List<String> diff = DiffUtils.generateUnifiedDiff("original", "revised", originalLinesList, patch, 0);

    return String.join("\n", diff);
}

From source file:com.esri.geoportal.geoportal.commons.geometry.GeometryService.java

/**
 * Translates UTM points from a string into lat lon values
 * /*from w w w . j a  v a2 s.  co m*/
 * @param coordinateStrings the points to translate, in the format {@code <grid><hemisphere> <easting> <northing>} E.G. {@code 18N 60000 80000}
 * @param toWkid the coordinate system to translate into
 * 
 * @return the translated points
 */
public MultiPoint fromGeoCoordinateString(List<String> coordinateStrings, int toWkid)
        throws IOException, URISyntaxException {
    HttpPost request = new HttpPost(createFromGeoCoordinateStringUrl().toURI());

    HashMap<String, String> params = new HashMap<>();
    params.put("f", "json");
    params.put("sr", Integer.toString(toWkid));
    params.put("strings", String.format("[\"%s\"]", String.join("\",\"", coordinateStrings)));
    params.put("conversionType", "UTM");
    params.put("coversionMode", "utmDefault");

    HttpEntity entity = new UrlEncodedFormEntity(params.entrySet().stream()
            .map(e -> new BasicNameValuePair(e.getKey(), e.getValue())).collect(Collectors.toList()), "UTF-8");
    request.setEntity(entity);

    try (CloseableHttpResponse httpResponse = httpClient.execute(request);
            InputStream contentStream = httpResponse.getEntity().getContent();) {
        if (httpResponse.getStatusLine().getStatusCode() >= 400) {
            throw new HttpResponseException(httpResponse.getStatusLine().getStatusCode(),
                    httpResponse.getStatusLine().getReasonPhrase());
        }

        FromGeoCoordinateStringResponse response = mapper.readValue(contentStream,
                FromGeoCoordinateStringResponse.class);
        return response.toMultipointGeometry();
    }
}

From source file:ddf.catalog.validation.impl.validator.RelationshipValidator.java

private String getValuesAsString() {
    return String.join(", ", targetValues);
}