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) 

Source Link

Document

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

Usage

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

@Override
public OpenLayersContent get() {

    OpenLayersContent content = new OpenLayersContent();
    content.jsressource = JSRESOURCE;/*from   w w w  . j ava2 s . co  m*/
    content.cssressource = CSSRESOURCE;
    content.body = BODY;

    StringBuffer js = new StringBuffer(MAPJSSTART);

    StringJoiner layers = new StringJoiner(",\n");
    for (SelectionDescriptor selection : context.selectionDescriptors.get()) {
        String layer = replace(LAYERJS, "WMSURL", ArenaPlugin.instance().config().getProxyUrl() + "/ows");
        layer = replace(layer, "LAYER", GeoServerUtils.simpleName(selection.layer.get().label.get()));
        if (!StringUtils.isBlank(ArenaPlugin.instance().config().getServiceAuthToken())) {
            layer = replace(layer, "AUTH",
                    ", 'authToken': '" + ArenaPlugin.instance().config().getServiceAuthToken() + "'");
        } else {
            layer = replace(layer, "AUTH", "");
        }
        //            Envelope envelope = context.boundingBox.get();
        //            StringBuffer extent = new StringBuffer().append( (int)envelope.getMinX() ).append( "," ).append( (int)envelope.getMinY() ).append( "," ).append( (int)envelope.getMaxX() ).append( "," ).append( (int)envelope.getMaxY() );
        //            layer = replace( layer, "EXTENT", extent.toString() );
        layer = replace(layer, "CRS", context.crs.get().getIdentifiers().iterator().next().toString());
        layers.add(layer);
    }
    js.append(layers.toString());

    Coordinate centreCoordinate = context.boundingBox.get().centre();
    StringBuffer centre = new StringBuffer().append((int) centreCoordinate.x).append(",")
            .append((int) centreCoordinate.y);
    String jsend = replace(MAPJSEND, "CENTER", centre.toString());
    jsend = replace(jsend, "RESOLUTION", "" + context.resolution.get().intValue());
    js.append(jsend);

    content.js = js.toString();

    StringBuffer complete = new StringBuffer();
    complete.append("<!DOCTYPE html>\n");
    complete.append("<html>\n");
    complete.append("  <head>\n");
    complete.append("    <title>").append(ArenaConfig.getAppTitle()).append("</title>\n");
    complete.append("    <link rel='stylesheet' href='").append(content.cssressource)
            .append("' type='text/css'>\n");
    complete.append("    <script src='").append(content.jsressource).append("'></script>\n");
    complete.append("  </head>\n");
    complete.append("  <body>\n");
    complete.append("    ").append(content.body).append("\n");
    complete.append("    <script>\n");
    complete.append(content.js);
    complete.append("    </script>\n");
    complete.append("  </body>\n");
    complete.append("</html>\n");

    content.complete = complete.toString();

    return content;
}

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 v a 2 s .c o m*/
    return sj.toString();

}

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

@Override
public ImagePngContent get() {
    ImagePngContent content = new ImagePngContent();

    StringJoiner layers = new StringJoiner(",");
    for (SelectionDescriptor selection : context.selectionDescriptors.get()) {
        layers.add(GeoServerUtils.simpleName(selection.layer.get().label.get()));
        // FIXME, if multilayers are working, remove this break!!!
        //break;//from w  w w. ja v a 2 s.  c om
    }
    Envelope bbox = context.boundingBox.get();
    String extent = Joiner.on(",").join((int) bbox.getMinX(), (int) bbox.getMinY(), (int) bbox.getMaxX(),
            (int) bbox.getMaxY());

    String imageUrl = ArenaPlugin.instance().config().getProxyUrl() + GeoServerStarter.ALIAS;
    List<NameValuePair> params = new ArrayList() {
        {
            add(nameValue("SERVICE", "WMS"));
            add(nameValue("VERSION", "1.3.0"));
            add(nameValue("REQUEST", "GetMap"));
            add(nameValue("FORMAT", "image/png"));
            add(nameValue("CRS", "EPSG:3857"));
            add(nameValue("BBOX", extent.toString()));
            add(nameValue("LAYERS", layers.toString()));
        }
    };
    if (!StringUtils.isBlank(ArenaPlugin.instance().config().getServiceAuthToken())) {
        params.add(nameValue("authToken", ArenaPlugin.instance().config().getServiceAuthToken()));
    }
    content.imgWidth = context.displaySize.get().x;
    content.imgHeight = context.displaySize.get().y;

    content.previewWidth = 320;
    content.previewHeight = content.previewWidth * content.imgHeight / content.imgWidth;

    ArrayList previewParams = new ArrayList(params) {
        {
            add(nameValue("WIDTH", content.previewWidth));
            add(nameValue("HEIGHT", content.previewHeight));
        }
    };
    content.previewResource = imageUrl + "?" + URLEncodedUtils.format(previewParams, "UTF-8");

    ArrayList imgParams = new ArrayList(params) {
        {
            add(nameValue("WIDTH", content.imgWidth));
            add(nameValue("HEIGHT", content.imgHeight));
        }
    };
    content.imgResource = imageUrl + "?" + URLEncodedUtils.format(imgParams, "UTF-8");
    return content;
}

From source file:edu.emory.mathcs.nlp.zzz.CSVRadiology.java

public void categorize(String inputFile) throws Exception {
    CSVParser parser = new CSVParser(IOUtils.createBufferedReader(inputFile), CSVFormat.DEFAULT);
    List<CSVRecord> records = parser.getRecords();
    StringJoiner join;/*from   w w  w.ja v  a  2  s . com*/
    CSVRecord record;

    for (int i = 0; i <= 500; i++) {
        if (i == 0)
            continue;
        record = records.get(i);
        join = new StringJoiner(" ");

        for (int j = 2; j < 7; j++)
            join.add(record.get(j));

        System.out.println(join.toString());
    }

    parser.close();
}

From source file:org.wildfly.test.security.common.elytron.SimpleServerSslContext.java

@Override
public void create(ModelControllerClient client, CLIWrapper cli) throws Exception {
    // /subsystem=elytron/server-ssl-context=twoWaySSC:add(key-manager=twoWayKM,protocols=["TLSv1.2"],
    // trust-manager=twoWayTM,security-domain=test,need-client-auth=true)
    StringBuilder sb = new StringBuilder("/subsystem=elytron/server-ssl-context=").append(name).append(":add(");
    if (StringUtils.isNotBlank(keyManager)) {
        sb.append("key-manager=\"").append(keyManager).append("\", ");
    }//w  ww .  j  a  v a 2 s  . c om
    if (protocols != null) {
        StringJoiner joiner = new StringJoiner(", ");
        for (String s : protocols) {
            String s1 = "\"" + s + "\"";
            joiner.add(s1);
        }
        sb.append("protocols=[").append(joiner.toString()).append("], ");
    }
    if (StringUtils.isNotBlank(trustManager)) {
        sb.append("trust-manager=\"").append(trustManager).append("\", ");
    }
    if (StringUtils.isNotBlank(securityDomain)) {
        sb.append("security-domain=\"").append(securityDomain).append("\", ");
    }
    if (authenticationOptional != null) {
        sb.append("authentication-optional=").append(authenticationOptional).append(", ");
    }
    sb.append("need-client-auth=").append(needClientAuth).append(")");
    cli.sendLine(sb.toString());
}

From source file:org.openrepose.powerfilter.intrafilterlogging.ResponseLog.java

private Map<String, String> convertResponseHeadersToMap(HttpServletResponseWrapper wrappedServletResponse) {
    HashMap<String, String> headerMap = new LinkedHashMap<>();
    Collection<String> headerNames = wrappedServletResponse.getHeaderNames();

    for (String headerName : headerNames) {
        StringJoiner stringJoiner = new StringJoiner(",");
        wrappedServletResponse.getHeaders(headerName).forEach(stringJoiner::add);
        headerMap.put(headerName, stringJoiner.toString());
    }//w  w  w  .  j a v  a  2 s.  co m

    return headerMap;
}

From source file:org.jhk.pulsing.search.elasticsearch.client.ESRestClient.java

public Optional<String> getDocument(String index, String type, String id) {
    String endpoint = new StringJoiner("/").add(index).add(type).add(id).toString();

    try {//from  ww  w . j  a va2s  . com
        Optional<Response> response = performRequest("GET", endpoint, Collections.EMPTY_MAP, null,
                EMPTY_HEADER);
        if (response.isPresent()) {
            HttpEntity hEntity = response.get().getEntity();
            String result = EntityUtils.toString(hEntity);

            _LOGGER.debug("ESRestClient.getDocument: result - " + result);
            return Optional.of(result);
        }
    } catch (IOException iException) {
        iException.printStackTrace();
    }

    return Optional.empty();
}

From source file:com.github.robozonky.app.version.UpdateMonitor.java

/**
 * Assemble the Maven Central metadata URL from the given groupId and artifactId.
 * @param groupId Group ID in question.//from w ww .  j a va 2  s .  c  o  m
 * @param artifactId Artifact ID in question.
 * @param hostname Maven Central hostname, such as "https://repo1.maven.org"
 * @return Stream to read the Maven Central metadata from.
 * @throws IOException Network communications failure.
 */
private static InputStream getMavenCentralData(final String groupId, final String artifactId,
        final String hostname) throws IOException {
    final StringJoiner joiner = new StringJoiner(UpdateMonitor.URL_SEPARATOR).add(hostname).add("maven2");
    for (final String pkg : UpdateMonitor.PATTERN_DOT.split(groupId)) {
        joiner.add(pkg);
    }
    joiner.add(artifactId).add("maven-metadata.xml");
    return UrlUtil.open(new URL(joiner.toString()));
}

From source file:org.trellisldp.file.FileUtils.java

/**
 * Get a directory for a given resource identifier.
 * @param baseDirectory the base directory
 * @param identifier a resource identifier
 * @return a directory/*w  ww. ja v a  2s . c  o  m*/
 */
public static File getResourceDirectory(final File baseDirectory, final IRI identifier) {
    requireNonNull(baseDirectory, "The baseDirectory may not be null!");
    requireNonNull(identifier, "The identifier may not be null!");
    final String id = identifier.getIRIString();
    final StringJoiner joiner = new StringJoiner(separator);
    final CRC32 hasher = new CRC32();
    hasher.update(id.getBytes(UTF_8));
    final String intermediate = Long.toHexString(hasher.getValue());

    range(0, intermediate.length() / LENGTH).limit(MAX)
            .forEach(i -> joiner.add(intermediate.substring(i * LENGTH, (i + 1) * LENGTH)));

    joiner.add(md5Hex(id));
    return new File(baseDirectory, joiner.toString());
}

From source file:com.thinkbiganalytics.spark.shell.SparkClientUtil.java

/**
 * Gets the Spark version string by executing {@code spark-submit}.
 *
 * @throws IOException if the version string cannot be obtained
 *///  ww  w. java2s .  c o m
private static String getVersion() throws IOException {
    // Build spark-submit process
    final String sparkSubmitCommand = new StringJoiner(File.separator).add(getSparkHome()).add("bin")
            .add("spark-submit").toString();
    final Process process = new ProcessBuilder().command(sparkSubmitCommand, "--version")
            .redirectErrorStream(true).start();

    // Wait for process to complete
    boolean exited;
    try {
        exited = process.waitFor(10, TimeUnit.SECONDS);
    } catch (final InterruptedException e) {
        Thread.currentThread().interrupt();
        exited = !process.isAlive();
    }

    if (!exited) {
        throw new IOException("Timeout waiting for Spark version");
    }

    // Read stdout
    final byte[] bytes = new byte[1024];
    final int length = process.getInputStream().read(bytes);

    final String output = new String(bytes, 0, length, "UTF-8");
    final Matcher matcher = Pattern.compile("version ([\\d+.]+)").matcher(output);
    if (matcher.find()) {
        return matcher.group(1);
    } else {
        throw new IllegalStateException("Unable to determine version from Spark Submit");
    }
}