List of usage examples for java.lang StringBuffer deleteCharAt
@Override public synchronized StringBuffer deleteCharAt(int index)
From source file:gov.nih.nci.cabig.ctms.lang.StringTools.java
/** * Normalizes the whitespace in the given buffer in-place. * This means that the whitespace is stripped from the head and the tail * and any contiguous stretches of whitespace are converted into a single * space.// w w w. jav a 2 s .c om * * @param toNormalize * @return the passed-in buffer */ public static StringBuffer normalizeWhitespace(StringBuffer toNormalize) { if (toNormalize == null) return null; // start with this value == true to completely remove leading whitespace boolean prevIsWhitespace = true; for (int i = 0; i < toNormalize.length(); i++) { if (Character.isWhitespace(toNormalize.charAt(i))) { if (prevIsWhitespace) { toNormalize.deleteCharAt(i); i--; } else { toNormalize.setCharAt(i, ' '); prevIsWhitespace = true; } } else { prevIsWhitespace = false; } } // remove (at most) one trailing ' ' if (toNormalize.length() > 0 && toNormalize.charAt(toNormalize.length() - 1) == ' ') toNormalize.deleteCharAt(toNormalize.length() - 1); return toNormalize; }
From source file:com.fantasia.snakerflow.engine.SnakerHelper.java
public static String getNodeJson(List<NodeModel> nodes) { StringBuffer buffer = new StringBuffer(); buffer.append("states: {"); for (NodeModel node : nodes) { buffer.append(node.getName());/* w w w . ja va2s .c o m*/ buffer.append(getBase(node)); buffer.append(getLayout(node)); buffer.append(getProperty(node)); buffer.append(","); } buffer.deleteCharAt(buffer.length() - 1); buffer.append("},"); return buffer.toString(); }
From source file:org.deegree.commons.tools.CommandUtils.java
/** * Prints a help message for a apache commons-cli based command line tool and <b>terminates the programm</b>. * /* w w w. j a v a2 s . c om*/ * @param options * the options to generate help/usage information for * @param toolName * the name of the command line tool * @param helpMsg * some further information * @param otherUsageInfo * an optional string to append to the usage information (e.g. for additional arguments like input files) */ public static void printHelp(Options options, String toolName, String helpMsg, String otherUsageInfo) { HelpFormatter formatter = new HelpFormatter(); StringWriter helpWriter = new StringWriter(); StringBuffer helpBuffer = helpWriter.getBuffer(); PrintWriter helpPrintWriter = new PrintWriter(helpWriter); helpPrintWriter.println(); if (helpMsg != null && helpMsg.length() != 0) { formatter.printWrapped(helpPrintWriter, HELP_TEXT_WIDTH, helpMsg); helpPrintWriter.println(); } formatter.printUsage(helpPrintWriter, HELP_TEXT_WIDTH, toolName, options); if (otherUsageInfo != null) { helpBuffer.deleteCharAt(helpBuffer.length() - 1); // append additional arguments helpBuffer.append(' ').append(otherUsageInfo).append("\n"); } helpBuffer.append("\n"); formatter.printOptions(helpPrintWriter, HELP_TEXT_WIDTH, options, 3, 5); System.err.print(helpBuffer.toString()); System.exit(1); }
From source file:org.apache.axis.attachments.MimeUtils.java
/** * This routine will get the content type from a mulit-part mime message. * * @param mp the MimeMultipart/*ww w . j a v a2s.co m*/ * @return the content type */ public static String getContentType(javax.mail.internet.MimeMultipart mp) { StringBuffer contentType = new StringBuffer(mp.getContentType()); // TODO (dims): Commons HttpClient croaks if we don't do this. // Need to get Commons HttpClient fixed. for (int i = 0; i < contentType.length();) { char ch = contentType.charAt(i); if (ch == '\r' || ch == '\n') contentType.deleteCharAt(i); else i++; } return contentType.toString(); }
From source file:com.jfaker.framework.flow.SnakerHelper.java
public static String getStateJson(ProcessModel model, List<Task> activeTasks, List<HistoryTask> historyTasks) { StringBuffer buffer = new StringBuffer(); buffer.append("{'activeRects':{'rects':["); if (activeTasks != null && activeTasks.size() > 0) { for (Task task : activeTasks) { buffer.append("{'paths':[],'name':'"); buffer.append(task.getTaskName()); buffer.append("'},"); }/* w ww . ja v a 2 s. c om*/ buffer.deleteCharAt(buffer.length() - 1); } buffer.append("]}, 'historyRects':{'rects':["); if (historyTasks != null && historyTasks.size() > 0) { for (HistoryTask historyTask : historyTasks) { NodeModel parentModel = model.getNode(historyTask.getTaskName()); if (parentModel == null) continue; buffer.append("{'name':'").append(parentModel.getName()).append("','paths':["); buffer.append("]},"); } buffer.deleteCharAt(buffer.length() - 1); } buffer.append("]}}"); return buffer.toString(); }
From source file:org.openadaptor.util.XmlUtils.java
/** * Generate an XPath expression from a list of Steps. * <br>/* w w w . ja v a 2 s .c om*/ * @param steps List containing XPath Steps. * @param absolutePath flag to indicate if path is absolute. * @return String containing the corresponding XPath. */ private static String toXPath(List steps, boolean absolutePath) { StringBuffer sb = new StringBuffer(); if (absolutePath) { sb.append('/'); } Iterator it = steps.iterator(); while (it.hasNext()) { Step step = (Step) it.next(); sb.append(step.getText()).append("/"); } sb.deleteCharAt(sb.length() - 1);//Drop last slash. return sb.toString(); }
From source file:system.vo.UserGridVO.java
public static UserGridVO initByUser(User user) { if (null == user) { return null; }/* w ww. j ava 2 s .c o m*/ Expert expert = CollectionUtils.isEmpty(user.experts) ? null : user.getExperts().iterator().next(); UserGridVO vo = new UserGridVO(); vo.setAverageScore(null == expert ? "" : Float.toString(expert.getAverageScoreWithDefault())); vo.setComplain(user.isComplain == null ? false : user.isComplain); vo.setCountry(null == expert ? "" : expert.country); vo.setEmail(user.email); vo.setEnable(user.isEnable); vo.setGender(user.getGender() == null ? 0 : user.getGender().ordinal()); ObjectMapper objectMapper = JackJsonUtil.getMapperInstance(false); List<String> skillsTagsList = new ArrayList<String>(); try { if (expert != null && StringUtils.isNotEmpty(expert.skillsTags)) { skillsTagsList = objectMapper.readValue(expert.skillsTags, List.class); } } catch (Exception e) { e.printStackTrace(); } StringBuffer skillsTags = new StringBuffer(""); if (CollectionUtils.isNotEmpty(skillsTagsList)) { for (String item : skillsTagsList) { skillsTags.append(item).append("@"); } skillsTags.deleteCharAt(skillsTags.length() - 1); // ? if (skillsTagsList.contains(new String("?"))) { vo.setOnlineService(true); } // if (skillsTagsList.contains(new String(""))) { vo.setOnlineTranslation(true); } } vo.setSkillsTags(null == expert ? "" : StringUtils.defaultIfBlank(skillsTags.toString(), "")); vo.setTop(null == expert ? false : BooleanUtils.toBooleanDefaultIfNull(expert.isTop, false)); vo.setTradeNum(null == expert ? 0L : expert.dealNum); vo.setUserId(user.id); vo.setUserName(StringUtils.isEmpty(user.userName) ? "-" : user.userName); vo.setPhoneNumber(user.getPhoneNumber()); if (user.registerDate != null) { vo.setRegisterDate(dateFormat.format(user.registerDate)); } if (Logger.isDebugEnabled()) { if (expert != null) { Logger.debug("[id:" + expert.getId() + ",??:" + expert.userName + "]" + expert.inTags); } } // expert.topIndustry? if (vo.isTop()) { if (expert != null && (expert.topIndustry == null || expert.topIndustry == 0)) { vo.setTop(Boolean.FALSE); } } StringBuffer inTags = new StringBuffer(""); if (expert != null && CollectionUtils.isNotEmpty(expert.inTags)) { for (SkillTag item : expert.inTags) { if (item != null) { inTags.append(item.tagName).append("@"); if (vo.isTop() && expert.topIndustry != null && StringUtils.isEmpty(vo.getTopIndustryName())) { if (item.id - expert.topIndustry == 0) { // topIndustryName vo.setTopIndustryName(item.tagName); } } } } inTags.deleteCharAt(inTags.length() - 1); } vo.setInTags(null == expert ? "" : StringUtils.defaultIfBlank(inTags.toString(), "")); if (StringUtils.isNotBlank(user.email)) { GetBalanceResult balance = PayService.getBalanceByEmail(user.email); if (GetBalanceResult.STATE.SUCCESS == balance.state) { vo.setBalance(balance.balance.toString()); } } vo.setResumeStatus(user.getResumeStatus().toString().toLowerCase()); // ? return vo; }
From source file:com.qk.applibrary.db.sqlite.SqlBuilder.java
public static SqlInfo getUpdateSqlAsSqlInfo(Object entity, String strWhere) { TableInfo table = TableInfo.get(entity.getClass()); List<KeyValue> keyValueList = new ArrayList<KeyValue>(); ////w w w . jav a 2s . c om Collection<Property> propertys = table.propertyMap.values(); for (Property property : propertys) { KeyValue kv = property2KeyValue(property, entity); if (kv != null) keyValueList.add(kv); } if (keyValueList == null || keyValueList.size() == 0) { throw new DbException("this entity[" + entity.getClass() + "] has no property"); } SqlInfo sqlInfo = new SqlInfo(); StringBuffer strSQL = new StringBuffer("UPDATE "); strSQL.append(table.getTableName()); strSQL.append(" SET "); for (KeyValue kv : keyValueList) { strSQL.append(kv.getKey()).append("=?,"); sqlInfo.addValue(kv.getValue()); } strSQL.deleteCharAt(strSQL.length() - 1); if (!TextUtils.isEmpty(strWhere)) { strSQL.append(" WHERE ").append(strWhere); } sqlInfo.setSql(strSQL.toString()); return sqlInfo; }
From source file:com.qk.applibrary.db.sqlite.SqlBuilder.java
public static SqlInfo getUpdateSqlAsSqlInfo(Object entity) { TableInfo table = TableInfo.get(entity.getClass()); Object idvalue = table.getId().getValue(entity); if (null == idvalue) {//?null?? throw new DbException("this entity[" + entity.getClass() + "]'s id value is null"); }//from ww w . j a v a2 s.c o m List<KeyValue> keyValueList = new ArrayList<KeyValue>(); // Collection<Property> propertys = table.propertyMap.values(); for (Property property : propertys) { KeyValue kv = property2KeyValue(property, entity); if (kv != null) keyValueList.add(kv); } if (keyValueList == null || keyValueList.size() == 0) return null; SqlInfo sqlInfo = new SqlInfo(); StringBuffer strSQL = new StringBuffer("UPDATE "); strSQL.append(table.getTableName()); strSQL.append(" SET "); for (KeyValue kv : keyValueList) { strSQL.append(kv.getKey()).append("=?,"); sqlInfo.addValue(kv.getValue()); } strSQL.deleteCharAt(strSQL.length() - 1); strSQL.append(" WHERE ").append(table.getId().getColumn()).append("=?"); sqlInfo.addValue(idvalue); sqlInfo.setSql(strSQL.toString()); return sqlInfo; }
From source file:com.redhat.rhn.common.util.ServletUtils.java
/** * Creates a encoded URL query string with the parameters from the given request. If the * request is a GET, then the returned query string will simply consist of the query * string from the request. If the request is a POST, the returned query string will * consist of the form variables.//ww w . j av a 2 s . c o m * * <br/><br/> * * <strong>Note</strong>: This method does not support multi-value parameters. * * @param request The request for which the query string will be generated. * * @return An encoded URL query string with the parameters from the given request. */ public static String requestParamsToQueryString(ServletRequest request) { StringBuffer queryString = new StringBuffer(); String paramName = null; String paramValue = null; Enumeration paramNames = request.getParameterNames(); while (paramNames.hasMoreElements()) { paramName = (String) paramNames.nextElement(); paramValue = request.getParameter(paramName); queryString.append(encode(paramName)).append("=").append(encode(paramValue)).append("&"); } if (endsWith(queryString, '&')) { queryString.deleteCharAt(queryString.length() - 1); } return queryString.toString(); }