List of usage examples for java.lang StringBuffer deleteCharAt
@Override public synchronized StringBuffer deleteCharAt(int index)
From source file:org.jboss.tusk.smartdata.ejb.SearcherEJB.java
private String pageAndMakeJSON(List<String> results, int from, int to) { if (from < 1 || to < 1 || from > to) { //return all results if from or to is < 1, //or if from > to (ie it's an invalid range), //or if from is greater than the number of results LOG.info("Returning all results because range is either not given or is invalid."); return ispnService.makeJSONFromResultList(results, false); } else {/*from w w w.j a v a 2 s .c o m*/ long start = System.currentTimeMillis(); String completeJSON = ispnService.makeJSONFromResultList(results, false); //this is a hack to do paging, I know, but it's the best I can do on short notice StringBuffer buf = new StringBuffer(); String[] pieces = completeJSON.split("\\{\"key\""); int numItems = pieces.length - 1; //subtract 1 because the first item is empty //the range must not start too high; if so, just return everything if (from > numItems) { return completeJSON; } int effectiveFrom = Math.min(from, numItems); int effectiveTo = Math.min(to, numItems); LOG.info("Paging on " + numItems + " matches with effective from and to of " + effectiveFrom + "-" + effectiveTo + "."); //'to' and 'from' start at 1, so we need to subtract 1 from them to get the corresponding indexes... //but there is also an empty first element of pieces[], so we add 1 back to 'from' and 'to' //and 'from' is inclusive... for (int i = effectiveFrom; i <= effectiveTo; i++) { buf.append("{\"key\"").append(pieces[i]); } //remove trailing ", " if necessary if (buf.lastIndexOf(", ") == (buf.length() - 2)) { buf.deleteCharAt(buf.length() - 2); } LOG.info("Paging took " + (System.currentTimeMillis() - start) + " ms."); return buf.toString(); } }
From source file:com.wabacus.config.component.application.report.ReportDataSetValueBean.java
public String getRealDependsConditionExpression(List<AbsReportDataPojo> lstReportData) { if (!this.isDependentDataSet()) return ""; if (lstReportData == null || lstReportData.size() == 0 || this.dependsConditionExpression == null || this.dependsConditionExpression.trim().equals("")) return ""; String realConExpress = this.dependsConditionExpression; DependingColumnBean dcbeanTmp;/*w w w .j a va 2 s .co m*/ StringBuffer parentValuesBuf = new StringBuffer(); for (Entry<String, DependingColumnBean> entryTmp : this.mDependParents.entrySet()) { dcbeanTmp = entryTmp.getValue(); for (AbsReportDataPojo dataObjTmp : lstReportData) {//?POJO? Object parentColVal = dataObjTmp.getColValue(dcbeanTmp.getParentColumn()); if (parentColVal == null) parentColVal = ""; if (dcbeanTmp.isVarcharType()) parentValuesBuf.append("'"); parentValuesBuf.append(String.valueOf(parentColVal)); if (dcbeanTmp.isVarcharType()) parentValuesBuf.append("'"); parentValuesBuf.append(","); } if (parentValuesBuf.length() > 0 && parentValuesBuf.charAt(parentValuesBuf.length() - 1) == ',') { parentValuesBuf.deleteCharAt(parentValuesBuf.length() - 1); } if (parentValuesBuf.length() == 0 && dcbeanTmp.isVarcharType()) parentValuesBuf.append("''"); realConExpress = Tools.replaceAll(realConExpress, "#" + dcbeanTmp.getParentValueid() + "." + dcbeanTmp.getParentColumn() + "#", parentValuesBuf.toString()); } return realConExpress; }
From source file:com.bigcommerce.http.QueryStringBuilder.java
/** * Returns the encoded URL <code>String</code>. * * @param enc// w ww . j a v a 2 s .c o m * The name of a supported character encoding * * @see URLEncoder#encode(String, String) * @exception UnsupportedEncodingException * If the named encoding is not supported */ public String encode(final String enc) throws UnsupportedEncodingException { StringBuffer buffer = new StringBuffer(); if (this.base != null) { buffer.append(this.base); } if (this.sessionid != null) { buffer.append(";jsessionid=" + this.sessionid); } if (this.parameters.size() > 0) { buffer.append("?"); for (Iterator<Map.Entry<String, NameValuePair>> iter = this.parameters.entrySet().iterator(); iter .hasNext();) { Map.Entry<String, NameValuePair> entry = iter.next(); String value = entry.getValue().getValue(); if (value != null && value.trim().length() > 0) { String encoded = enc == null ? URLEncoder.encode(value, DEFAULT_ENCODING) : URLEncoder.encode(value, enc); buffer.append(entry.getKey()).append("=").append(encoded); buffer.append("&"); } } // remove the last "&", not very elegant but it works buffer.deleteCharAt(buffer.length() - 1); } return buffer.toString(); }
From source file:org.apache.axis2.jaxws.util.BaseWSDLLocator.java
protected String normalizePath(String parentLocation, String relativeLocation) { if (log.isDebugEnabled()) { log.debug(//w ww . j a v a2 s . c o m "normalizePath, parentLocation= " + parentLocation + " relativeLocation= " + relativeLocation); } // Get the path from the module root to the directory containing the importing WSDL file. // Note this path will end in a "/" and will not contain any ".." path components. String pathFromRoot = convertURI(parentLocation); // Construct the path to the location relative to the module root based on the parent location, // removing any ".." or "." path components. StringBuffer pathToRelativeLocation = new StringBuffer(pathFromRoot); StringTokenizer tokenizedRelativeLocation = new StringTokenizer(relativeLocation, WSDL_PATH_SEPERATOR); if (log.isDebugEnabled()) { log.debug("pathFromRoot = " + pathFromRoot); log.debug("relativeLocation = " + relativeLocation); } while (tokenizedRelativeLocation.hasMoreTokens()) { String nextToken = tokenizedRelativeLocation.nextToken(); if (nextToken.equals("..")) { // Relative parent directory, so chop off the last path component in the path to back // up to the parent directory. First delete the trailing "/" from the path if there // is one, then delete characters from the end of the path until we find the next "/". int charToDelete = pathToRelativeLocation.length() - 1; if (pathToRelativeLocation.charAt(charToDelete) == WSDL_PATH_SEPERATOR_CHAR || pathToRelativeLocation.charAt(charToDelete) == '\\') { pathToRelativeLocation.deleteCharAt(charToDelete--); } while (pathToRelativeLocation.charAt(charToDelete) != WSDL_PATH_SEPERATOR_CHAR && pathToRelativeLocation.charAt(charToDelete) != '\\') { pathToRelativeLocation.deleteCharAt(charToDelete--); } } else if (nextToken.equals(".")) { // Relative current directory, do not add or delete any path components } else { // Make sure the current path ends in a "/" or "\\" then append this path component // This handles locations within the module and URIs if ((pathToRelativeLocation.indexOf(String.valueOf(WSDL_PATH_SEPERATOR_CHAR)) != -1) && (pathToRelativeLocation .charAt(pathToRelativeLocation.length() - 1) != WSDL_PATH_SEPERATOR_CHAR)) { pathToRelativeLocation.append(WSDL_PATH_SEPERATOR_CHAR); } // This handles file based locations else if ((pathToRelativeLocation.indexOf("\\") != -1) && (pathToRelativeLocation.charAt(pathToRelativeLocation.length() - 1) != '\\')) { pathToRelativeLocation.append('\\'); } pathToRelativeLocation.append(nextToken); } } if (log.isDebugEnabled()) { log.debug("Built path = " + pathToRelativeLocation.toString()); } return pathToRelativeLocation.toString(); }
From source file:org.apache.roller.weblogger.pojos.WeblogEntry.java
/** * @roller.wrapPojoMethod type="simple"/*from w w w . j a v a 2 s .com*/ */ public String getTagsAsString() { StringBuffer sb = new StringBuffer(); for (Iterator it = getTags().iterator(); it.hasNext();) { sb.append(((WeblogEntryTag) it.next()).getName()).append(" "); } if (sb.length() > 0) { sb.deleteCharAt(sb.length() - 1); } return sb.toString(); }
From source file:edu.ncsa.sstde.indexing.postgis.PostgisIndexer.java
private String createInsertSQL(String tableName, Object[] varNames) { StringBuffer leftHalf = new StringBuffer( "insert into " + tableName + " (" + PostgisIndexerSettings.OID + ","); StringBuffer rightHalf = new StringBuffer("values (?,"); for (Object var : varNames) { leftHalf.append(var).append(','); rightHalf.append('?').append(','); }/*from w ww . jav a 2 s. co m*/ return leftHalf.deleteCharAt(leftHalf.length() - 1).append(") ") .append(rightHalf.deleteCharAt(rightHalf.length() - 1).append(")")).toString(); }
From source file:mvm.rya.indexing.external.tupleSet.AccumuloIndexSet.java
public AccumuloIndexSet(String sparql, SailRepositoryConnection conn, Connector accCon, String tablename) throws MalformedQueryException, SailException, QueryEvaluationException, MutationsRejectedException, TableNotFoundException {/*from w ww. j a va2s .c o m*/ super(null); this.tablename = tablename; this.accCon = accCon; SPARQLParser sp = new SPARQLParser(); ParsedTupleQuery pq = (ParsedTupleQuery) sp.parseQuery(sparql, null); setProjectionExpr((Projection) pq.getTupleExpr()); CloseableIteration<BindingSet, QueryEvaluationException> iter = (CloseableIteration<BindingSet, QueryEvaluationException>) conn .getSailConnection().evaluate(getTupleExpr(), null, new EmptyBindingSet(), false); BatchWriter w = accCon.createBatchWriter(tablename, WRITER_MAX_MEMORY, WRITER_MAX_LATNECY, WRITER_MAX_WRITE_THREADS); this.bindingslist = Lists.newArrayList(pq.getTupleExpr().getAssuredBindingNames()); this.bindings = Maps.newHashMap(); pq.getTupleExpr().visit(new QueryModelVisitorBase<RuntimeException>() { @Override public void meet(Var node) { QueryModelNode parent = node.getParentNode(); if (parent instanceof StatementPattern) { StatementPattern statement = (StatementPattern) parent; if (node.equals(statement.getSubjectVar())) { bindings.put(node.getName(), new AccUrlFactory()); } if (node.equals(statement.getPredicateVar())) { bindings.put(node.getName(), new AccUrlFactory()); } if (node.equals(statement.getObjectVar())) { bindings.put(node.getName(), new AccValueFactoryImpl()); } if (node.equals(statement.getContextVar())) { // TODO is this correct? bindings.put(node.getName(), new AccUrlFactory()); } } else if (parent instanceof ValueExpr) { bindings.put(node.getName(), new AccValueFactoryImpl()); } }; }); varOrder = new ArrayList<String>(bindingslist.size()); while (iter.hasNext()) { BindingSet bs = iter.next(); List<String> shiftBindingList = null; for (int j = 0; j < bindingslist.size(); j++) { StringBuffer sb = new StringBuffer(); shiftBindingList = listShift(bindingslist, j); //TODO calling this each time not efficient String order = ""; for (String b : shiftBindingList) { String val = bindings.get(b).create(bs.getValue(b)); sb.append(val).append("\u0000"); if (order.length() == 0) { order = b; } else { order = order + "\u0000" + b; } } if (varOrder.size() < bindingslist.size()) { varOrder.add(order); } //System.out.println("String buffer is " + sb); Mutation m = new Mutation(sb.deleteCharAt(sb.length() - 1).toString()); m.put(new Text(varOrder.get(j)), new Text(""), new org.apache.accumulo.core.data.Value(new byte[] {})); w.addMutation(m); } tableSize += 1; } setLocalityGroups(tablename, accCon, varOrder); this.setSupportedVariableOrderMap(createSupportedVarOrderMap(varOrder)); String orders = ""; for (String s : varOrder) { s = s.replace("\u0000", ";"); if (orders.length() == 0) { orders = s; } else { orders = orders + "\u0000" + s; } } Mutation m = new Mutation("~SPARQL"); Value v = new Value(sparql.getBytes()); m.put(new Text("" + tableSize), new Text(orders), v); w.addMutation(m); w.close(); iter.close(); }
From source file:com.fmguler.ven.QueryGenerator.java
/** * Generates insert query for the specified object * @param object the object to generate insert query for * @return the insert SQL query//from ww w. ja v a 2s.c o m */ public String generateInsertQuery(Object object) { BeanWrapper wr = new BeanWrapperImpl(object); String objectName = Convert.toSimpleName(object.getClass().getName()); String tableName = Convert.toDB(objectName); PropertyDescriptor[] pdArr = wr.getPropertyDescriptors(); //generate insert query StringBuffer query = new StringBuffer("insert into " + tableName + "("); StringBuffer values = new StringBuffer(" values("); for (int i = 0; i < pdArr.length; i++) { Class fieldClass = pdArr[i].getPropertyType(); //field class String columnName = Convert.toDB(pdArr[i].getName()); //column name String fieldName = pdArr[i].getName(); //field name //if (fieldName.equals("id")) continue; //remove if it does not break the sequence if (dbClasses.contains(fieldClass)) { //direct database field (Integer,String,Date, etc) query.append(columnName.equals("order") ? "\"order\"" : columnName); query.append(","); values.append(":").append(fieldName); values.append(","); } if (fieldClass.getPackage() != null && domainPackages.contains(fieldClass.getPackage().getName())) { //object query.append(Convert.toDB(fieldName)).append("_id"); query.append(","); values.append(":").append(fieldName).append(".id"); values.append(","); } } query.deleteCharAt(query.length() - 1); query.append(")"); values.deleteCharAt(values.length() - 1); values.append(");"); query.append(values); return query.toString(); }
From source file:au.org.theark.lims.web.component.subjectlims.lims.biospecimen.form.BiospecimenModalDetailForm.java
private void initDeleteModelWindow() { answer = new ConfirmationAnswer(false); confirmModal = new ModalWindow("modal"); confirmModal.setCookieName("yesNoPanel"); if (!isNew()) { List<BioTransaction> bioTransactions = iLimsService .getAllBiotransactionForBiospecimen(cpModel.getObject().getBiospecimen()); StringBuffer bioTxID = new StringBuffer(); for (BioTransaction bioTransaction : bioTransactions) { bioTxID.append(bioTransaction.getId()).append(","); }//from www . ja v a 2 s .co m bioTxID.deleteCharAt(bioTxID.length() - 1); String modelTextReplce1 = modalText.replaceAll("number", Integer.toString(bioTransactions.size())); String modeltextReplace2 = modelTextReplce1.replaceAll("txs", bioTxID.toString()); confirmModal.setContent(new YesNoPanel(confirmModal.getContentId(), modeltextReplace2, "Warning", confirmModal, answer)); confirmModal.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() { private static final long serialVersionUID = 1L; public void onClose(AjaxRequestTarget target) { if (answer.isAnswer()) { iLimsService.deleteBiospecimen(cpModel.getObject()); getSession().getFeedbackMessages().info(me, "Biospecimen " + cpModel.getObject().getBiospecimen().getBiospecimenUid() + " was deleted successfully"); } else { EditModeButtonsPanel editModeButtonsPanel = ((EditModeButtonsPanel) buttonsPanelWMC .get("buttonsPanel")); editModeButtonsPanel.setDeleteButtonEnabled(true); target.add(editModeButtonsPanel); } target.add(feedbackPanel); } }); } }
From source file:com.mobilyzer.util.PhoneUtils.java
/** * Returns the information about cell towers in range. Returns null if the information is * not available //from w w w.j ava 2 s . com * * TODO(wenjiezeng): As folklore has it and Wenjie has confirmed, we cannot get cell info from * Samsung phones. */ public String getCellInfo(boolean cidOnly) { if (!(ContextCompat.checkSelfPermission(context, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED)) { return null; } initNetwork(); List<NeighboringCellInfo> infos = telephonyManager.getNeighboringCellInfo(); StringBuffer buf = new StringBuffer(); String tempResult = ""; if (infos.size() > 0) { for (NeighboringCellInfo info : infos) { tempResult = cidOnly ? info.getCid() + ";" : info.getLac() + "," + info.getCid() + "," + info.getRssi() + ";"; buf.append(tempResult); } // Removes the trailing semicolon buf.deleteCharAt(buf.length() - 1); return buf.toString(); } else { return null; } }