List of usage examples for java.util StringJoiner StringJoiner
public StringJoiner(CharSequence delimiter)
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: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)// w w w . ja v a 2 s . co m */ 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:com.github.wxiaoqi.gate.ratelimit.filters.RateLimitFilter.java
private String key(final HttpServletRequest request, final List<Type> types) { final Route route = route(); final StringJoiner joiner = new StringJoiner(":"); joiner.add(properties.getKeyPrefix()); joiner.add(route.getId());//from w w w. jav a 2 s. com if (!types.isEmpty()) { if (types.contains(Type.URL)) { joiner.add(route.getPath()); } if (types.contains(Type.ORIGIN)) { joiner.add(getRemoteAddr(request)); } if (types.contains(Type.USER)) { joiner.add( userPrincipal.getName(request) != null ? userPrincipal.getName(request) : ANONYMOUS_USER); } } return joiner.toString(); }
From source file:org.fcrepo.client.GetBuilder.java
private String buildPrefer(final String prefer, final List<URI> includeUris, final List<URI> omitUris) { final StringJoiner preferJoin = new StringJoiner("; "); preferJoin.add("return=" + prefer); if (includeUris != null) { final String include = includeUris.stream().map(URI::toString).collect(Collectors.joining(" ")); if (include.length() > 0) { preferJoin.add("include=\"" + include + "\""); }// www. j a v a 2s . c om } if (omitUris != null) { final String omit = omitUris.stream().map(URI::toString).collect(Collectors.joining(" ")); if (omit.length() > 0) { preferJoin.add("omit=\"" + omit + "\""); } } return preferJoin.toString(); }
From source file:com.comcast.cdn.traffic_control.traffic_router.core.external.StatsTest.java
@Test public void itGetsApplicationStats() throws Exception { HttpGet httpGet = new HttpGet("http://localhost:3333/crs/stats"); CloseableHttpResponse httpResponse = null; try {//www . jav a 2s .c o m httpResponse = httpClient.execute(httpGet); String responseContent = EntityUtils.toString(httpResponse.getEntity()); ObjectMapper objectMapper = new ObjectMapper(); Map<String, Object> data = objectMapper.readValue(responseContent, new TypeReference<HashMap<String, Object>>() { }); assertThat(data.keySet(), containsInAnyOrder("app", "stats")); Map<String, Object> appData = (Map<String, Object>) data.get("app"); assertThat(appData.keySet(), containsInAnyOrder("buildTimestamp", "name", "deploy-dir", "git-revision", "version")); Map<String, Object> statsData = (Map<String, Object>) data.get("stats"); assertThat(statsData.keySet(), containsInAnyOrder("dnsMap", "httpMap", "totalDnsCount", "totalHttpCount", "totalDsMissCount", "appStartTime", "averageDnsTime", "averageHttpTime", "updateTracker")); Map<String, Object> dnsStats = (Map<String, Object>) statsData.get("dnsMap"); Map<String, Object> cacheDnsStats = (Map<String, Object>) dnsStats.values().iterator().next(); assertThat(cacheDnsStats.keySet(), containsInAnyOrder("czCount", "geoCount", "missCount", "dsrCount", "errCount", "deepCzCount", "staticRouteCount", "fedCount", "regionalDeniedCount", "regionalAlternateCount")); Map<String, Object> httpStats = (Map<String, Object>) statsData.get("httpMap"); Map<String, Object> cacheHttpStats = (Map<String, Object>) httpStats.values().iterator().next(); assertThat(cacheHttpStats.keySet(), containsInAnyOrder("czCount", "geoCount", "missCount", "dsrCount", "errCount", "deepCzCount", "staticRouteCount", "fedCount", "regionalDeniedCount", "regionalAlternateCount")); Map<String, Object> updateTracker = (Map<String, Object>) statsData.get("updateTracker"); Set<String> keys = updateTracker.keySet(); List<String> expectedStats = Arrays.asList("lastCacheStateCheck", "lastCacheStateChange", "lastConfigCheck", "lastConfigChange"); if (!keys.containsAll(expectedStats)) { StringJoiner joiner = new StringJoiner(","); for (String stat : expectedStats) { joiner.add(stat); } fail("Missing at least one of the following keys '" + joiner.toString() + "'"); } } finally { if (httpResponse != null) httpResponse.close(); } }
From source file:org.glassfish.jersey.examples.feedcombiner.resources.CombinedFeedControllerTest.java
@Test public void testCreate() { Form form = new Form(); form.param("title", params[0]); form.param("description", params[1]); form.param("urls", new StringJoiner(",").add(params[2]).add(params[3]).toString()); form.param("refreshPeriod", params[4]); Response response = target().request() .post(Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED_TYPE)); assertEquals(Status.OK.getStatusCode(), response.getStatus()); String html = response.readEntity(String.class); // HTML page contains all information about the created entity assertTrue(html.contains(params[0]) && html.contains(params[1]) && html.contains(params[2]) && html.contains(params[3]) && html.contains(params[4])); }
From source file:com.offbynull.voip.kademlia.GraphHelper.java
@SuppressWarnings("unchecked") private void applyRoutingTreeChanges(Context ctx, RouteTreeChangeSet changeSet) { Set<BitString> updatedPrefixes = new HashSet<>(); // Remove nodes from graph and set for (Activity removedNode : changeSet.getKBucketChangeSet().getBucketChangeSet().viewRemoved()) { Id id = removedNode.getNode().getId(); BitString prefix = findPrefixInRouteTreeIds(id); routeTreePrefixToIds.get(prefix).remove(id); updatedPrefixes.add(prefix);/*from www. j av a2s.c o m*/ } // Add nodes to graph and set for (Activity addedNode : changeSet.getKBucketChangeSet().getBucketChangeSet().viewAdded()) { Id id = addedNode.getNode().getId(); BitString prefix = findPrefixInRouteTreeIds(id); routeTreePrefixToIds.get(prefix).add(id); updatedPrefixes.add(prefix); } for (BitString updatedPrefix : updatedPrefixes) { // Concatenate to string and set as label StringJoiner joiner = new StringJoiner("\n"); // Find parent int prefixBitLength = updatedPrefix.getBitLength(); BitString parentPrefix = getParentPrefix(routeTreePrefixToIds.keySet(), updatedPrefix); // Calculate number of bits after parent prefix (the bits to display) int newBitsOffset = parentPrefix.getBitLength(); int newBitsLength = prefixBitLength - parentPrefix.getBitLength(); BitString prefixDisplayBits = updatedPrefix.getBits(newBitsOffset, newBitsLength); // Change label to contain all nodes in the bucket joiner.add(prefixDisplayBits.toString()); routeTreePrefixToIds.get(updatedPrefix).forEach(id -> joiner.add(id.getBitString().toString())); ctx.addOutgoingMessage(graphAddress, new LabelNode(updatedPrefix.toString(), joiner.toString())); } }
From source file:cc.altruix.javaprologinterop.PlUtilsLogic.java
protected String composeVarNameTxt(String[] varNames) { final StringJoiner stringJoiner = new StringJoiner(","); Arrays.stream(varNames).forEach(x -> stringJoiner.add(x)); return stringJoiner.toString(); }
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 v a2s . 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]; } 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:info.archinnov.achilles.internals.codegen.meta.UDTMetaCodeGen.java
private MethodSpec buildComponentsProperty(TypeName rawBeanType, List<FieldMetaSignature> parsingResults) { TypeName returnType = genericType(LIST, genericType(ABSTRACT_PROPERTY, rawBeanType, WILDCARD, WILDCARD)); final StringJoiner allFields = new StringJoiner(", "); parsingResults.stream().map(x -> x.context.fieldName).forEach(x -> allFields.add(x)); StringBuilder fieldList = new StringBuilder(); fieldList.append("return $T.asList(").append(allFields.toString()).append(")"); return MethodSpec.methodBuilder("getComponentsProperty").addAnnotation(Override.class) .addModifiers(Modifier.PROTECTED).returns(returnType).addStatement(fieldList.toString(), ARRAYS) .build();//from w ww . j a v a 2 s.c o m }