List of usage examples for java.lang StringBuilder deleteCharAt
@Override public StringBuilder deleteCharAt(int index)
From source file:net.sf.jclal.classifier.WekaComitteClassifier.java
/** * The simple names of the classifiers./*from w ww. j a v a 2 s. c o m*/ * * @return The string of the object. */ @Override public String toString() { StringBuilder st = new StringBuilder(); for (Classifier cl : classifiers) { st.append(cl.getClass().getSimpleName() + "-"); } st.deleteCharAt(st.length() - 1); return st.toString(); }
From source file:com.github.lightdocs.ModelBuilder.java
@VisibleForTesting String buildEffectiveURIFor(String sbClass, String sbMethod) { StringBuilder sb = new StringBuilder("/"); if (StringUtils.isNotBlank(sbClass)) { sb.append(sbClass).append("/"); }/*from ww w. ja va 2 s .c om*/ if (StringUtils.isNotBlank(sbMethod)) { sb.append(sbMethod); } if (sb.lastIndexOf("/") == sb.length() - 1) { sb.deleteCharAt(sb.length() - 1); } return sb.toString(); }
From source file:io.vertx.ext.shell.term.TelnetTermServerTest.java
@Test public void testWrite(TestContext context) throws IOException { startTelnet(context, term -> {/*from w w w .j a v a2s. c o m*/ term.write("hello_from_server"); }); client.connect("localhost", server.actualPort()); Reader reader = new InputStreamReader(client.getInputStream()); StringBuilder sb = new StringBuilder("hello_from_server"); while (sb.length() > 0) { int c = reader.read(); context.assertNotEquals(-1, c); context.assertEquals(c, (int) sb.charAt(0)); sb.deleteCharAt(0); } }
From source file:com.aurel.track.prop.LoginBL.java
private static String getUserProperties(TPersonBean personBean) { StringBuilder sb = new StringBuilder(); sb.append("{"); Map<Integer, Boolean> userLevelSpecificMap = UserLevelsProxy.getInstance() .getMapByUserLevel(personBean.getUserLevel()); for (Integer propertyKey : userLevelSpecificMap.keySet()) { String convertedValue = convertUserPropIDToUserPropString(propertyKey); if (convertedValue != null) { JSONUtility.appendBooleanValue(sb, convertedValue, userLevelSpecificMap.get(propertyKey)); }/*w ww. j ava2s . c o m*/ } sb.deleteCharAt(sb.length() - 1); sb.append("}"); return sb.toString(); }
From source file:org.jasig.ssp.util.importer.job.staging.PostgresExternalTableUpsertWriter.java
@Override public void write(List<? extends RawItem> items) throws Exception { JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); List<String> batchedStatements = new ArrayList<String>(); String fileName = items.get(0).getResource().getFilename(); String[] fileNameSplit = fileName.split("\\."); String tableName = fileNameSplit[0]; Object batchStart = stepExecution.getExecutionContext().get("batchStart"); Object batchStop = stepExecution.getExecutionContext().get("batchStop"); RawItem item = items.get(0);//from w w w .j a va 2s .c o m if (currentResource == null) { this.orderedHeaders = writeHeader(items.get(0)); this.currentResource = items.get(0).getResource(); } Resource itemResource = item.getResource(); if (!(this.currentResource.equals(itemResource))) { this.orderedHeaders = writeHeader(item); this.currentResource = itemResource; } StringBuilder updateSql = new StringBuilder(); updateSql.append(" UPDATE " + tableName + " AS target SET "); for (String header : this.orderedHeaders) { updateSql.append(header + "=source." + header + ","); } updateSql.deleteCharAt(updateSql.lastIndexOf(",")); updateSql.append(" FROM stg_" + tableName + " AS source WHERE "); List<String> tableKeys = metadataRepository.getRepository().getColumnMetadataRepository() .getTableMetadata(new TableReference(tableName)).getTableKeys(); // There are a few external tables that don't (yet) have natural keys, // in these cases we've enforced the key on the staging table // so in cases where the external table does not have any keys, we look // towards the corresponding staging table for them if (tableKeys.isEmpty()) { tableKeys = metadataRepository.getRepository().getColumnMetadataRepository() .getTableMetadata(new TableReference("stg_" + tableName)).getTableKeys(); } for (String key : tableKeys) { updateSql.append(" target." + key + " = source." + key + " AND "); } updateSql.append(" source.batch_id >= " + batchStart + " and source.batch_id <= " + batchStop + ";"); batchedStatements.add(updateSql.toString()); sayQuery(updateSql); StringBuilder insertSql = new StringBuilder(); insertSql.append(" INSERT INTO " + tableName + "("); for (String header : this.orderedHeaders) { insertSql.append(header + ","); } insertSql.setLength(insertSql.length() - 1); // trim comma insertSql.append(") SELECT "); for (String header : this.orderedHeaders) { insertSql.append(" source." + header).append(","); } insertSql.setLength(insertSql.length() - 1); // trim comma insertSql.append(" FROM stg_" + tableName + " AS source "); insertSql.append(" LEFT OUTER JOIN " + tableName + " AS target ON "); for (String key : tableKeys) { insertSql.append(" source." + key + " = target." + key + " AND"); } insertSql.setLength(insertSql.length() - 3); // trim comma insertSql.append(" WHERE "); for (String key : tableKeys) { insertSql.append(" target." + key + " IS NULL AND "); } insertSql.append(" source.batch_id >= " + batchStart + " and source.batch_id <= " + batchStop + ""); batchedStatements.add(insertSql.toString()); sayQuery(insertSql); try { int[] results = jdbcTemplate.batchUpdate(batchedStatements.toArray(new String[] {})); Integer numInsertedUpdated = (Integer) stepExecution.getExecutionContext().get("numInsertedUpdated"); numInsertedUpdated = numInsertedUpdated == null ? 0 : numInsertedUpdated; numInsertedUpdated = numInsertedUpdated + results[0] + results[1]; stepExecution.getExecutionContext().put("numInsertedUpdated", numInsertedUpdated); } catch (Exception e) { throw new NotSkippableException(e); } }
From source file:net.duckling.ddl.service.resource.dao.TagItemDAOImpl.java
@Override public List<TagItem> getItemsInTags(int[] tgids, int offset, int size) { if (offset < 0 || size < 0 || (size == 0 && offset > 0)) { LOG.error("offset and size should be positive while query, however, in this query, " + "offset = " + offset + ", size = " + size); return new ArrayList<TagItem>(); }/* w w w.ja v a 2 s . c om*/ int len = tgids.length; String condition = ""; if (len > 0) { StringBuilder sb = new StringBuilder(); sb.append(" where tgid in("); for (int i = 0; i < tgids.length; i++) { sb.append(tgids[i] + ","); } sb.deleteCharAt(sb.length() - 1); sb.append(")"); condition = sb.toString(); } String limit = ""; if (offset >= 0 && size > 0) { limit = " limit " + offset + "," + size; } String sql = SQL_QUERY + condition + limit; return this.getJdbcTemplate().query(sql, tagItemRowMapper); }
From source file:fr.paris.lutece.plugins.directory.modules.rest.rs.DirectoryRest.java
/** * Get the wadl.xml content// w ww .ja v a2 s. c o m * @param request {@link HttpServletRequest} * @return the content of wadl.xml */ @GET @Path(DirectoryRestConstants.PATH_WADL) @Produces(MediaType.APPLICATION_XML) public String getWADL(@Context HttpServletRequest request) { StringBuilder sbBase = new StringBuilder(AppPathService.getBaseUrl(request)); if (sbBase.toString().endsWith(DirectoryRestConstants.SLASH)) { sbBase.deleteCharAt(sbBase.length() - 1); } sbBase.append(RestConstants.BASE_PATH + DirectoryPlugin.PLUGIN_NAME); Map<String, Object> model = new HashMap<String, Object>(); model.put(DirectoryRestConstants.MARK_BASE_URL, sbBase.toString()); HtmlTemplate t = AppTemplateService.getTemplate(DirectoryRestConstants.TEMPLATE_WADL, request.getLocale(), model); return t.getHtml(); }
From source file:at.pcgamingfreaks.Bukkit.RegisterablePluginCommand.java
/** * {@inheritDoc}/*ww w . ja v a2s. c o m*/ * * Delegates to the tab completer if present. * * If it is not present or returns null, will delegate to the current * command executor if it implements {@link TabCompleter}. If a non-null * list has not been found, will default to standard player name * completion in {@link * Command#tabComplete(CommandSender, String, String[])}. * * This method does not consider permissions. * * @throws CommandException if the completer or executor throw an exception during the process of tab-completing. * @throws IllegalArgumentException if sender, alias, or args is null */ @Override public List<String> tabComplete(CommandSender sender, String alias, String[] args) throws CommandException, IllegalArgumentException { Validate.notNull(sender, "Sender cannot be null"); Validate.notNull(args, "Arguments cannot be null"); Validate.notNull(alias, "Alias cannot be null"); List<String> completions = null; try { if (completer != null) { completions = completer.onTabComplete(sender, this, alias, args); } if (completions == null && executor instanceof TabCompleter) { completions = ((TabCompleter) executor).onTabComplete(sender, this, alias, args); } } catch (Throwable ex) { StringBuilder message = new StringBuilder(); message.append("Unhandled exception during tab completion for command '/").append(alias).append(' '); for (String arg : args) { message.append(arg).append(' '); } message.deleteCharAt(message.length() - 1).append("' in plugin ") .append(owningPlugin.getDescription().getFullName()); throw new CommandException(message.toString(), ex); } if (completions == null) { return super.tabComplete(sender, alias, args); } return completions; }
From source file:gtu._work.etc.GoogleContactUI.java
void googleTableMouseClicked(MouseEvent evt) { try {/* w ww.j a v a2 s. co m*/ JPopupMenuUtil popupUtil = JPopupMenuUtil.newInstance(googleTable).applyEvent(evt); //CHANGE ENCODE popupUtil.addJMenuItem("set encode", new ActionListener() { public void actionPerformed(ActionEvent e) { try { String code = StringUtils.defaultString(JOptionPaneUtil.newInstance().iconPlainMessage() .showInputDialog("input file encode", "ENCODE"), "UTF8"); encode = Charset.forName(code).displayName(); } catch (Exception ex) { JCommonUtil.handleException(ex); } System.err.println("encode : " + encode); } }); //SIMPLE LOAD GOOGLE CSV FILE popupUtil.addJMenuItem("open Google CSV file", new ActionListener() { public void actionPerformed(ActionEvent e) { File file = JFileChooserUtil.newInstance().selectFileOnly().addAcceptFile("csv", ".csv") .showOpenDialog().getApproveSelectedFile(); if (file == null) { errorMessage("file is not correct!"); return; } try { if (file.getName().endsWith(".csv")) { DefaultTableModel model = (DefaultTableModel) googleTable.getModel(); LineNumberReader reader = new LineNumberReader( new InputStreamReader(new FileInputStream(file), GOOGLE_CVS_ENCODE)); for (String line = null; (line = reader.readLine()) != null;) { if (reader.getLineNumber() == 1) { continue; } model.addRow(line.split(",")); } reader.close(); googleTable.setModel(model); JTableUtil.newInstance(googleTable).hiddenAllEmptyColumn(); } } catch (Exception ex) { JCommonUtil.handleException(ex); } } }); //SAVE CSV FILE FOR GOOGLE popupUtil.addJMenuItem("save to Google CVS file", new ActionListener() { public void actionPerformed(ActionEvent e) { File file = JFileChooserUtil.newInstance().selectFileOnly().addAcceptFile(".csv", ".csv") .showSaveDialog().getApproveSelectedFile(); if (file == null) { errorMessage("file is not correct!"); return; } file = FileUtil.getIndicateFileExtension(file, ".csv"); try { BufferedWriter writer = new BufferedWriter( new OutputStreamWriter(new FileOutputStream(file), GOOGLE_CVS_ENCODE)); StringBuilder sb = new StringBuilder(); for (Object title : googleColumns) { sb.append(title + ","); } sb.deleteCharAt(sb.length() - 1); System.out.println(sb); writer.write(sb.toString()); writer.newLine(); DefaultTableModel model = (DefaultTableModel) googleTable.getModel(); for (int row = 0; row < model.getRowCount(); row++) { sb = new StringBuilder(); for (int col = 0; col < model.getColumnCount(); col++) { String colVal = StringUtils.defaultString((String) model.getValueAt(row, col), ""); if (colVal.equalsIgnoreCase("null")) { colVal = ""; } sb.append(colVal + ","); } sb.deleteCharAt(sb.length() - 1); System.out.println(sb); writer.write(sb.toString()); writer.newLine(); } writer.flush(); writer.close(); } catch (Exception ex) { JCommonUtil.handleException(ex); } } }); //PASTE CLIPBOARD popupUtil.addJMenuItem("paste clipboard", new ActionListener() { public void actionPerformed(ActionEvent paramActionEvent) { JTableUtil.newInstance(googleTable).pasteFromClipboard_multiRowData(true); } }); popupUtil.addJMenuItem("paste clipboard to selected cell", new ActionListener() { public void actionPerformed(ActionEvent paramActionEvent) { JTableUtil.newInstance(googleTable).pasteFromClipboard_singleValueToSelectedCell(); } }); JMenuItem addEmptyRowItem = JTableUtil.newInstance(googleTable).jMenuItem_addRow(false, "add row count?"); addEmptyRowItem.setText("add row"); JMenuItem removeColumnItem = JTableUtil.newInstance(googleTable).jMenuItem_removeColumn(null); removeColumnItem.setText("remove column"); JMenuItem removeRowItem = JTableUtil.newInstance(googleTable).jMenuItem_removeRow(null); removeRowItem.setText("remove row"); JMenuItem removeAllRowItem = JTableUtil.newInstance(googleTable) .jMenuItem_removeAllRow("remove all row?"); removeAllRowItem.setText("remove all row"); JMenuItem clearSelectedCellItem = JTableUtil.newInstance(googleTable) .jMenuItem_clearSelectedCell("are you sure clear selected area?"); clearSelectedCellItem.setText("clear selected area"); popupUtil.addJMenuItem(addEmptyRowItem, removeColumnItem, removeRowItem, removeAllRowItem, clearSelectedCellItem); popupUtil.show(); } catch (Exception ex) { JCommonUtil.handleException(ex); } }
From source file:jongo.sql.dialect.H2Dialect.java
@Override public String toStatementString(Update update) { if (update.getColumns().isEmpty()) throw new IllegalArgumentException("An update query can't be empty"); final StringBuilder b = new StringBuilder("UPDATE "); b.append(update.getTable().getDatabase()).append("."); b.append(update.getTable().getName()).append(" SET "); for (String k : update.getColumns().keySet()) { b.append(update.getTable().getName()).append("."); b.append(k);/*w ww. j av a 2s . c o m*/ b.append("=?,"); } b.deleteCharAt(b.length() - 1); b.append(" WHERE "); b.append(update.getTable().getName()).append("."); b.append(update.getTable().getPrimaryKey()).append("=?"); l.debug(b.toString()); return b.toString(); }