List of usage examples for java.lang StringBuilder delete
@Override public StringBuilder delete(int start, int end)
From source file:com.flowpowered.commons.datatable.SerializableHashMap.java
@Override public String toString() { StringBuilder toString = new StringBuilder("DataMap {"); for (Map.Entry<? extends String, ? extends Serializable> e : entrySet()) { toString.append("("); toString.append(e.getKey());//from ww w.j a v a 2 s .c om toString.append(", "); toString.append(e.getValue()); toString.append("), "); } toString.delete(toString.length() - 3, toString.length()); toString.append("}"); return toString.toString(); }
From source file:ark.model.SupervisedModelCreg.java
private boolean outputXData(String outputPath, FeaturizedDataSet<D, L> data, boolean requireLabels) { try {//from w w w. j a va2s . c om BufferedWriter writer = new BufferedWriter(new FileWriter(outputPath)); for (D datum : data) { L label = mapValidLabel(datum.getLabel()); if (requireLabels && label == null) continue; Map<Integer, Double> featureValues = data.getFeatureVocabularyValuesAsMap(datum); Map<Integer, String> featureNames = data .getFeatureVocabularyNamesForIndices(featureValues.keySet()); StringBuilder datumStr = new StringBuilder(); datumStr = datumStr.append("id").append(datum.getId()).append("\t{"); for (Entry<Integer, Double> feature : featureValues.entrySet()) { datumStr = datumStr.append("\"").append(featureNames.get(feature.getKey())).append("\": ") .append(feature.getValue()).append(", "); } if (featureValues.size() > 0) { datumStr = datumStr.delete(datumStr.length() - 2, datumStr.length()); } datumStr = datumStr.append("}"); writer.write(datumStr.toString()); writer.write("\n"); } writer.close(); return true; } catch (IOException e) { e.printStackTrace(); return false; } }
From source file:com.haulmont.cuba.desktop.gui.components.DesktopTimeField.java
@Override public void setShowSeconds(boolean showSeconds) { this.showSeconds = showSeconds; if (showSeconds) { if (!timeFormat.contains("ss")) { int minutesIndex = timeFormat.indexOf("mm"); StringBuilder builder = new StringBuilder(timeFormat); builder.insert(minutesIndex + 2, ":ss"); timeFormat = builder.toString(); }/* w ww.j a v a2 s .c o m*/ } else { if (timeFormat.contains("ss")) { int secondsIndex = timeFormat.indexOf("ss"); StringBuilder builder = new StringBuilder(timeFormat); builder.delete(secondsIndex > 0 ? --secondsIndex : secondsIndex, secondsIndex + 3); timeFormat = builder.toString(); } } updateTimeFormat(); updateWidth(); }
From source file:org.matsim.counts.algorithms.CountSimComparisonKMLWriter.java
/** * Creates a placemark//from w w w. j a v a 2 s .com * * @param linkid * @param csc * @param relativeError * @param timestep * @return the Placemark instance with description and name set */ private PlacemarkType createPlacemark(final String linkid, final CountSimComparison csc, final double relativeError, final int timestep) { StringBuilder stringBuffer = new StringBuilder(); PlacemarkType placemark = kmlObjectFactory.createPlacemarkType(); stringBuffer.delete(0, stringBuffer.length()); stringBuffer.append(LINK); stringBuffer.append(linkid); placemark.setDescription(createPlacemarkDescription(linkid, csc, relativeError, timestep)); return placemark; }
From source file:com.haulmont.cuba.desktop.gui.components.DesktopDateField.java
@Override public void setDateFormat(String dateFormat) { dateTimeFormat = dateFormat;/*w w w . ja va2s . c om*/ StringBuilder date = new StringBuilder(dateFormat); StringBuilder time = new StringBuilder(dateFormat); int timeStartPos = findTimeStartPos(dateFormat); if (timeStartPos >= 0) { time.delete(0, timeStartPos); timeFormat = StringUtils.trimToEmpty(time.toString()); timeField.setFormat(timeFormat); _setResolution(resolution); date.delete(timeStartPos, dateFormat.length()); } else if (resolution.ordinal() < Resolution.DAY.ordinal()) { _setResolution(Resolution.DAY); } this.dateFormat = StringUtils.trimToEmpty(date.toString()); datePicker.setFormats(this.dateFormat); updateLayout(); }
From source file:it.unibas.spicy.model.algebra.query.operators.sql.GenerateSQL.java
public static String generateFromClause(List<SetAlias> variables, int chainingStep) { StringBuilder result = new StringBuilder(); result.append("from "); List<String> addedVariables = new ArrayList<String>(); for (int i = 0; i < variables.size(); i++) { SetAlias variable = variables.get(i); String relationName = GenerateSQL.sourceRelationName(variable, chainingStep); String aliasRelationName = GenerateSQL.RELATION_ALIAS_PREFIX + variable.toShortString(); // NOTE: we are preventing to reuse the same variable twice in the from clause // this might not be correct in all cases if (!addedVariables.contains(aliasRelationName)) { addedVariables.add(aliasRelationName); result.append(relationName).append(" AS ").append(aliasRelationName); // if (i != variables.size() - 1) result.append(", "); result.append(", "); }//from w w w .ja v a 2 s . co m } result.delete(result.length() - ", ".length(), result.length() - 1); result.append("\n"); return result.toString(); }
From source file:com.github.mikanbako.checkstyle.commentedpackagevisibilitycheck.CommentedPackageVisibilityCheck.java
/** * Get string of checking target.// w w w . j a v a2s . c om * * @param aStart Start position of checking target. * @param aEnd End position of checking target. * @return String of checking target. */ private String getCheckingTargetString(LineColumn aStart, LineColumn aEnd) { final StringBuilder targetStringBuilder = new StringBuilder(); final String[] targetLines = getLines(); // Combine lines. for (int lineNumber = aStart.getLine(); lineNumber <= aEnd.getLine(); lineNumber++) { final int lineIndex = lineNumber - 1; targetStringBuilder.append(targetLines[lineIndex]); if (lineNumber < aEnd.getLine()) { targetStringBuilder.append('\n'); } } // Delete redundant characters at last line. final int endDeletingCount = (targetLines[aEnd.getLine() - 1].length() - 1) - aEnd.getColumn(); targetStringBuilder.delete(targetStringBuilder.length() - endDeletingCount, targetStringBuilder.length()) .delete(0, aStart.getColumn()); return targetStringBuilder.toString(); }
From source file:com.epam.dlab.module.ParserCsv.java
@Override public List<String> parseRow(String line) throws ParseException { int realPos = 0; int pos = 0;/*from ww w. j av a2 s . com*/ boolean isDelimiter = false; StringBuilder sb = new StringBuilder(line); List<String> row = new ArrayList<String>(); while (pos < sb.length()) { char c = sb.charAt(pos); /* LOGGER.debug("Current buffer {}", sb); LOGGER.debug("pos {}", pos); LOGGER.debug("isDelimiter {}", isDelimiter); */ if (c == escapeChar) { realPos++; pos++; if (pos == sb.length()) { throw getParseException("Invalid escape char", realPos, line); } sb.delete(pos - 1, pos); realPos++; } else if (c == fieldTerminator) { realPos++; if (isDelimiter) { realPos++; pos++; if (pos == sb.length()) { sb.delete(pos - 1, pos); break; } if (sb.charAt(pos) == fieldSeparator) { row.add(sb.substring(0, pos - 1)); sb.delete(0, pos + 1); pos = 0; isDelimiter = false; continue; } throw getParseException("Invalid field delimiter", realPos, line); } if (pos != 0) { throw getParseException("Unterminated field", realPos, line); } sb.delete(0, 1); isDelimiter = true; continue; } else if (c == fieldSeparator) { realPos++; if (isDelimiter) { pos++; continue; } row.add(sb.substring(0, pos)); sb.delete(0, pos + 1); pos = 0; } else { realPos++; pos++; } } row.add(sb.toString()); return row; }
From source file:org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDaoImpl.java
/** * Return SQL string from details, to be placed between SQL Prefix and SQL Suffix when creating storage tags PreparedStatement. * @param details storage pool details//www . jav a2 s. c o m * @return SQL string containing storage tag values to be Prefix and Suffix when creating PreparedStatement. * @throws NullPointerException if details is null * @throws IndexOutOfBoundsException if details is not null, but empty */ protected String getSqlValuesFromDetails(Map<String, String> details) { StringBuilder sqlValues = new StringBuilder(); for (Map.Entry<String, String> detail : details.entrySet()) { sqlValues.append("((storage_pool_details.name='").append(detail.getKey()) .append("') AND (storage_pool_details.value='").append(detail.getValue()).append("')) OR "); } sqlValues.delete(sqlValues.length() - 4, sqlValues.length()); return sqlValues.toString(); }
From source file:org.apache.tajo.cli.tsql.commands.DescTableCommand.java
@Override public void invoke(String[] cmd) throws TajoException { if (cmd.length >= 2) { StringBuilder tableNameMaker = new StringBuilder(); for (int i = 1; i < cmd.length; i++) { if (i != 1) { tableNameMaker.append(" "); }/*w w w .j ava 2s. com*/ tableNameMaker.append(cmd[i]); } String tableName = tableNameMaker.toString().replace("\"", ""); TableDesc desc = client.getTableDesc(tableName); if (desc == null) { context.getError().println("Did not find any relation named \"" + tableName + "\""); } else { context.getOutput().println(toFormattedString(desc)); // If there exists any indexes for the table, print index information if (client.hasIndexes(tableName)) { StringBuilder sb = new StringBuilder(); sb.append("Indexes:\n"); for (IndexDescProto index : client.getIndexes(tableName)) { sb.append("\"").append(index.getIndexName()).append("\" "); sb.append(index.getIndexMethod()).append(" ("); for (SortSpecProto key : index.getKeySortSpecsList()) { sb.append(IdentifierUtil.extractSimpleName(key.getColumn().getName())); sb.append(key.getAscending() ? " ASC" : " DESC"); sb.append(key.getNullFirst() ? " NULLS FIRST, " : " NULLS LAST, "); } sb.delete(sb.length() - 2, sb.length() - 1).append(")\n"); } context.getOutput().println(sb.toString()); } } } else if (cmd.length == 1) { List<String> tableList = client.getTableList(null); if (tableList.size() == 0) { context.getError().println("No Relation Found"); } for (String table : tableList) { context.getOutput().println(table); } } else { throw new IllegalArgumentException(); } }