List of usage examples for java.lang StringBuffer deleteCharAt
@Override public synchronized StringBuffer deleteCharAt(int index)
From source file:com.fluidinfo.fom.Object.java
/** * Tag this object with the passed Tag instance and the associated string array value * @param tag the tag to associate with this object * @param value the string array value of the tag on this object * @throws FluidException/*from w w w . jav a 2 s.co m*/ * @throws IOException */ public void tag(Tag tag, String[] values) throws FluidException, IOException { StringBuffer jsonArray = new StringBuffer(); jsonArray.append("[ "); for (int i = 0; i < values.length; i++) { jsonArray.append(JSONObject.quote(values[i])); jsonArray.append(","); } jsonArray.deleteCharAt(jsonArray.length() - 1); jsonArray.append(" ]"); this.tagPrimitive(tag, jsonArray.toString()); }
From source file:org.latticesoft.util.container.tree.impl.NodeImpl.java
public String getHierarchicalListName() { List l = this.getHierarchicalList(); StringBuffer sb = new StringBuffer(); for (int i = 0; i < l.size(); i++) { Node n = (Node) l.get(i); sb.append(n.getName());/*from w w w.java 2 s .c o m*/ sb.append("-"); } if (sb.length() > 0) { sb.deleteCharAt(sb.length() - 1); } return sb.toString(); }
From source file:dk.netarkivet.common.utils.FileUtils.java
/** * @param theFile//from w w w.j ava 2 s .com * A file to make relative * @param theDir * A directory * @return the filepath of the theFile relative to theDir. null, if * theFile is not relative to theDir. null, if theDir is not a * directory. */ public static String relativeTo(File theFile, File theDir) { ArgumentNotValid.checkNotNull(theFile, "File theFile"); ArgumentNotValid.checkNotNull(theDir, "File theDir"); if (!theDir.isDirectory()) { log.trace("The File '" + theDir.getAbsolutePath() + "' does not represent a directory. Null returned"); return null; } List<String> filePathList = new ArrayList<String>(); List<String> theDirPath = new ArrayList<String>(); File tempFile = theFile.getAbsoluteFile(); filePathList.add(tempFile.getName()); while ((tempFile = tempFile.getParentFile()) != null) { filePathList.add(tempFile.getName()); } tempFile = theDir.getAbsoluteFile(); theDirPath.add(tempFile.getName()); while ((tempFile = tempFile.getParentFile()) != null) { theDirPath.add(tempFile.getName()); } // check, at the path prefix is the same List<String> sublist = filePathList.subList(theDirPath.size() - 2, filePathList.size()); if (!theDirPath.equals(sublist)) { log.trace("The file '" + theFile.getAbsolutePath() + "' is not relative to the directory '" + theDir.getAbsolutePath() + "'. Null returned"); return null; } List<String> relativeList = filePathList.subList(0, theDirPath.size() - 2); StringBuffer sb = new StringBuffer(); Collections.reverse(relativeList); for (String aRelativeList : relativeList) { sb.append(aRelativeList); sb.append(File.separatorChar); } sb.deleteCharAt(sb.length() - 1); // remove last separatorChar return sb.toString(); }
From source file:org.eclipse.datatools.connectivity.sample.ftp.internal.FTPFileObject.java
public String getName() { StringBuffer sb = new StringBuffer(); FTPFileObject parent = this; while (parent != null) { sb.insert(0, "/" + parent.getFTPFile().getName()); if (parent.getParent() instanceof FTPFileObject) { parent = (FTPFileObject) parent.getParent(); } else {//from w w w . j a va2 s. c o m parent = null; } } while (sb.charAt(0) == '/') { sb.deleteCharAt(0); } return sb.toString(); }
From source file:org.apache.axis2.fastinfoset.FastInfosetMessageFormatter.java
/** * Construct URL parameters like, "param1=value1¶m2=value2" * FIXME This is very HTTP specific. What about other transports * /*from w w w . j av a 2 s.c om*/ * @param messageContext * @return Formatted URL parameters */ private String getParam(MessageContext messageContext) { OMElement dataOut = messageContext.getEnvelope().getBody().getFirstElement(); Iterator it = dataOut.getChildElements(); StringBuffer paramBuffer = new StringBuffer(); while (it.hasNext()) { OMElement element = (OMElement) it.next(); String parameter = element.getLocalName() + "=" + element.getText(); paramBuffer.append(parameter); paramBuffer.append("&"); } //We don't need a '&' at the end paramBuffer.deleteCharAt(paramBuffer.length() - 1); return paramBuffer.toString(); }
From source file:org.zebrafish.feature.AbstractFieldList.java
public String toURLString() { if (isEmpty()) { return StringUtils.EMPTY; }// www .j av a 2s .c o m StringBuffer sb = createStringBuffer(); for (T t : this) { String fieldURLString = t.toURLString(); if (StringUtils.isNotEmpty(fieldURLString)) { sb.append(fieldURLString); sb.append(getSeparator()); } } return sb.charAt(sb.length() - 1) == Separator.EQUAL.getSymbol() ? StringUtils.EMPTY : sb.deleteCharAt(sb.length() - 1).toString(); }
From source file:net.sf.jabref.sql.importer.DBImporter.java
/** * Worker method to perform the import from a database * * @param dbs The necessary database connection information * @param mode//from w w w . j a v a 2s . c om * @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 Exception */ public List<DBImporterResult> performImport(DBStrings dbs, List<String> listOfDBs, BibDatabaseMode mode) throws Exception { List<DBImporterResult> result = new ArrayList<>(); try (Connection conn = this.connectToDB(dbs)) { Iterator<String> itLista = listOfDBs.iterator(); StringBuffer jabrefDBsb = new StringBuffer(); jabrefDBsb.append('('); while (itLista.hasNext()) { jabrefDBsb.append('\'').append(itLista.next()).append("',"); } jabrefDBsb.deleteCharAt(jabrefDBsb.length() - 1).append(')'); try (Statement statement = SQLUtil.queryAllFromTable(conn, "jabref_database WHERE database_name IN " + jabrefDBsb.toString()); ResultSet rsDatabase = statement.getResultSet()) { 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 = SQLUtil.queryAllFromTable(conn, "entry_types"); ResultSet rsEntryType = entryTypes.getResultSet()) { while (rsEntryType.next()) { Optional<EntryType> entryType = EntryTypes.getType(rsEntryType.getString("label"), mode); if (entryType.isPresent()) { types.put(rsEntryType.getString("entry_types_id"), entryType.get()); } } rsEntryType.getStatement().close(); } List<String> colNames = this.readColumnNames(conn).stream() .filter(column -> !columnsNotConsideredForEntries.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 = SQLUtil.queryAllFromTable(conn, "entries WHERE database_id= '" + database_id + "';"); ResultSet rsEntries = entryStatement.getResultSet()) { while (rsEntries.next()) { String id = rsEntries.getString("entries_id"); BibEntry entry = new BibEntry(IdGenerator.next(), types.get(rsEntries.getString("entry_types_id")).getName()); entry.setField(BibEntry.KEY_FIELD, 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); } rsEntries.getStatement().close(); } // Import strings and preamble: try (Statement stringStatement = SQLUtil.queryAllFromTable(conn, "strings WHERE database_id='" + database_id + '\''); ResultSet rsStrings = stringStatement.getResultSet()) { 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); } } rsStrings.getStatement().close(); } 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:org.zebrafish.util.ChartHelper.java
/** * Encodes data.//from ww w . j a va 2s . c o m * * @param dataList the data list needed to be encoded * @return an encoded string */ public static String encodeData(DataList dataList) { StringBuffer sb = new StringBuffer(128); StringBuffer sbTmp = new StringBuffer(32); EncodingType type = dataList.getType(); for (Data data : dataList) { float[] content = data.getContent(); if (content == null || content.length == 0) { sb.append(type.getMissingValue()).append(type.getSymbol()); continue; } if (dataList.isAutoScale()) { content = autoDataScale(content, 0, type.getMax()); } sbTmp.setLength(0); try { for (float f : content) { switch (type) { case TEXT: sbTmp.append(TEXT_ENCODING_FOMART.format(f)).append(","); break; case SIMPLE: sbTmp.append(SIMPLE_ENCODING.charAt(Math.round(f) % SIMPLE_ENCODING_LENGTH)); break; case EXTENDED: int k = Math.round(f); sbTmp.append(EXTENDED_ENCODING.charAt(k / EXTENDED_ENCODING_LENGTH)); sbTmp.append(EXTENDED_ENCODING.charAt(k % EXTENDED_ENCODING_LENGTH)); } } if (type == EncodingType.TEXT) { sbTmp.deleteCharAt(sbTmp.length() - 1); } sb.append(sbTmp).append(type.getSymbol()); } catch (Exception e) { sb.append(type.getMissingValue()).append(type.getSymbol()); } } return sb.toString(); }
From source file:com.wabacus.util.TestFileUploadInterceptor.java
/** * ??/??????// ww w .j a va2 s.c om */ public boolean beforeDisplayFileUploadPrompt(HttpServletRequest request, List lstFieldItems, Map<String, String> mFormAndConfigValues, String failedMessage, PrintWriter out) { if (lstFieldItems == null || lstFieldItems.size() == 0) return true; FileItem fItemTmp; StringBuffer fileNamesBuf = new StringBuffer(); for (int i = 0; i < lstFieldItems.size(); i++) { fItemTmp = (FileItem) lstFieldItems.get(i); if (fItemTmp.isFormField()) continue;//? fileNamesBuf.append(fItemTmp.getName()).append(";"); } if (fileNamesBuf.charAt(fileNamesBuf.length() - 1) == ';') fileNamesBuf.deleteCharAt(fileNamesBuf.length() - 1); if (failedMessage != null && !failedMessage.trim().equals("")) {// out.println("<h4>??" + fileNamesBuf.toString() + "" + failedMessage + "</h4>"); } else {//? out.println("<script language='javascript'>"); out.println("alert('" + fileNamesBuf.toString() + "?');"); String inputboxid = mFormAndConfigValues.get("INPUTBOXID"); if (inputboxid != null && !inputboxid.trim().equals("")) {//? String name = mFormAndConfigValues.get("param_name"); name = name + "[" + fileNamesBuf.toString() + "]"; out.println("selectOK('" + name + "','name',null,true);"); } out.println("</script>"); } return false;//???? }
From source file:be.ibridge.kettle.trans.step.textfileinput.TextFileInput.java
public static final Value convertValue(String pol, String field_name, int field_type, String field_format, int field_length, int field_precision, String num_group, String num_decimal, String num_currency, String nullif, String ifNull, int trim_type, DecimalFormat ldf, DecimalFormatSymbols ldfs, SimpleDateFormat ldaf, DateFormatSymbols ldafs) throws Exception { Value value = new Value(field_name, field_type); // build a value! // If no nullif field is supplied, take the default. String null_value = nullif;/*from ww w .ja v a2 s. co m*/ if (null_value == null) { switch (field_type) { case Value.VALUE_TYPE_BOOLEAN: null_value = Const.NULL_BOOLEAN; break; case Value.VALUE_TYPE_STRING: null_value = Const.NULL_STRING; break; case Value.VALUE_TYPE_BIGNUMBER: null_value = Const.NULL_BIGNUMBER; break; case Value.VALUE_TYPE_NUMBER: null_value = Const.NULL_NUMBER; break; case Value.VALUE_TYPE_INTEGER: null_value = Const.NULL_INTEGER; break; case Value.VALUE_TYPE_DATE: null_value = Const.NULL_DATE; break; case Value.VALUE_TYPE_BINARY: null_value = Const.NULL_BINARY; break; default: null_value = Const.NULL_NONE; break; } } String null_cmp = Const.rightPad(new StringBuffer(null_value), pol.length()); if (pol == null || pol.length() == 0 || pol.equalsIgnoreCase(null_cmp)) { if (ifNull != null && ifNull.length() != 0) pol = ifNull; } if (pol == null || pol.length() == 0 || pol.equalsIgnoreCase(null_cmp)) { value.setNull(); } else { if (value.isNumeric()) { try { StringBuffer strpol = new StringBuffer(pol); switch (trim_type) { case TextFileInputMeta.TYPE_TRIM_LEFT: while (strpol.length() > 0 && strpol.charAt(0) == ' ') strpol.deleteCharAt(0); break; case TextFileInputMeta.TYPE_TRIM_RIGHT: while (strpol.length() > 0 && strpol.charAt(strpol.length() - 1) == ' ') strpol.deleteCharAt(strpol.length() - 1); break; case TextFileInputMeta.TYPE_TRIM_BOTH: while (strpol.length() > 0 && strpol.charAt(0) == ' ') strpol.deleteCharAt(0); while (strpol.length() > 0 && strpol.charAt(strpol.length() - 1) == ' ') strpol.deleteCharAt(strpol.length() - 1); break; default: break; } pol = strpol.toString(); if (value.isNumber()) { if (field_format != null) { ldf.applyPattern(field_format); if (num_decimal != null && num_decimal.length() >= 1) ldfs.setDecimalSeparator(num_decimal.charAt(0)); if (num_group != null && num_group.length() >= 1) ldfs.setGroupingSeparator(num_group.charAt(0)); if (num_currency != null && num_currency.length() >= 1) ldfs.setCurrencySymbol(num_currency); ldf.setDecimalFormatSymbols(ldfs); } value.setValue(ldf.parse(pol).doubleValue()); } else { if (value.isInteger()) { value.setValue(Long.parseLong(pol)); } else { if (value.isBigNumber()) { value.setValue(new BigDecimal(pol)); } else { throw new KettleValueException("Unknown numeric type: contact vendor!"); } } } } catch (Exception e) { throw (e); } } else { if (value.isString()) { value.setValue(pol); switch (trim_type) { case TextFileInputMeta.TYPE_TRIM_LEFT: value.ltrim(); break; case TextFileInputMeta.TYPE_TRIM_RIGHT: value.rtrim(); break; case TextFileInputMeta.TYPE_TRIM_BOTH: value.trim(); break; default: break; } if (pol.length() == 0) value.setNull(); } else { if (value.isDate()) { try { if (field_format != null) { ldaf.applyPattern(field_format); ldaf.setDateFormatSymbols(ldafs); } value.setValue(ldaf.parse(pol)); } catch (Exception e) { throw (e); } } else { if (value.isBinary()) { value.setValue(pol.getBytes()); } } } } } value.setLength(field_length, field_precision); return value; }