List of usage examples for java.util StringJoiner toString
@Override
public String toString()
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:com.tom.deleteme.PrintAnnotations.java
public static void appendOtherNamedTags(JSONObject json, String coveredText) { String otherNamedTags = (String) json.get(OtherNamedTagsKey); StringJoiner joiner = new StringJoiner(","); joiner.add(otherNamedTags).add(coveredText); String joinedString = joiner.toString(); json.put(OtherNamedTagsKey, joinedString); }
From source file:pcgen.core.display.VisionDisplay.java
@NotNull public static String getVision(final PlayerCharacter aPC, CDOMObject cdo) { if (aPC == null) { return ""; }/*w ww . j a v a 2s.co m*/ Collection<CDOMReference<Vision>> mods = CollectionUtils.emptyIfNull(cdo.getListMods(Vision.VISIONLIST)); StringJoiner visionString = new StringJoiner(";"); mods.stream().flatMap(ref -> ref.getContainedObjects().stream()).map(v -> v.toString(aPC)) .forEach(visionString::add); return visionString.toString(); }
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 va 2s . co 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:uk.nhs.fhir.load.FileLoader.java
/** * @param file File to load content from * @return String containing content of specified file *//* w w w.ja v a 2 s .c o m*/ public static String loadFile(final File file) { LOG.debug("Loading file: " + file.getAbsolutePath()); String charsetName; try { charsetName = getCharset(file); } catch (IOException e) { throw new IllegalStateException("Unable to determine appropriate charset for file " + file.getName(), e); } LOG.debug("Loading file using encoding: " + charsetName); try (ByteArrayOutputStream bOutStream = new ByteArrayOutputStream(); InputStream fis = new FileInputStream(file); InputStream bomInputStream = new BOMInputStream(fis); Reader streamReader = new InputStreamReader(bomInputStream, charsetName); BufferedReader in = new BufferedReader(streamReader);) { StringJoiner sj = new StringJoiner("\n"); String str; while ((str = in.readLine()) != null) { sj.add(str); } return sj.toString(); } catch (IOException e) { throw new IllegalStateException("Error reading file: " + file.getName(), e); } }
From source file:net.straylightlabs.archivo.controller.TelemetryController.java
public static String getAddressesAsString(NetworkInterface nic) { StringJoiner sj = new StringJoiner(", "); for (InetAddress address : Collections.list(nic.getInetAddresses())) { sj.add(address.getHostAddress()); }//from w w w.ja va 2 s . com return sj.toString(); }
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 w w. ja v a2 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.wso2.identity.integration.test.util.Utils.java
public static List<NameValuePair> getConsentRequiredClaimsFromResponse(HttpResponse response) throws Exception { String redirectUrl = Utils.getRedirectUrl(response); Map<String, String> queryParams = Utils.getQueryParams(redirectUrl); List<NameValuePair> urlParameters = new ArrayList<>(); String requestedClaims = queryParams.get("requestedClaims"); String mandatoryClaims = queryParams.get("mandatoryClaims"); String consentRequiredClaims; if (isNotBlank(mandatoryClaims) && isNotBlank(requestedClaims)) { StringJoiner joiner = new StringJoiner(","); joiner.add(mandatoryClaims);//from w ww.j ava2 s.c o m joiner.add(requestedClaims); consentRequiredClaims = joiner.toString(); } else if (isNotBlank(mandatoryClaims)) { consentRequiredClaims = mandatoryClaims; } else { consentRequiredClaims = requestedClaims; } String[] claims; if (isNotBlank(consentRequiredClaims)) { claims = consentRequiredClaims.split(","); } else { claims = new String[0]; } for (String claim : claims) { if (isNotBlank(claim)) { String[] claimMeta = claim.split("_", 2); if (claimMeta.length == 2) { urlParameters.add(new BasicNameValuePair("consent_" + claimMeta[0], "on")); } } } return urlParameters; }
From source file:org.wso2.identity.integration.test.util.Utils.java
public static HttpResponse sendPOSTConsentMessage(HttpResponse response, String commonAuthUrl, String userAgent, String referer, HttpClient httpClient, String pastreCookie) throws Exception { String redirectUrl = getRedirectUrl(response); Map<String, String> queryParams = getQueryParams(redirectUrl); String sessionKey = queryParams.get("sessionDataKey"); String mandatoryClaims = queryParams.get("mandatoryClaims"); String requestedClaims = queryParams.get("requestedClaims"); String consentRequiredClaims; if (isNotBlank(mandatoryClaims) && isNotBlank(requestedClaims)) { StringJoiner joiner = new StringJoiner(","); joiner.add(mandatoryClaims);/*from w w w. j a va 2 s . c om*/ joiner.add(requestedClaims); consentRequiredClaims = joiner.toString(); } else if (isNotBlank(mandatoryClaims)) { consentRequiredClaims = mandatoryClaims; } else { consentRequiredClaims = requestedClaims; } String[] claims; if (isNotBlank(consentRequiredClaims)) { claims = consentRequiredClaims.split(","); } else { claims = new String[0]; } HttpPost post = new HttpPost(commonAuthUrl); post.setHeader("User-Agent", userAgent); post.addHeader("Referer", referer); post.addHeader("Cookie", pastreCookie); List<NameValuePair> urlParameters = new ArrayList<>(); for (int i = 0; i < claims.length; i++) { if (isNotBlank(claims[i])) { String[] claimMeta = claims[i].split("_", 2); if (claimMeta.length == 2) { urlParameters.add(new BasicNameValuePair("consent_" + claimMeta[0], "on")); } } } urlParameters.add(new BasicNameValuePair("sessionDataKey", sessionKey)); urlParameters.add(new BasicNameValuePair("consent", "approve")); post.setEntity(new UrlEncodedFormEntity(urlParameters)); return httpClient.execute(post); }
From source file:Main.java
public static String getDeepNodeValue(Node node) { StringJoiner out = new StringJoiner(" "); if (node.hasChildNodes()) { for (int i = 0; i < node.getChildNodes().getLength(); i++) { String val = getDeepNodeValue(node.getChildNodes().item(i)); if (val != null && val.trim().length() != 0) out.add(val.trim()); }//from w ww .j a v a2 s . c o m } else if (node.getNodeValue() != null && node.getNodeValue().trim().length() != 0) { out.add(node.getNodeValue().trim()); } return out.toString(); }