List of usage examples for java.util StringJoiner add
public StringJoiner add(CharSequence newElement)
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:main.java.framework.java.measurement.MeasurementUtils.java
/** * Parses a {@link MethodTree} for it's id used in the database * @param tree/*from www . j a va2s .c o 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:ch.newscron.encryption.Encryption.java
/** * Given a JSONObject, extracts its fields and computes the hash using the MD5 algorithm * @param obj is a JSONObject consisting of the four fields * @return a MD5 hash of type byte[]/* w ww.ja va 2 s .com*/ */ public static byte[] createMD5Hash(JSONObject obj) { //Create a string of the fields with format: "<customerId>$<rew1>$<rew2>$<val>" StringJoiner stringToHash = new StringJoiner("$"); stringToHash.add((String) obj.get("custID")); stringToHash.add((String) obj.get("rew1")); stringToHash.add((String) obj.get("rew2")); stringToHash.add((String) obj.get("val")); //Get hash of string try { MessageDigest m = MessageDigest.getInstance("MD5"); byte[] hash = m.digest(stringToHash.toString().getBytes("UTF-8")); return hash; } catch (Exception e) { } return null; }
From source file:uk.nhs.fhir.load.FileLoader.java
/** * @param file File to load content from * @return String containing content of specified file *///from ww w .j a v a 2s .c om 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:edu.artic.geneva.sync.RowProcessor.java
/** * Mint a URL for the given ID value, based on an MD5-based pairtree *//* www .j ava 2s .c om*/ private static String buildPath(final String prefix, final String id) { final StringBuilder path = new StringBuilder(); final String md5 = md5Hex(id); final StringJoiner joiner = new StringJoiner("/", "", "/" + md5); IntStream.rangeClosed(0, DEFAULT_COUNT - 1) .forEach(x -> joiner.add(md5.substring(x * DEFAULT_LENGTH, (x + 1) * DEFAULT_LENGTH))); if (!prefix.startsWith("/")) { path.append("/"); } if (prefix.length() > 0) { path.append(prefix); if (!prefix.endsWith("/")) { path.append("/"); } } path.append(joiner.toString()); return path.toString(); }
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()); }/* w w w. ja va2s . co m*/ return sj.toString(); }
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()); }/*w w w . j a va 2 s .c om*/ } else if (node.getNodeValue() != null && node.getNodeValue().trim().length() != 0) { out.add(node.getNodeValue().trim()); } return out.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./* w ww . ja 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:info.archinnov.achilles.internals.codegen.dsl.select.SelectDSLCodeGen.java
private static MethodSpec buildSelectComputedColumnMethod(TypeName newTypeName, FieldMetaSignature parsingResult, String fieldName, ReturnType returnType) { final ComputedColumnInfo columnInfo = (ComputedColumnInfo) parsingResult.context.columnInfo; StringJoiner joiner = new StringJoiner(",", fieldName + ".fcall($S,", ").as($S)"); columnInfo.functionArgs.forEach(x -> joiner.add("$L")); final Object[] functionName = new Object[] { columnInfo.functionName }; final Object[] functionArgs = columnInfo.functionArgs.stream() .map(arg -> CodeBlock.builder().add("$T.column($S)", QUERY_BUILDER, arg).build()).toArray(); final Object[] alias = new Object[] { columnInfo.alias }; final Object[] varargs = ArrayUtils.addAll(functionName, ArrayUtils.addAll(functionArgs, alias)); final MethodSpec.Builder builder = MethodSpec.methodBuilder(parsingResult.context.fieldName) .addJavadoc("Generate a SELECT ... <strong>$L($L) AS $L</strong> ...", varargs) .addModifiers(Modifier.PUBLIC, Modifier.FINAL).addStatement(joiner.toString(), varargs) .returns(newTypeName);/*from ww w .j av a2s . com*/ if (returnType == NEW) { return builder.addStatement("return new $T(select)", newTypeName).build(); } else { return builder.addStatement("return this").build(); } }