List of usage examples for java.lang StringBuilder length
int length();
From source file:Main.java
/** * Returns a String that is suitable for use as an <code>application/x-www-form-urlencoded</code> * list of parameters in an HTTP PUT or HTTP POST. * * @param parameters The parameters to include. * @param charset The encoding to use. *//*from w ww . j ava2 s . co m*/ public static String format(final List<? extends NameValuePair> parameters, final String charset) { final StringBuilder result = new StringBuilder(); for (final NameValuePair parameter : parameters) { final String encodedName = encodeFormFields(parameter.getName(), charset); final String encodedValue = encodeFormFields(parameter.getValue(), charset); if (result.length() > 0) { result.append(PARAMETER_SEPARATOR); } result.append(encodedName); if (encodedValue != null) { result.append(NAME_VALUE_SEPARATOR); result.append(encodedValue); } } return result.toString(); }
From source file:Main.java
/** * Returns a String that is suitable for use as an <code>application/x-www-form-urlencoded</code> * list of parameters in an HTTP PUT or HTTP POST. * * @param parameters The parameters to include. * @param charset The encoding to use. * @since 4.2/*from www. j ava 2 s. co m*/ */ public static String format(final Iterable<? extends NameValuePair> parameters, final Charset charset) { final StringBuilder result = new StringBuilder(); for (final NameValuePair parameter : parameters) { final String encodedName = encodeFormFields(parameter.getName(), charset); final String encodedValue = encodeFormFields(parameter.getValue(), charset); if (result.length() > 0) { result.append(PARAMETER_SEPARATOR); } result.append(encodedName); if (encodedValue != null) { result.append(NAME_VALUE_SEPARATOR); result.append(encodedValue); } } return result.toString(); }
From source file:Main.java
/** * For logging.//www . j a v a2 s. c o m * * @param map * @return */ public static <K, V> String map2str(Map<K, V> map) { StringBuilder sb = new StringBuilder(); try { if (!isEmpty(map)) { for (Map.Entry<K, V> entry : map.entrySet()) { String key = entry.getKey().toString(); String val = entry.getValue().toString(); sb.append(key).append(':').append(val).append(','); } return sb.substring(0, sb.length() - 1); } } catch (Exception e) { } return sb.toString(); }
From source file:org.apache.commons.scxml2.io.ContentParser.java
/** * Space normalize content string, trimming pre/post-fixed whitespace and collapsing embedded whitespaces to * single space.//from w ww . j a v a 2s.c om * @param content content to space-normalize * @return space-normalized content */ public static String spaceNormalizeContent(final String content) { if (content != null) { int index = 0; int length = content.length(); StringBuilder buffer = new StringBuilder(length); boolean whiteSpace = false; while (index < length) { if (isWhiteSpace(content.charAt(index))) { if (!whiteSpace && buffer.length() > 0) { buffer.append(' '); whiteSpace = true; } } else { buffer.append(content.charAt(index)); whiteSpace = false; } index++; } if (whiteSpace) { buffer.setLength(buffer.length() - 1); } return buffer.toString(); } return null; }
From source file:com.hmsinc.epicenter.classifier.util.ClassifierUtils.java
public static CharSequence filterAllowNumbers(final CharSequence complaint, final Set<String> stopwords) { String ret = ""; if (complaint != null) { // Lowercase, alphabetic only, remove extra spaces.. final String cleaned = StringUtils.trimToNull(complaint.toString().toLowerCase(Locale.getDefault()) .replaceAll("h/a", "headache").replaceAll("n/v", "nausea vomiting").replaceAll("[/,]", " ") .replaceAll("[^a-z\\s\\d]", " ")); if (cleaned != null) { final StringBuilder buf = new StringBuilder(); final String[] sp = cleaned.split("\\s"); for (int i = 0; i < sp.length; i++) { if (sp[i] != null && sp[i].length() > 1 && !stopwords.contains(sp[i])) { if (buf.length() > 0) { buf.append(" "); }//w w w .j a v a 2 s. c o m buf.append(sp[i]); } } if (buf.length() > 0) { ret = buf.toString(); } } } return ret; }
From source file:com.vaadin.tools.ReportUsage.java
private static String makeUserAgent() { String userAgent = USER_AGENT_BASE; StringBuilder extra = new StringBuilder(); appendUserAgentProperty(extra, "java.vendor"); appendUserAgentProperty(extra, "java.version"); appendUserAgentProperty(extra, "os.arch"); appendUserAgentProperty(extra, "os.name"); appendUserAgentProperty(extra, "os.version"); if (extra.length() > 0) { userAgent += " (" + extra.toString() + ")"; }//w ww . ja v a 2s . co m return userAgent.toString(); }
From source file:com.ocs.dynamo.ui.composite.table.TableUtils.java
/** * Formats a collection of entities (turns it into a comma-separated string based on the value * of the "displayProperty")//ww w . j a v a 2 s . c o m * * @param entityModelFactory * @param collection * @return */ public static String formatEntityCollection(EntityModelFactory entityModelFactory, Object collection) { StringBuilder builder = new StringBuilder(); Iterable<?> col = (Iterable<?>) collection; Iterator<?> it = col.iterator(); while (it.hasNext()) { if (builder.length() > 0) { builder.append(", "); } Object next = it.next(); if (next instanceof AbstractEntity) { EntityModel<?> entityModel = entityModelFactory.getModel(next.getClass()); String displayProperty = entityModel.getDisplayProperty(); if (displayProperty != null) { builder.append(ClassUtils.getFieldValueAsString(next, displayProperty)); } else { builder.append(next.toString()); } } else { builder.append(next); } } return builder.toString(); }
From source file:com.hmsinc.epicenter.classifier.util.ClassifierUtils.java
public static CharSequence filter(final CharSequence complaint, final Set<String> stopwords) { String ret = ""; if (complaint != null) { // Lowercase, alphabetic only, remove extra spaces.. final String cleaned = StringUtils.trimToNull(complaint.toString().toLowerCase(Locale.getDefault()) .replaceAll("h/a", "headache").replaceAll("n/v", "nausea vomiting").replaceAll("[/,]", " ") .replaceAll("[^a-z\\s]", " ")); if (cleaned != null) { final StringBuilder buf = new StringBuilder(); final String[] sp = cleaned.split("\\s"); for (int i = 0; i < sp.length; i++) { if (sp[i] != null && sp[i].length() > 1 && !stopwords.contains(sp[i])) { if (buf.length() > 0) { buf.append(" "); }/*from ww w .j ava 2s. c o m*/ buf.append(sp[i]); } } if (buf.length() > 0) { ret = buf.toString(); } } } return ret; }
From source file:com.khepry.utilities.GenericUtilities.java
public static String joinString(Collection<String> values, String delimiter) { StringBuilder sb = new StringBuilder(); for (String value : values) { sb.append(value);//from ww w. j ava 2 s.c om sb.append(delimiter); } if (sb.length() >= delimiter.length()) { sb.setLength(sb.length() - delimiter.length()); } return sb.toString(); }
From source file:com.khepry.utilities.GenericUtilities.java
public static String joinString(List<String> values, String delimiter) { StringBuilder sb = new StringBuilder(); for (String value : values) { sb.append(value);/*from w w w . j a v a2 s.c om*/ sb.append(delimiter); } if (sb.length() >= delimiter.length()) { sb.setLength(sb.length() - delimiter.length()); } return sb.toString(); }