List of usage examples for java.util StringJoiner toString
@Override
public String toString()
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);//from ww w. jav a 2 s . c o m if (monNum > today.getMonthValue()) { sj.add(String.valueOf(lastYearDate.getYear())); } else { sj.add(String.valueOf(today.getYear())); } return sj.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/* ww w. ja va 2s .com*/ * @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:com.hzq.car.CarTest.java
private void sendAndSave(String token, Date date, String url) throws ParseException, IOException { Integer pages = getPages(token, date, url); for (int i = 0; i <= pages; i++) { Map map = getData(token, date, url, i); List<Map> o = (List<Map>) ((Map) ((Map) map.get("data")).get("pager")).get("items"); o.stream().filter(secondCar -> "".equals(secondCar.get("status")) && "".equals(secondCar.get("upShelf"))).forEach(data1 -> { SecondCar car = new SecondCar(); car.setUserId(-1);/* w w w . java 2 s. c o m*/ car.setMerchantId(0); car.setIsMerchant(0); //? String brand = (String) data1.get("brand"); if (brand != null) { Integer type = getCarType(brand); car.setType(type); } // String model = (String) data1.get("model"); car.setTitle(model); // journey String mileage = (String) data1.get("mileage"); BigDecimal journey = new BigDecimal(mileage).divide(new BigDecimal(10000), 2, RoundingMode.HALF_UP); car.setJourney(journey); SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); SimpleDateFormat fmt2 = new SimpleDateFormat("yyyy-MM-dd"); // String firstLicensePlateDate = (String) data1.get("firstLicensePlateDate"); try { firstLicensePlateDate = fmt2.format(fmt.parse(firstLicensePlateDate)); } catch (ParseException e) { e.printStackTrace(); } car.setLicenseTime(firstLicensePlateDate); // car.setBuyTime(firstLicensePlateDate); // String insuranceExpiresDate = (String) data1.get("insuranceExpiresDate"); try { if (insuranceExpiresDate != null && !"null".equals(insuranceExpiresDate)) { insuranceExpiresDate = fmt2.format(fmt.parse(insuranceExpiresDate)); } } catch (ParseException e) { e.printStackTrace(); } car.setInsuranceDeadtime(insuranceExpiresDate); //?? String carDescribe = (String) data1.get("carDescribe"); car.setIntroduction(carDescribe); //??? nature Integer usage = 0; String useType = (String) data1.get("useType"); if ("??".equals(useType)) usage = 1; car.setNature(usage.toString()); //? exhaust BigDecimal engineVolume = new BigDecimal((String) data1.get("engineVolume")); car.setExhaust(engineVolume); // carPicture List<String> carPicture = (List<String>) data1.get("carPicture"); if (carPicture.size() > 0) { car.setPictue(carPicture.get(0)); StringJoiner joiner = new StringJoiner(","); carPicture.forEach(joiner::add); car.setCarPic(joiner.toString()); } // salePrice Integer salePrice = Integer.parseInt((String) data1.get("salePrice")); BigDecimal price = new BigDecimal(salePrice).divide(new BigDecimal(10000), 2, RoundingMode.HALF_UP); car.setPrice(price); //? firstLicensePlateDate Integer year = Integer.parseInt(firstLicensePlateDate.substring(0, 4)); Integer toSet = 0; int now = 2017 - year; if (now <= 1) toSet = 0; if (now > 1 && now <= 3) toSet = 1; if (now > 3 && now <= 5) toSet = 3; if (now > 5 && now <= 8) toSet = 4; if (now > 8 && now <= 10) toSet = 5; if (now > 10) toSet = 6; car.setYear(toSet); // String color = (String) data1.get("color"); Integer resultColor = 15; if (color != null) { if (color.contains("")) resultColor = 1; if (color.contains("")) resultColor = 2; if (color.contains("")) resultColor = 3; if (color.contains("?")) resultColor = 4; if (color.contains("")) resultColor = 5; if (color.contains("?")) resultColor = 6; if (color.contains("")) resultColor = 7; if (color.contains("")) resultColor = 8; if (color.contains("")) resultColor = 9; if (color.contains("")) resultColor = 10; if (color.contains("")) resultColor = 11; if (color.contains("")) resultColor = 12; if (color.contains("")) resultColor = 13; if (color.contains("")) resultColor = 14; } car.setColor(resultColor); //?,?? contactPerson phone String contactPerson = (String) data1.get("contactPerson"); String phone = (String) data1.get("phone"); car.setConcactName(contactPerson); car.setConcactPhone(phone); // Integer transferNumber = (Integer) data1.get("transferNumber"); car.setTimes(transferNumber); // try { car.setCreatedAt(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss") .parse((String) data1.get("upShelfDate"))); } catch (ParseException e) { e.printStackTrace(); } try { secondCarMapper.insert(car); } catch (Exception e) { e.printStackTrace(); } }); } }
From source file:com.sri.ai.praise.sgsolver.solver.HOGMQueryError.java
@Override public String toString() { StringJoiner sj = new StringJoiner(""); if (context == Context.UNKNOWN) { sj.add("General Error: "); } else if (context == Context.QUERY) { sj.add("Error in Query "); } else if (context == Context.MODEL) { sj.add("Error in Model "); }/*from w w w . j a va 2 s . c o m*/ if (context != Context.UNKNOWN) { sj.add("at Line " + line + ": "); } sj.add(errorMessage); if (throwable != null) { sj.add("\n"); sj.add(ExceptionUtils.getStackTrace(throwable)); } return sj.toString(); }
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. ja va2s.c o m 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: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.microsoft.sqlserver.testframework.DBTable.java
/** * This will give you query for Drop Table. *//* w ww. j ava2 s . co 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.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 + "\""); }// w ww. j av a2s. com } 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: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"); }/* w w w .j av a 2 s .co m*/ 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:it.polimi.diceH2020.SPACE4Cloud.shared.solution.Solution.java
public String toStringReduced() { StringJoiner sj = new StringJoiner("\t", "", ""); sj.add("solID=" + id).add("solFeas=" + this.isFeasible().toString()) .add("cost=" + BigDecimal.valueOf(this.getCost()).toString()); sj.add("totalDuration=" + this.getOptimizationTime().toString()); lstPhases.forEach(ph -> sj.add("phase=" + ph.getId().toString()).add("duration=" + ph.getDuration())); lstSolutions.forEach(s -> sj.add("jobClass=" + s.getId()).add("typeVM=" + s.getTypeVMselected().getId()) .add("numVM=" + s.getNumberVM()).add("numReserved=" + s.getNumReservedVM()) .add("numOnDemand=" + s.getNumOnDemandVM()).add("numSpot=" + s.getNumSpotVM()) .add("jobFeas=" + s.getFeasible().toString())); return sj.toString(); }