List of usage examples for java.util StringJoiner add
public StringJoiner add(CharSequence newElement)
From source file:se.nrm.dina.naturarv.portal.controller.MainChart.java
private String buildLabel(Month month, boolean isSwedish) { log.info("month : {} -- {}", month, month.getEnglish()); StringJoiner sj = new StringJoiner(" "); String monName = isSwedish ? month.getSwedish() : month.getEnglish(); int monNum = month.getNumberOfMonth(); sj.add(monName); if (monNum > today.getMonthValue()) { sj.add(String.valueOf(lastYearDate.getYear())); } else {/*from w ww . ja v a 2 s . co m*/ sj.add(String.valueOf(today.getYear())); } return sj.toString(); }
From source file:com.microsoft.sqlserver.testframework.DBTable.java
/** * This will give you query for Drop Table. *///from w w w . j ava 2 s . c om 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:com.microsoft.sqlserver.testframework.DBTable.java
String createTableSql() { StringJoiner sb = new StringJoiner(SPACE_CHAR); sb.add(CREATE_TABLE); sb.add(escapedTableName);/* w w w .j av a 2 s . co m*/ 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.microsoft.sqlserver.testframework.DBTable.java
/** * //from w w w.ja v a2 s. 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:net.sf.jabref.sql.importer.DatabaseImporter.java
/** * Worker method to perform the import from a database * * @param dbs The necessary database connection information * @param mode/*from ww w . j a v a2s.c o m*/ * @return An ArrayList containing pairs of Objects. Each position of the ArrayList stores three Objects: a * BibDatabase, a MetaData and a String with the bib database name stored in the DBMS * @throws SQLException * @throws ClassNotFoundException * @throws InstantiationException * @throws IllegalAccessException * @throws Exception */ public List<DBImporterResult> performImport(DBStrings dbs, List<String> listOfDBs, BibDatabaseMode mode) throws IllegalAccessException, InstantiationException, ClassNotFoundException, SQLException { List<DBImporterResult> result = new ArrayList<>(); try (Connection conn = this.connectToDB(dbs)) { Iterator<String> itLista = listOfDBs.iterator(); StringJoiner stringJoiner = new StringJoiner(",", "(", ")"); while (itLista.hasNext()) { stringJoiner.add("'" + itLista.next() + "'"); } String query = SQLUtil .queryAllFromTable("jabref_database WHERE database_name IN " + stringJoiner.toString()); try (Statement statement = conn.createStatement(); ResultSet rsDatabase = statement.executeQuery(query)) { while (rsDatabase.next()) { BibDatabase database = new BibDatabase(); // Find entry type IDs and their mappings to type names: HashMap<String, EntryType> types = new HashMap<>(); try (Statement entryTypes = conn.createStatement(); ResultSet rsEntryType = entryTypes .executeQuery(SQLUtil.queryAllFromTable("entry_types"))) { while (rsEntryType.next()) { Optional<EntryType> entryType = EntryTypes.getType(rsEntryType.getString("label"), mode); if (entryType.isPresent()) { types.put(rsEntryType.getString("entry_types_id"), entryType.get()); } } } List<String> colNames = this.readColumnNames(conn).stream() .filter(column -> !COLUMNS_NOT_CONSIDERED_FOR_ENTRIES.contains(column)) .collect(Collectors.toList()); final String database_id = rsDatabase.getString("database_id"); // Read the entries and create BibEntry instances: HashMap<String, BibEntry> entries = new HashMap<>(); try (Statement entryStatement = conn.createStatement(); ResultSet rsEntries = entryStatement.executeQuery(SQLUtil .queryAllFromTable("entries WHERE database_id= '" + database_id + "';"))) { while (rsEntries.next()) { String id = rsEntries.getString("entries_id"); BibEntry entry = new BibEntry(IdGenerator.next(), types.get(rsEntries.getString("entry_types_id")).getName()); entry.setCiteKey(rsEntries.getString("cite_key")); for (String col : colNames) { String value = rsEntries.getString(col); if (value != null) { col = col.charAt(col.length() - 1) == '_' ? col.substring(0, col.length() - 1) : col; entry.setField(col, value); } } entries.put(id, entry); database.insertEntry(entry); } } // Import strings and preamble: try (Statement stringStatement = conn.createStatement(); ResultSet rsStrings = stringStatement.executeQuery(SQLUtil .queryAllFromTable("strings WHERE database_id='" + database_id + '\''))) { while (rsStrings.next()) { String label = rsStrings.getString("label"); String content = rsStrings.getString("content"); if ("@PREAMBLE".equals(label)) { database.setPreamble(content); } else { BibtexString string = new BibtexString(IdGenerator.next(), label, content); database.addString(string); } } } MetaData metaData = new MetaData(); metaData.initializeNewDatabase(); // Read the groups tree: importGroupsTree(metaData, entries, conn, database_id); result.add(new DBImporterResult(database, metaData, rsDatabase.getString("database_name"))); } } } return result; }
From source file:info.archinnov.achilles.internals.parser.CodecFactory.java
CodeBlock buildJavaTypeForJackson(TypeName sourceType) { if (sourceType instanceof ClassName) { final ClassName className = (ClassName) sourceType; return CodeBlock.builder().add("$T.construct($T.class)", SIMPLE_TYPE, className.box()).build(); } else if (sourceType instanceof ParameterizedTypeName) { final ParameterizedTypeName paramTypeName = (ParameterizedTypeName) sourceType; StringJoiner code = new StringJoiner(",", "$T.TYPE_FACTORY_INSTANCE.constructParametricType($T.class,", ")"); for (TypeName x : paramTypeName.typeArguments) { code.add("$L"); }/*from w w w. j a v a2 s . c om*/ final Object[] headTypes = new Object[] { JSON_CODEC, paramTypeName.rawType }; final Object[] codeBlocks = paramTypeName.typeArguments.stream() .map(typeName -> (Object) buildJavaTypeForJackson(typeName)).toArray(); return CodeBlock.builder().add(code.toString(), ArrayUtils.addAll(headTypes, codeBlocks)).build(); } else if (sourceType instanceof ArrayTypeName) { final TypeName componentType = ((ArrayTypeName) sourceType).componentType; return CodeBlock.builder().add("$T.TYPE_FACTORY_INSTANCE.constructArrayType($L)", JSON_CODEC, buildJavaTypeForJackson(componentType.box())).build(); } else if (sourceType instanceof WildcardTypeName) { aptUtils.printError("Cannot build Jackson Mapper JavaType for wildcard type " + sourceType.toString()); } else { aptUtils.printError("Cannot build Jackson Mapper JavaType for type " + sourceType.toString()); } return null; }
From source file:org.mule.service.soap.client.CxfClientProvider.java
private Map<String, Object> buildSecurityProperties(List<SecurityStrategyCxfAdapter> strategies, SecurityStrategyType type) {// w ww. ja v a 2s .c o m 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:org.springframework.cloud.gcp.data.spanner.core.SpannerTemplate.java
private StringBuilder logColumns(String tableName, KeySet keys, Iterable<String> columns) { StringBuilder logSb = new StringBuilder( "Executing read on table " + tableName + " with keys: " + keys + " and columns: "); StringJoiner sj = new StringJoiner(","); columns.forEach((col) -> sj.add(col)); logSb.append(sj.toString());// w w w.j ava 2 s.c o m return logSb; }
From source file:com.oneops.transistor.service.BomManagerImpl.java
private String getNspath(String nsPath, CmsCI plat) { StringJoiner nSjoiner = new StringJoiner("/"); nSjoiner.add(nsPath).add(plat.getCiName()).add(plat.getAttribute("major_version").getDjValue()); return nSjoiner.toString(); }
From source file:com.sri.ai.praise.model.imports.church.ChurchToModelVisitor.java
@Override public synchronized Expression visitParse(@NotNull ChurchParser.ParseContext ctx) { Expression result = null;// w ww .j a va 2s .c o m // Clear down the working variables randoms.clear(); knownConstants.clear(); knownRandomVariableNames.clear(); rules.clear(); queries.clear(); flipIdToValue.clear(); visitChildren(ctx); // Construct the HOGM StringBuilder hogm = new StringBuilder(); hogm.append("\n"); if (knownConstants.size() > 0) { StringJoiner knownConstantsCommaSeparatedList = new StringJoiner(", ", ", ", ""); knownConstants.forEach(constant -> knownConstantsCommaSeparatedList.add(constant.toString())); hogm.append("sort " + CHURCH_VALUES_SORT + " : " + SortDeclaration.UNKNOWN_SIZE + knownConstantsCommaSeparatedList + ";\n\n"); } else { boolean randomsReferToValuesSort = false; for (String randomDeclaration : randoms) { if (randomDeclaration.contains(CHURCH_VALUES_SORT)) { randomsReferToValuesSort = true; break; } } if (randomsReferToValuesSort) { hogm.append("sort " + CHURCH_VALUES_SORT + ";\n\n"); } } for (String rv : randoms) { hogm.append(rv + ";\n"); } hogm.append("\n"); for (String r : rules) { if (Expressions.ZERO_POINT_FIVE.equals(r)) { continue; // simplified to know nothing about the random variable so skip it } hogm.append(r + ";\n"); } Model m = RuleConverter.makeModel(churchProgramName, "\n" + churchProgram + "\n--->\n" + hogm.toString(), hogm.toString()); result = Tuple.make(newSymbol(hogm.toString()), m.getModelDefinition(), ExtensionalSet.makeUniSet(queries)); return result; }