List of usage examples for java.util StringJoiner toString
@Override
public String toString()
From source file:org.trellisldp.rosid.file.FileUtils.java
/** * Partition an identifier into a directory structure * @param identifier the identifier//from www .j a v a 2 s . c o m * @return a string usable as a directory path */ public static String partition(final String identifier) { requireNonNull(identifier, "identifier must not be null!"); final StringJoiner joiner = new StringJoiner(separator); final CRC32 hasher = new CRC32(); hasher.update(identifier.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(identifier)); return joiner.toString(); }
From source file:org.wso2.identity.scenarios.commons.util.SSOUtil.java
/** * Post user consent to Consent page/*from w w w. j av a2s .c o m*/ * * @param response HttpResponse to be referred for request sending. * @param commonAuthUrl commonauth URL * @param userAgent user-Agent * @param referer referer URL * @param httpClient HttpClient to be used for request sending. * @param pastreCookie 'pastre' Cookie * @return response after submitting consent * @throws Exception */ public static HttpResponse sendPOSTConsentMessage(HttpResponse response, String commonAuthUrl, String userAgent, String referer, HttpClient httpClient, String pastreCookie) throws Exception { String redirectUrl = getRedirectUrlFromResponse(response); Map<String, String> queryParams = getQueryParams(redirectUrl); String sessionKey = queryParams.get(PARAM_SESSION_DATA_KEY); String mandatoryClaims = queryParams.get(PARAM_MANDATORY_CLAIMS); String requestedClaims = queryParams.get(PARAM_REQUESTED_CLAIMS); String consentRequiredClaims; if (isNotBlank(mandatoryClaims) && isNotBlank(requestedClaims)) { StringJoiner joiner = new StringJoiner(","); joiner.add(mandatoryClaims); 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(HttpHeaders.USER_AGENT, userAgent); post.addHeader(HttpHeaders.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(PARAM_SESSION_DATA_KEY, sessionKey)); urlParameters.add(new BasicNameValuePair("consent", "approve")); post.setEntity(new UrlEncodedFormEntity(urlParameters)); return httpClient.execute(post); }
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[]/*from www .j av a2s .c o m*/ */ 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:edu.artic.geneva.sync.RowProcessor.java
/** * Mint a URL for the given ID value, based on an MD5-based pairtree */// w ww.ja va 2s . co m 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: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/*from w ww. j a v a 2 s . 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:org.elasticsearch.client.Request.java
/** * Utility method to build request's endpoint. *//* w w w .j a va 2 s.c o m*/ static String endpoint(String... parts) { if (parts == null || parts.length == 0) { return DELIMITER; } StringJoiner joiner = new StringJoiner(DELIMITER, DELIMITER, ""); for (String part : parts) { if (part != null) { joiner.add(part); } } return joiner.toString(); }
From source file:org.ballerinalang.langserver.command.CommandUtil.java
/** * Get the object constructor snippet generated from public object fields. * * @param fields List of Fields/*from w w w. ja va2 s.c o m*/ * @param baseOffset Offset of snippet * @return {@link String} Constructor snippet as String */ public static String getObjectConstructorSnippet(List<BLangSimpleVariable> fields, int baseOffset) { StringJoiner funcFields = new StringJoiner(", "); StringJoiner funcBody = new StringJoiner(CommonUtil.LINE_SEPARATOR); String offsetStr = String.join("", Collections.nCopies(baseOffset, " ")); fields.stream().filter(bField -> ((bField.symbol.flags & Flags.PUBLIC) != Flags.PUBLIC)).forEach(var -> { funcFields.add(generateTypeDefinition(null, null, var) + " " + var.name.value); funcBody.add(offsetStr + " self." + var.name.value + " = " + var.name.value + ";"); }); return offsetStr + "public function __init(" + funcFields.toString() + ") {" + CommonUtil.LINE_SEPARATOR + funcBody.toString() + CommonUtil.LINE_SEPARATOR + offsetStr + "}" + CommonUtil.LINE_SEPARATOR; }
From source file:org.ballerinalang.langserver.command.testgen.ValueSpaceGenerator.java
/** * Returns a value space for a given BLangNode. * * @param importsAcceptor imports acceptor * @param currentPkgId current package id * @param bLangNode BLangNode to evaluate * @param template templates to be modified * @return {@link String} modified templates * @see #createTemplateArray(int)/* ww w .j ava2s . c om*/ */ public static String[] getValueSpaceByNode(BiConsumer<String, String> importsAcceptor, PackageID currentPkgId, BLangNode bLangNode, String[] template) { if (bLangNode.type == null && bLangNode instanceof BLangTupleDestructure) { // Check for tuple assignment eg. (int, int) List<BLangExpression> varRefs = ((BLangTupleDestructure) bLangNode).getVariableRefs(); String[][] list = new String[varRefs.size()][template.length]; IntStream.range(0, varRefs.size()).forEach(j -> { BLangExpression bLangExpression = varRefs.get(j); if (bLangExpression.type != null) { String[] values = getValueSpaceByType(importsAcceptor, currentPkgId, bLangExpression.type, createTemplateArray(template.length)); IntStream.range(0, values.length).forEach(i -> list[i][j] = values[i]); } }); IntStream.range(0, template.length).forEach(index -> { template[index] = template[index].replace(PLACE_HOLDER, "(" + String.join(", ", list[index]) + ")"); }); return template; } else if (bLangNode instanceof BLangLiteral) { return (String[]) Stream.of(template) .map(s -> s.replace(PLACE_HOLDER, ((BLangLiteral) bLangNode).getValue().toString())).toArray(); } else if (bLangNode instanceof BLangAssignment) { return (String[]) Stream.of(template).map(s -> s.replace(PLACE_HOLDER, "0")).toArray(); } else if (bLangNode instanceof BLangFunctionTypeNode) { BLangFunctionTypeNode funcType = (BLangFunctionTypeNode) bLangNode; TestFunctionGenerator generator = new TestFunctionGenerator(importsAcceptor, currentPkgId, funcType); StringJoiner params = new StringJoiner(", "); String[][] valueSpace = generator.getValueSpace(); String[] typeSpace = generator.getTypeSpace(); String[] nameSpace = generator.getNamesSpace(); IntStream.range(0, typeSpace.length - 1).forEach(index -> { String type = typeSpace[index]; String name = nameSpace[index]; params.add(type + " " + name); }); String returnType = "(" + typeSpace[typeSpace.length - 1] + ")"; IntStream.range(0, template.length).forEach(index -> { String builder = "function (" + params.toString() + ") returns " + returnType + "{ " + ((valueSpace != null) ? "return " + valueSpace[index][funcType.params.size()] : "") + "; }"; template[index] = template[index].replace(PLACE_HOLDER, builder); }); return template; } return (bLangNode.type != null) ? getValueSpaceByType(importsAcceptor, currentPkgId, bLangNode.type, template) : template; }
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);//w w w . j a v a 2 s .c o m if (returnType == NEW) { return builder.addStatement("return new $T(select)", newTypeName).build(); } else { return builder.addStatement("return this").build(); } }
From source file:org.briljantframework.array.ArrayPrinter.java
/** * Format the {@link org.briljantframework.array.ArrayPrinter.ToStringArray} * * @param sb write resulting string representation to * @param arr the ToStringMatrix/*from w w w .jav a 2 s.c o m*/ * @throws java.io.IOException if an IO error occurs */ public static void print(Appendable sb, ToStringArray arr, String startChar, String endChar, boolean truncate, int dims, IntArray maxWidth) throws IOException { if (arr.size() == 0) { sb.append(startChar).append(arr.get(0)).append(endChar); return; } if (arr.dims() == 1) { StringJoiner joiner = new StringJoiner(", ", startChar, endChar); int max = arr.size(); if (truncate) { max = visiblePerSlice < 0 ? arr.size() : visiblePerSlice; } for (int i = 0; i < arr.size(); i++) { String value = pad(arr.get(i), maxWidth.get(i % max)); joiner.add(value); if (i >= max) { int left = arr.size() - i - 1; if (left > max) { i += left - max - 1; joiner.add("..."); } } } sb.append(joiner.toString()); } else { int len = arr.size(0); sb.append("["); print(sb, arr.select(0), startChar, endChar, truncate, dims, maxWidth); for (int i = 1; i < len; i++) { if (arr.dims() > 2) { sb.append(",\n\n"); } else { sb.append(",\n"); } for (int j = 0; j < dims - arr.dims(); j++) { sb.append(" "); } print(sb, arr.select(i), startChar, endChar, truncate, dims, maxWidth); int max = len; if (truncate) { max = printSlices < 0 ? len : printSlices; } if (i >= max) { int left = len - i - 1; if (left > max) { i += left - max - 1; sb.append(",\n"); for (int j = 0; j < dims - arr.dims(); j++) { sb.append(" "); } sb.append("..."); } } } sb.append("]"); } }