List of usage examples for java.util StringJoiner StringJoiner
public StringJoiner(CharSequence delimiter)
From source file:com.microsoft.sqlserver.testframework.DBTable.java
String createTableSql() { StringJoiner sb = new StringJoiner(SPACE_CHAR); sb.add(CREATE_TABLE);/*from ww w. j a v a2 s.co m*/ sb.add(escapedTableName); sb.add(OPEN_BRACKET); for (int i = 0; i < totalColumns; i++) { DBColumn column = getColumn(i); sb.add(escapeIdentifier(column.getColumnName())); sb.add(column.getSqlType().getName()); // add precision and scale if (VariableLengthType.Precision == column.getSqlType().getVariableLengthType()) { sb.add(OPEN_BRACKET); sb.add("" + column.getSqlType().getPrecision()); sb.add(CLOSE_BRACKET); } else if (VariableLengthType.Scale == column.getSqlType().getVariableLengthType()) { sb.add(OPEN_BRACKET); sb.add("" + column.getSqlType().getPrecision()); sb.add(COMMA); sb.add("" + column.getSqlType().getScale()); sb.add(CLOSE_BRACKET); } sb.add(COMMA); } sb.add(CLOSE_BRACKET); return sb.toString(); }
From source file:com.cotrino.langnet.GenerateVisualization.java
/** * based on http://bl.ocks.org/1377729/*w ww . jav a2 s. c om*/ * @param jsFile */ private void generateVisualization(String jsFile) { String content = ""; int i = 0; double max = 0.0, min = 100.0; StringJoiner sj = new StringJoiner(","); StringJoiner nodesHash = new StringJoiner(" "); StringJoiner linkList = new StringJoiner(","); HashMap<String, Integer> languageIds = new HashMap<String, Integer>(); for (String language : amountWordsPerLanguage.keySet()) { // language bubble color & size int red = (int) (Math.random() * 127.0); int green = (int) (Math.random() * 127.0); int blue = (int) (Math.random() * 127.0); int color = ((red + 128) << 16) | ((green + 128) << 8) | ((blue + 128)); int textcolor = ((red + 64) << 16) | ((green + 64) << 8) | ((blue + 64)); int size = amountWordsPerLanguage.get(language) / 2000; if (size < 5) { size = 5; } // language information String description = "Language: " + getWikiURL(language) + "<br/><br/>"; if (languageSimilarities.containsKey(language)) { List<LanguageSimilarity> similarLanguages = languageSimilarities.get(language); Collections.sort(similarLanguages); description += "Similar to:<ul>"; // look for most similar languages for (LanguageSimilarity languageB : similarLanguages) { description += "<li>" + getWikiURL(languageB.language) + " at " + String.format("%d", (int) (languageB.similarity * 100)) + "%</li>"; max = Math.max(max, languageB.similarity); min = Math.min(min, languageB.similarity); } description += "</ul>"; } else { description += "No similar languages found."; } sj.add("{ label : \"" + language + "\", " + "id : " + i + ", " + "color : \"#" + String.format("%6x", color) + "\", " + "textcolor : \"#" + String.format("%6x", textcolor) + "\", " + "size : " + size + ", desc : \"" + description + "\" }"); nodesHash.add("nodesHash[\"" + language + "\"] = " + i + ";"); languageIds.put(language, i); i++; } content += "var nodesArray = [\n" + sj.toString() + "\n];\n\n"; content += "var nodesHash = [];\n" + nodesHash.toString() + "\n\n"; for (String languageA : languageSimilarities.keySet()) { for (LanguageSimilarity languageB : languageSimilarities.get(languageA)) { int color = (int) (240 * (1.0 + MIN_SIMILARITY - languageB.similarity)); if (color > 240) { color = 240; } if (languageIds.containsKey(languageA) && languageIds.containsKey(languageB.language)) { linkList.add("{ desc : \"" + languageA + " -- " + languageB.language + "\", " + "source : " + languageIds.get(languageA) + ", " + "target : " + languageIds.get(languageB.language) + ", " + "weight : " + languageB.similarity + ", " + "color : \"#" + String.format("%02x%02xff", color, color) + "\" }"); } } } content += "var linksArray = [\n" + linkList.toString() + "\n];\n"; IOUtil.write(jsFile, content); }
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()); }//ww w.ja va 2s . c o m return sj.toString(); }
From source file:org.mule.service.soap.client.CxfClientProvider.java
private Map<String, Object> buildSecurityProperties(List<SecurityStrategyCxfAdapter> strategies, SecurityStrategyType type) {//from w w w . j a va2 s . c om if (strategies.isEmpty()) { return emptyMap(); } Map<String, Object> props = new HashMap<>(); StringJoiner actionsJoiner = new StringJoiner(" "); ImmutableList.Builder<CallbackHandler> callbackHandlersBuilder = ImmutableList.builder(); strategies.stream().filter(securityStrategy -> securityStrategy.securityType().equals(type)) .forEach(securityStrategy -> { props.putAll(securityStrategy.buildSecurityProperties()); actionsJoiner.add(securityStrategy.securityAction()); securityStrategy.buildPasswordCallbackHandler().ifPresent(callbackHandlersBuilder::add); }); List<CallbackHandler> handlers = callbackHandlersBuilder.build(); if (!handlers.isEmpty()) { props.put(PW_CALLBACK_REF, new CompositeCallbackHandler(handlers)); } String actions = actionsJoiner.toString(); if (isNotBlank(actions)) { // the list of actions is passed as a String with the action names separated by a black space. props.put(ACTION, actions); } // This Map needs to be mutable, cxf will add properties if needed. return props; }
From source file:com.google.gerrit.server.mail.send.OutgoingEmail.java
/** * Format and enqueue the message for delivery. * * @throws EmailException// ww w. j a va2 s . c o m */ public void send() throws EmailException { if (NotifyHandling.NONE.equals(notify) && accountsToNotify.isEmpty()) { return; } if (!args.emailSender.isEnabled()) { // Server has explicitly disabled email sending. // return; } init(); if (useHtml()) { appendHtml(soyHtmlTemplate("HeaderHtml")); } format(); appendText(textTemplate("Footer")); if (useHtml()) { appendHtml(soyHtmlTemplate("FooterHtml")); } Set<Address> smtpRcptToPlaintextOnly = new HashSet<>(); if (shouldSendMessage()) { if (fromId != null) { final Account fromUser = args.accountCache.get(fromId).getAccount(); GeneralPreferencesInfo senderPrefs = fromUser.getGeneralPreferencesInfo(); if (senderPrefs != null && senderPrefs.getEmailStrategy() == CC_ON_OWN_COMMENTS) { // If we are impersonating a user, make sure they receive a CC of // this message so they can always review and audit what we sent // on their behalf to others. // add(RecipientType.CC, fromId); } else if (!accountsToNotify.containsValue(fromId) && rcptTo.remove(fromId)) { // If they don't want a copy, but we queued one up anyway, // drop them from the recipient lists. // removeUser(fromUser); } } // Check the preferences of all recipients. If any user has disabled // his email notifications then drop him from recipients' list. // In addition, check if users only want to receive plaintext email. for (Account.Id id : rcptTo) { Account thisUser = args.accountCache.get(id).getAccount(); GeneralPreferencesInfo prefs = thisUser.getGeneralPreferencesInfo(); if (prefs == null || prefs.getEmailStrategy() == DISABLED) { removeUser(thisUser); } else if (useHtml() && prefs.getEmailFormat() == EmailFormat.PLAINTEXT) { removeUser(thisUser); smtpRcptToPlaintextOnly.add(new Address(thisUser.getFullName(), thisUser.getPreferredEmail())); } if (smtpRcptTo.isEmpty() && smtpRcptToPlaintextOnly.isEmpty()) { return; } } // Set Reply-To only if it hasn't been set by a child class // Reply-To will already be populated for the message types where Gerrit supports // inbound email replies. if (!headers.containsKey("Reply-To")) { StringJoiner j = new StringJoiner(", "); if (fromId != null) { Address address = toAddress(fromId); if (address != null) { j.add(address.getEmail()); } } smtpRcptTo.stream().forEach(a -> j.add(a.getEmail())); smtpRcptToPlaintextOnly.stream().forEach(a -> j.add(a.getEmail())); setHeader("Reply-To", j.toString()); } String textPart = textBody.toString(); OutgoingEmailValidationListener.Args va = new OutgoingEmailValidationListener.Args(); va.messageClass = messageClass; va.smtpFromAddress = smtpFromAddress; va.smtpRcptTo = smtpRcptTo; va.headers = headers; va.body = textPart; if (useHtml()) { va.htmlBody = htmlBody.toString(); } else { va.htmlBody = null; } for (OutgoingEmailValidationListener validator : args.outgoingEmailValidationListeners) { try { validator.validateOutgoingEmail(va); } catch (ValidationException e) { return; } } if (!smtpRcptTo.isEmpty()) { // Send multipart message args.emailSender.send(va.smtpFromAddress, va.smtpRcptTo, va.headers, va.body, va.htmlBody); } if (!smtpRcptToPlaintextOnly.isEmpty()) { // Send plaintext message Map<String, EmailHeader> shallowCopy = new HashMap<>(); shallowCopy.putAll(headers); // Remove To and Cc shallowCopy.remove(HDR_TO); shallowCopy.remove(HDR_CC); for (Address a : smtpRcptToPlaintextOnly) { // Add new To EmailHeader.AddressList to = new EmailHeader.AddressList(); to.add(a); shallowCopy.put(HDR_TO, to); } args.emailSender.send(va.smtpFromAddress, smtpRcptToPlaintextOnly, shallowCopy, va.body); } } }
From source file:com.microsoft.sqlserver.testframework.DBTable.java
/** * //from w w w . ja v a2s . c o m * @return query to create table */ String populateTableSql() { StringJoiner sb = new StringJoiner(SPACE_CHAR); sb.add("INSERT"); sb.add("INTO"); sb.add(escapedTableName); sb.add("VALUES"); for (int i = 0; i < totalRows; i++) { if (i != 0) { sb.add(COMMA); } sb.add(OPEN_BRACKET); for (int colNum = 0; colNum < totalColumns; colNum++) { // TODO: consider how to enclose data in case of preparedStatemets if (passDataAsString(colNum)) { sb.add("'" + String.valueOf(getColumn(colNum).getRowValue(i)) + "'"); } else if (passDataAsHex(colNum)) { sb.add("0X" + Hex.encodeHexString((byte[]) (getColumn(colNum).getRowValue(i)))); } else { sb.add(String.valueOf(getColumn(colNum).getRowValue(i))); } if (colNum < totalColumns - 1) { sb.add(COMMA); } } sb.add(CLOSE_BRACKET); } return (sb.toString()); }
From source file:org.polymap.p4.data.importer.prompts.CharsetPrompt.java
private String displayName(Charset charset) { StringBuffer name = new StringBuffer(charset.displayName(Polymap.getSessionLocale())); if (!charset.aliases().isEmpty()) { name.append(" ( "); StringJoiner joiner = new StringJoiner(", "); for (String alias : charset.aliases()) { joiner.add(alias);//from www . j a v a 2s .co m } name.append(joiner.toString()); name.append(" )"); } return name.toString(); }
From source file:info.archinnov.achilles.internals.parser.FieldInfoParser.java
protected Tuple2<CodeBlock, ColumnInfo> buildColumnInfo(AnnotationTree annotationTree, VariableElement elm, String fieldName, TypeName rawEntityClass) { final CodeBlock.Builder builder = CodeBlock.builder(); final boolean isFrozen = containsAnnotation(annotationTree, Frozen.class); final Optional<TypedMap> partitionKey = extractTypedMap(annotationTree, PartitionKey.class); final Optional<TypedMap> clusteringColumn = extractTypedMap(annotationTree, ClusteringColumn.class); final Optional<TypedMap> computed = extractTypedMap(annotationTree, Computed.class); validateAllowedFrozen(isFrozen, aptUtils, elm, fieldName, rawEntityClass); if (partitionKey.isPresent()) { final int order = partitionKey.get().getTyped("order"); aptUtils.validateTrue(order > 0, "@PartitionKey order on field '%s' of class '%s' should be > 0, the ordering starts at 1", fieldName, rawEntityClass); builder.add("new $T($L, $L)", PARTITION_KEY_INFO, order, isFrozen); return Tuple2.of(builder.build(), new PartitionKeyInfo(order, isFrozen)); } else if (clusteringColumn.isPresent()) { final int order = clusteringColumn.get().getTyped("order"); final ClusteringOrder clusteringOrder = clusteringColumn.get().<Boolean>getTyped("asc") ? ASC : DESC; aptUtils.validateTrue(order > 0, "@ClusteringColumn order on field '%s' of class '%s' should be > 0, the ordering starts at 1", fieldName, rawEntityClass); builder.add("new $T($L, $L, $T.$L)", CLUSTERING_COLUMN_INFO, order, isFrozen, CLUSTERING_ORDER, clusteringOrder.name()); return Tuple2.of(builder.build(), new ClusteringColumnInfo(order, isFrozen, clusteringOrder)); } else if (computed.isPresent()) { final TypedMap typedMap = computed.get(); final String function = typedMap.getTyped("function"); final String alias = typedMap.getTyped("alias"); final List<String> targetColumns = typedMap.getTyped("targetColumns"); final Class<?> cqlClass = typedMap.getTyped("cqlClass"); final ClassName className = ClassName.get(cqlClass); final StringJoiner joiner = new StringJoiner(","); for (String x : targetColumns) { joiner.add("\"" + x + "\""); }//from w ww. ja v a2 s . com builder.add("new $T($S, $S, $T.asList(new String[]{$L}), $T.class)", COMPUTED_COLUMN_INFO, function, alias, ARRAYS, joiner.toString(), className); return Tuple2.of(builder.build(), new ComputedColumnInfo(function, alias, targetColumns, cqlClass)); } else { builder.add("new $T($L)", COLUMN_INFO, isFrozen); return Tuple2.of(builder.build(), new ColumnInfo(isFrozen)); } }
From source file:com.microsoft.sqlserver.testframework.DBTable.java
/** * This will give you query for Drop Table. *//*from w w w.j a v a2s . c o m*/ String dropTableSql() { StringJoiner sb = new StringJoiner(SPACE_CHAR); sb.add("IF OBJECT_ID"); sb.add(OPEN_BRACKET); sb.add(wrapName(tableName)); sb.add(","); sb.add(wrapName("U")); sb.add(CLOSE_BRACKET); sb.add("IS NOT NULL"); sb.add("DROP TABLE"); sb.add(escapedTableName); // for drop table no need to wrap. return sb.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 ww w .j av a 2 s.c om * @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; }