List of usage examples for java.lang StringBuffer length
@Override public synchronized int length()
From source file:StringUtils.java
/** * Concat all the specified strings to a single one * /* ww w . ja v a2s. co m*/ * @param strings - * strings to concat, all null and empty ones will be ignored * @param separator - * separator to put in between the string elements * @param quote - * quote string to put around string elements, if null nothing will * be put around them * @return String with concatenated inputs */ public static String concat(String[] strings, String separator, String quote) { StringBuffer output = new StringBuffer(); if (strings != null) { int iIndex; boolean bSeparator; boolean bQuote; bSeparator = (separator != null) && (separator.length() > 0); bQuote = (quote != null) && (quote.length() > 0); for (iIndex = 0; iIndex < strings.length; iIndex++) { if ((strings[iIndex] != null) && (strings[iIndex].length() > 0)) { if ((output.length() > 0) && (bSeparator)) { output.append(separator); } if (bQuote) { output.append(quote); } output.append(strings[iIndex]); if (bQuote) { output.append(quote); } } } } return output.toString(); }
From source file:com.seedboxer.seedboxer.mule.processor.postaction.SSHCommandSender.java
@SuppressWarnings("unchecked") private String processTemplate(String command, Map<String, Object> templateVars) throws IOException, TemplateException { List<String> files = (List<String>) templateVars.get(Configuration.FILES); StringBuffer sb = new StringBuffer(); for (String file : files) { sb.append(new File(file).getName()); sb.append(","); }/*w ww . j a v a 2 s . c o m*/ sb.deleteCharAt(sb.length() - 1); return command.replaceAll(variableNameInCmd, sb.toString()); }
From source file:com.gemstone.gemfire.management.internal.cli.parser.preprocessor.PreprocessorUtils.java
/** * //from w w w .jav a 2 s . c om * This function will trim the given input string. It will not only remove the * spaces and tabs at the end but also compress multiple spaces and tabs to a * single space * * @param input * The input string on which the trim operation needs to be performed * @param retainLineSeparator * whether to retain the line separator. * * @return String */ public static TrimmedInput trim(final String input, final boolean retainLineSeparator) { if (input != null) { String inputCopy = input; StringBuffer output = new StringBuffer(); // First remove the trailing white spaces, we do not need those inputCopy = StringUtils.stripEnd(inputCopy, null); // As this parser is for optionParsing, we also need to remove // the trailing optionSpecifiers provided it has previous // options. Remove the trailing LONG_OPTION_SPECIFIERs // in a loop. It is necessary to check for previous options for // the case of non-mandatory arguments. // "^(.*)(\\s-+)$" - something that ends with a space followed by a series of hyphens. while (Pattern.matches("^(.*)(\\s-+)$", inputCopy)) { inputCopy = StringUtils.removeEnd(inputCopy, SyntaxConstants.SHORT_OPTION_SPECIFIER); // Again we need to trim the trailing white spaces // As we are in a loop inputCopy = StringUtils.stripEnd(inputCopy, null); } // Here we made use of the String class function trim to remove the // space and tabs if any at the // beginning and the end of the string int noOfSpacesRemoved = 0; { int length = inputCopy.length(); inputCopy = inputCopy.trim(); noOfSpacesRemoved += length - inputCopy.length(); } // Now we need to compress the multiple spaces and tabs to single space // and tabs but we also need to ignore the white spaces inside the // quotes and parentheses StringBuffer buffer = new StringBuffer(); boolean startWhiteSpace = false; for (int i = 0; i < inputCopy.length(); i++) { char ch = inputCopy.charAt(i); buffer.append(ch); if (PreprocessorUtils.isWhitespace(ch)) { if (PreprocessorUtils.isSyntaxValid(buffer.toString())) { if (startWhiteSpace) { noOfSpacesRemoved++; } else { startWhiteSpace = true; if (ch == '\n') { if (retainLineSeparator) { output.append("\n"); } } else { output.append(" "); } } buffer.delete(0, buffer.length()); } else { output.append(ch); } } else { startWhiteSpace = false; output.append(ch); } } return new TrimmedInput(output.toString(), noOfSpacesRemoved); } else { return null; } }
From source file:com.sfs.whichdoctor.beans.ContactBean.java
/** * Gets the status.// w ww.j a va2s.c o m * * @param personStatus the person status * * @return the status */ public final String getStatus(final String personStatus) { StringBuffer contactStatus = new StringBuffer(); if (this.returnedMail) { if (contactStatus.length() > 0) { contactStatus.append(", "); } contactStatus.append("returned mail"); } if (this.requestNoMail) { if (contactStatus.length() > 0) { contactStatus.append(", "); } contactStatus.append("no mail requested"); } if (StringUtils.equalsIgnoreCase(personStatus, "Deceased")) { if (contactStatus.length() > 0) { contactStatus.append(", "); } contactStatus.append("deceased"); } return capitalise(contactStatus.toString()); }
From source file:com.bdaum.juploadr.uploadapi.locrrest.LocrMethod.java
private void appendNVP(StringBuffer url, String name, String value) { if (url.length() == 0) { url.append("?"); //$NON-NLS-1$ }//ww w .ja v a 2 s . c o m char lastChar = url.charAt(url.length() - 1); if (lastChar != '&' && lastChar != '?') { url.append("&"); //$NON-NLS-1$ } url.append(name); url.append("="); //$NON-NLS-1$ url.append(encode(value)); }
From source file:com.clican.pluto.cms.dao.hibernate.BaseDao.java
protected String getInString(IPojo[] array) { StringBuffer str = new StringBuffer(); str.append("("); for (IPojo pojo : array) { str.append(pojo.getId());//from w ww .jav a 2s . c om str.append(","); } return str.substring(0, str.length() - 1) + ")"; }
From source file:es.itg.sensorweb.model.swecommon.DataRecord.java
@Override @JsonIgnore//from w ww . j a v a 2 s . c om public String getTextEncodedValue(String blockSeparator, String tokenSeparator) { StringBuffer sb = new StringBuffer(); for (AbstractDataComponent field : fields) { sb.append(field.getTextEncodedValue(blockSeparator, tokenSeparator)); sb.append(tokenSeparator); } sb.delete(sb.length() - tokenSeparator.length(), sb.length()); return sb.toString(); }
From source file:com.linuxbox.enkive.docsearch.indri.IndriQueryComposer.java
/** * Creates an Indri query by using the filter-require (#filreq) and * filter-reject (#filrej) operators to filter the results. Then it uses the * #compose operator to rank/weight the result of the the required elements. * If there are no required elements, it uses a simple #not to complete the * query./*from www .j a va 2 s. c o m*/ * * @param query * @return * @throws DocSearchException */ public static CharSequence composeQuery(TextQueryParser.Query query) throws DocSearchException { if (LOGGER.isTraceEnabled()) { StringBuilder output = new StringBuilder(); boolean first = true; for (Phrase p : query) { if (first) { first = false; } else { output.append(", "); } output.append(p.getTermsAsCharSeq()); } LOGGER.trace("composeQuery receives phrases: " + output.toString()); } StringBuffer result = new StringBuffer(); /* * Separate the requirements and the rejections and sanitize in place. */ List<Phrase> requirements = new LinkedList<Phrase>(); List<Phrase> rejections = new LinkedList<Phrase>(); for (Phrase p : query) { sanitizePhraseInPlace(p); if (p.isNegated()) { rejections.add(p); } else { requirements.add(p); } } if (!requirements.isEmpty()) { // prefer to combine requirements with #combine, which does some // perhaps useful weighting of search terms based on frequency if (requirements.size() > 1) { result.append("#combine("); } for (Phrase p : requirements) { result.append(composePhrase(p)); result.append(' '); } result.deleteCharAt(result.length() - 1); if (requirements.size() > 1) { result.append(")"); } } else if (!rejections.isEmpty()) { // if everything is negation, so we have something in the query, // just prohibit the first element, given that we've already // #filrej'ed everything result.append("#not("); result.append(composePhrase(rejections.get(0))); result.append(')'); } else { throw new DocSearchException("illegal query: empty"); } // now we have the core; lets add the filters to the outside; since // requirements (#filereq) are likely to reduce the number of results // more quickly, make that the outer filter with the rejections within. // first wrap rejection filter if necessary if (!rejections.isEmpty()) { StringBuffer prefix = new StringBuffer("#filrej("); if (rejections.size() > 1) { prefix.append("#syn("); } for (Phrase p : rejections) { prefix.append(composePhrase(p)); prefix.append(' '); } // delete last space prefix.deleteCharAt(prefix.length() - 1); if (rejections.size() > 1) { prefix.append(')'); } prefix.append(' '); result.insert(0, prefix); result.append(")"); } // now wrap requirements filter if necessary; this will be executed // before any rejection filter if (!requirements.isEmpty()) { StringBuffer prefix = new StringBuffer("#filreq("); if (requirements.size() > 1) { prefix.append("#band("); } for (Phrase p : requirements) { prefix.append(composePhrase(p)); prefix.append(' '); } // delete last space prefix.deleteCharAt(prefix.length() - 1); if (requirements.size() > 1) { prefix.append(')'); } prefix.append(' '); result.insert(0, prefix); result.append(")"); } if (LOGGER.isTraceEnabled()) { LOGGER.trace("composeQuery produces: " + result); } return result; }
From source file:net.beaconcontroller.web.view.json.OFFlowStatisticsReplyDataTableFormatCallback.java
@Override public void format(OFFlowStatisticsReply data, JsonGenerator jg) throws IOException { jg.writeNumber(U16.f(data.getMatch().getInputPort())); jg.writeString(HexString.toHexString(data.getMatch().getDataLayerSource())); jg.writeString(HexString.toHexString(data.getMatch().getDataLayerDestination())); jg.writeNumber(U16.f(data.getMatch().getDataLayerType())); jg.writeString(IPv4.fromIPv4Address(data.getMatch().getNetworkSource())); jg.writeString(IPv4.fromIPv4Address(data.getMatch().getNetworkDestination())); jg.writeNumber(U8.f(data.getMatch().getNetworkProtocol())); jg.writeNumber(U16.f(data.getMatch().getTransportSource())); jg.writeNumber(U16.f(data.getMatch().getTransportDestination())); jg.writeNumber(U32.f(data.getMatch().getWildcards())); jg.writeNumber(U64.f(data.getByteCount())); jg.writeNumber(U64.f(data.getPacketCount())); jg.writeNumber(((double) U32.f(data.getDurationSeconds())) + ((double) data.getDurationNanoseconds()) / 1000000000d); jg.writeNumber(U16.f(data.getIdleTimeout())); jg.writeNumber(U16.f(data.getHardTimeout())); jg.writeNumber(U64.f(data.getCookie())); StringBuffer outPorts = new StringBuffer(); for (OFAction action : data.getActions()) { if (action instanceof OFActionOutput) { OFActionOutput ao = (OFActionOutput) action; if (outPorts.length() > 0) outPorts.append(" "); outPorts.append(U16.f(ao.getPort())); }/*from w ww . j a va2s .co m*/ } jg.writeString(outPorts.toString()); String url = StringEscapeUtils .escapeHtml3("/wm/core/switch/" + switchId + "/flow/" + data.getMatch().toString() + "/del"); jg.writeString("<a href=\"" + url + "\">del</a>"); }
From source file:de.helmholtz_muenchen.ibis.ngs.gatkvariantfiltration.GATKVariantFiltrationNodeModel.java
/** * Adds the values of SettingsModelString to the filterString if model is enabled * @param toAdd//from w w w . j a v a2 s. co m */ private StringBuffer addToFilterString(SettingsModelOptionalString toAdd, String FieldName, StringBuffer filterString) { if (toAdd.isActive()) { if (filterString.length() == 0 && !(FieldName.equals(""))) { filterString.append(FieldName + toAdd.getStringValue()); } else if (filterString.length() > 0 && !(FieldName.equals(""))) { filterString.append("||" + FieldName + toAdd.getStringValue()); } else { filterString.append("||" + toAdd.getStringValue()); } } return filterString; }