List of usage examples for java.lang StringBuffer length
@Override public synchronized int length()
From source file:com.genentech.application.calcProps.SDFCalcProps.java
/** * Sort commands by dependencies ex. Solubility_Index requires cLogD7.4 * Need to calculate cLogD7.4 before calculating solubility_index * cLogD7.4 command line need to appear before solubility_index command line *///from w ww. j a v a2 s . com private static List<Calculator> sortByDependencies(ArrayList<Calculator> calculators, int noCalculatorSizeChangeCount) { int oldCalculatorsSize = calculators.size(); List<Calculator> sorted = new ArrayList<Calculator>(); if (!calculators.isEmpty()) { Calculator calc = calculators.remove(0); //get first element in list Set<String> reqCalculators = calc.getRequiredCalculators(); if (reqCalculators.size() == 0) { // no dependencies, add to beginning sorted.add(0, calc); } else { //there are dependencies // are any dependencies left in the list of calculators to be sorted if (anyDependenciesInList(reqCalculators, calculators)) { calculators.add(calc); //add calc back to the end of the list to be sorted later } else { //they must be in the sorted list, add calc to the end of sorted list sorted.add(calc); //append to end of sorted calculators } } } if (calculators.size() == oldCalculatorsSize) noCalculatorSizeChangeCount = noCalculatorSizeChangeCount + 1; else noCalculatorSizeChangeCount = 0; /*If the number of calculators in the list has not going down within calculators.size() times*/ if (noCalculatorSizeChangeCount == calculators.size() && calculators.size() > 0) { StringBuffer calculatorText = new StringBuffer(); for (Calculator calc : calculators) calculatorText = calculatorText.append(calc.getName()).append(" "); throw new Error("There is a circular dependencies amongst following calculators: " + calculatorText.substring(0, calculatorText.length())); } //recursively sort remaining calculators if (calculators.size() > 0) { //append rest to sorted sorted.addAll(sortByDependencies(calculators, noCalculatorSizeChangeCount)); } return sorted; }
From source file:com.concursive.connect.web.modules.search.utils.SearchUtils.java
/** * Extracts the keywords into tokens, and then either concats them with AND * if all words are required, or leaves the tokens alone * * @param searchText Description of the Parameter * @param allWords Description of the Parameter * @return Description of the Return Value *///from w w w.jav a2s .c o m public static String parseSearchText(String searchText, boolean allWords) { StringBuffer sb = new StringBuffer(); boolean returnTokens = true; String currentDelims = WHITESPACE_AND_QUOTES; StringTokenizer parser = new StringTokenizer(searchText, currentDelims, returnTokens); String token = null; boolean spacer = false; while (parser.hasMoreTokens()) { token = parser.nextToken(currentDelims); if (!isDoubleQuote(token)) { if (hasText(token)) { String gotToken = token.trim().toLowerCase(); if ("and".equals(gotToken) || "or".equals(gotToken) || "not".equals(gotToken)) { if (sb.length() > 0) { sb.append(" "); } sb.append(gotToken.toUpperCase()); spacer = true; } else { if (spacer) { if (sb.length() > 0) { sb.append(" "); } spacer = false; } else { if (sb.length() > 0) { if (allWords) { sb.append(" AND "); } else { sb.append(" "); } } } if (gotToken.indexOf(" ") > -1) { sb.append("\"").append(gotToken).append("\""); } else { sb.append(gotToken); } } } } else { currentDelims = flipDelimiters(currentDelims); } } return sb.toString(); }
From source file:XMLUtils.java
/** * Returns the text value of an element. * @param el/* www.j ava2 s .co m*/ * @return */ public static String getTextValue(Element el) { StringBuffer b = new StringBuffer(); // retrieve the text node child NodeList nl = el.getChildNodes(); int len = nl.getLength(); for (int i = 0; i < len; i++) { Node n = nl.item(i); if (n instanceof Text) { Text t = (Text) n; b.append(t.getData()); } } // trim the result, ignoring the first spaces and cariage return int iFirst = 0; for (; iFirst < b.length(); iFirst++) { char c = b.charAt(iFirst); if (c != ' ' && c != '\r' && c != '\n' && c != '\t') { break; } } // start by the end as well int iLast = b.length() - 1; for (; iLast >= 0; iLast--) { char c = b.charAt(iLast); if (c != ' ' && c != '\r' && c != '\n' && c != '\t') { break; } } return b.substring(iFirst, iLast + 1); }
From source file:de.escalon.hypermedia.spring.uber.UberUtils.java
private static String getModelProperty(String href, ActionDescriptor actionDescriptor) { RequestMethod httpMethod = RequestMethod.valueOf(actionDescriptor.getHttpMethod()); StringBuffer model = new StringBuffer(); switch (httpMethod) { case POST:/*from w w w . j a v a 2s .c o m*/ case PUT: case PATCH: { List<UberField> uberFields = new ArrayList<UberField>(); recurseBeanCreationParams(uberFields, actionDescriptor.getRequestBody().getParameterType(), actionDescriptor, actionDescriptor.getRequestBody(), actionDescriptor.getRequestBody().getValue(), "", Collections.<String>emptySet()); for (UberField uberField : uberFields) { if (model.length() > 0) { model.append("&"); } model.append(String.format(MODEL_FORMAT, uberField.getName(), uberField.getName())); } break; } default: } return model.length() == 0 ? null : model.toString(); }
From source file:com.liferay.util.Http.java
public static String parameterMapToStringNoEncode(Map parameterMap) { StringBuffer sb = new StringBuffer(); if (parameterMap.size() > 0) { sb.append(StringPool.QUESTION);//from w ww. j a v a2 s . c o m Iterator itr = parameterMap.entrySet().iterator(); while (itr.hasNext()) { Map.Entry entry = (Map.Entry) itr.next(); String name = (String) entry.getKey(); String[] values = (String[]) entry.getValue(); for (int i = 0; i < values.length; i++) { sb.append(name); sb.append(StringPool.EQUAL); sb.append(values[i]); sb.append(StringPool.AMPERSAND); } } sb.deleteCharAt(sb.length() - 1); } return sb.toString(); }
From source file:eionet.cr.util.Util.java
/** * * @param coll// w w w .j a va 2 s . co m * @param surroundWith * @return */ public static String toCSV(Collection coll, String surroundWith) { StringBuffer buf = new StringBuffer(); if (coll != null) { for (Iterator it = coll.iterator(); it.hasNext();) { if (buf.length() > 0) { buf.append(","); } buf.append(surroundWith).append(it.next()).append(surroundWith); } } return buf.toString(); }
From source file:eionet.cr.util.Util.java
/** * * @param coll//from w w w . j a v a 2 s . c o m * @return */ public static String toCSVHashes(Collection coll) { StringBuffer buf = new StringBuffer(); if (coll != null) { for (Iterator it = coll.iterator(); it.hasNext();) { if (buf.length() > 0) { buf.append(","); } buf.append(Hashes.spoHash(it.next().toString())); } } return buf.toString(); }
From source file:com.edgenius.wiki.render.MarkupUtil.java
/** * Markup token has odd number leading slash "\", then convert this markup to <em>HTML entity</em>. * @param input//w ww.j a va 2 s . c om * @return */ public static String escapeMarkupToEntity(String input) { if (input == null) return null; int len = input.length(); StringBuffer sb = new StringBuffer(); int slash = 0; int currLen; boolean odd; for (int idx = 0; idx < len; idx++) { char c = input.charAt(idx); if (c == '\\') { slash++; sb.append(c); continue; } odd = processDoubleSlash(sb, slash); //even ">" is not filter pattern keyword, but it use in markup link. // For example[view has \\> char>link],here must escape \> to entity, then in LinkFilter could correctly convert \&#(int >); // to ">", as it will call unescapeMarkupLink() to remove another "\" if (StringUtils.contains(FilterRegxConstants.FILTER_KEYWORD + ">", c) && odd) { currLen = sb.length(); sb.deleteCharAt(currLen - 1); //delete last slash sb.append(EscapeUtil.toEntity(c)); } else sb.append(c); slash = 0; } //string end by some amount "\" if (slash > 0) { odd = processDoubleSlash(sb, slash); //TDB: how to handle last single "\" to entity? if (odd) { currLen = sb.length(); sb.deleteCharAt(currLen - 1); //delete last slash sb.append(ENTITY_SLASH); } } return sb.toString(); }
From source file:com.projity.server.data.MPXConverter.java
public static String removeInvalidChars(String in) { // had case of user with newlines in task names if (in == null) return null; StringBuffer inBuf = new StringBuffer(in); for (int i = 0; i < inBuf.length(); i++) { char c = inBuf.charAt(i); if (c == '\r' || c == '\n' || c == '\t') // using escape chars of the form � is not good - they show up in MSP literally. MSP doesn't seem to support newlines anyway inBuf.setCharAt(i, ' '); }// ww w .ja va 2 s. com return inBuf.toString(); }
From source file:com.qpark.eip.core.failure.BaseFailureHandler.java
private static String format(final FailureMessagePhraseableType m, final Object... data) { StringBuffer sb = new StringBuffer(1024); if (m != null) { if (m.getText() != null && m.getText().trim().length() > 0) { if (data != null && data.length > 0) { MessageFormat mf = new MessageFormat(checkUnnumberedBrackets(m.getText())); sb.append(mf.format(data)); } else { sb.append(m.getText());//ww w.jav a 2s.c o m } } if (m.getPhraseKey() != null) { for (String key : m.getPhraseKey()) { if (phrases.get(key) != null && phrases.get(key).length() > 0) { if (sb.length() > 0) { sb.append(" "); } } sb.append(phrases.get(key)); } } } return sb.toString(); }