List of usage examples for java.lang StringBuilder length
int length();
From source file:lu.lippmann.cdb.dt.ui.DecisionTreeToGraphViewHelper.java
public static String buildHTML(final String title, final List<String> l) { final StringBuilder sb = new StringBuilder("<html>"); sb.append("<b>").append(title).append("</b><br/><br/>"); if (l != null) { for (final String s : l) { sb.append(StringEscapeUtils.escapeHtml(s)).append("<br/>"); }//from ww w . j a va 2 s . c om sb.setLength(sb.length() - 1); sb.append("</html>"); } return sb.toString(); }
From source file:Main.java
public static String quadKey(int x, int y, final int zoom) { final StringBuilder quadKey = new StringBuilder(); for (int i = zoom; i > 0; i--) { char digit = '0'; final int mask = 1 << (i - 1); if ((x & mask) != 0) { digit++;//from w w w.j a va 2 s . com } if ((y & mask) != 0) { digit++; digit++; } quadKey.append(digit); } if (quadKey.length() > 1) { quadKey.insert(0, "0"); } return quadKey.toString(); }
From source file:Main.java
private static String realCanonicalize(final String path, final int lastDot, final int initialState) { int state = initialState; int eatCount = 0; int tokenEnd = path.length(); final List<String> parts = new ArrayList<>(); for (int i = lastDot - 1; i >= 0; --i) { final char c = path.charAt(i); switch (state) { case NORMAL: { if (c == '/') { state = FIRST_SLASH;// www. j a v a 2 s. c o m if (eatCount > 0) { --eatCount; tokenEnd = i; } } break; } case FIRST_SLASH: { if (c == '.') { state = ONE_DOT; } else if (c == '/') { if (eatCount > 0) { --eatCount; tokenEnd = i; } else { parts.add(path.substring(i + 1, tokenEnd)); tokenEnd = i; } } else { state = NORMAL; } break; } case ONE_DOT: { if (c == '.') { state = TWO_DOT; } else if (c == '/') { if (i + 2 != tokenEnd) { parts.add(path.substring(i + 2, tokenEnd)); } tokenEnd = i; state = FIRST_SLASH; } else { state = NORMAL; } break; } case TWO_DOT: { if (c == '/') { if (i + 3 != tokenEnd) { parts.add(path.substring(i + 3, tokenEnd)); } tokenEnd = i; eatCount++; state = FIRST_SLASH; } else { state = NORMAL; } } } } final StringBuilder result = new StringBuilder(); if (tokenEnd != 0) { result.append(path.substring(0, tokenEnd)); } for (int i = parts.size() - 1; i >= 0; --i) { result.append(parts.get(i)); } if (result.length() == 0) { return "/"; } return result.toString(); }
From source file:com.fluidops.iwb.ui.configuration.WikiWidgetConfigurationForm.java
/** * Searches for the end of a widget configuration in a string having a * string and the start index of the widget configuration. Returns -1 if * nothing found//w w w .j ava2 s. co m * * @param searchString * @param widgetStart */ private static int findWidgetConfigurationEnd(String searchString, int widgetStart) { if (widgetStart < 0 || widgetStart > searchString.length()) return -1; StringBuilder sb = new StringBuilder(searchString.substring(widgetStart)); int numberOfBrackets = 0; for (int i = 0; i < sb.length(); i++) { if (sb.charAt(i) == '{') { numberOfBrackets++; } else if (sb.charAt(i) == '}') { numberOfBrackets--; } if (numberOfBrackets == 0) { return widgetStart + i + 1; } } return -1; }
From source file:com.sic.bb.jenkins.plugins.sicci_for_xcode.util.PluginUtils.java
public static Pattern createPattern(List<String> stringList) { StringBuilder regex = new StringBuilder(); if (stringList != null) { regex.append('('); for (String item : stringList) { if (StringUtils.isBlank(item)) continue; regex.append(stringToPattern(item)); regex.append('|'); }//from w ww .ja va 2s . c om regex.deleteCharAt(regex.length() - 1); regex.append(')'); } return Pattern.compile(regex.toString()); }
From source file:es.uvigo.ei.sing.adops.datatypes.BatchProject.java
private final static String filesToFilenames(File[] files) { final StringBuilder sb = new StringBuilder(); for (File file : files) { if (sb.length() > 0) sb.append(','); sb.append(file.getAbsolutePath()); }/*from w ww.j a v a2s. c o m*/ return sb.toString(); }
From source file:Main.java
public static String getTextContent(Node e) { if (e == null || e.getNodeType() != Node.ELEMENT_NODE) { return null; }/*w w w. ja va 2 s . c o m*/ NodeList nodes = e.getChildNodes(); StringBuilder text = new StringBuilder(); for (int i = 0; i < nodes.getLength(); i++) { Node node = e.getFirstChild(); if (node != null && node.getNodeType() == Node.TEXT_NODE) { String s = node.getNodeValue(); if (s != null) { text.append(s); } } } if (text.length() > 0) { return text.toString(); } else { return null; } }
From source file:com.adaptris.core.marshaller.xstream.XStreamUtils.java
/** * Converts a camelcase name into a lowercase hyphen separated format for output to XML. Used by the marshalling process to * convert a java class/field name into an xml element name. * * @param fieldName - Current element name to be processed. * @return translated name//from w w w . j ava2 s . co m */ public static String toXmlElementName(String fieldName) { if (fieldName == null) { return null; } if (fieldName.length() == 0) { return fieldName; } if (fieldName.length() == 1) { return fieldName.toLowerCase(); } // -- Follow the Java beans Introspector::decapitalize // -- convention by leaving alone String that start with // -- 2 uppercase characters. if (Character.isUpperCase(fieldName.charAt(0)) && Character.isUpperCase(fieldName.charAt(1))) { return fieldName; } // -- process each character StringBuilder cbuff = new StringBuilder(fieldName); cbuff.setCharAt(0, Character.toLowerCase(cbuff.charAt(0))); boolean ucPrev = false; for (int i = 1; i < cbuff.length(); i++) { char ch = cbuff.charAt(i); if (Character.isUpperCase(ch)) { if (ucPrev) { continue; } ucPrev = true; cbuff.insert(i, '-'); ++i; cbuff.setCharAt(i, Character.toLowerCase(ch)); } else { ucPrev = false; } } return cbuff.toString(); }
From source file:Main.java
/** * Converts a map into a delimited string value. * A "{@literal =}" separates the keys and values and a "{@literal &}" separates the key pairs. * @param stringMap map to convert// w w w .j av a 2 s . co m * @return string representation of map */ public static String convertMapToString(final Map<String, String> stringMap) { final StringBuilder sb = new StringBuilder(); final char keySeparator = '='; final char pairSeparator = '&'; for (final Map.Entry<String, String> pair : stringMap.entrySet()) { sb.append(pair.getKey()); sb.append(keySeparator); sb.append(pair.getValue()); sb.append(pairSeparator); } return sb.toString().substring(0, sb.length() - 1); }
From source file:com.hmsinc.epicenter.surveillance.notification.EventNotifierUtils.java
public static String makeAgeGroupAndGenderString(final Anomaly anomaly) { // Just do this in Java because it's too goofy in Velocity final String genders = StringUtils.trimToNull(makeAttributeString( anomaly.getSet().getAttribute(com.hmsinc.epicenter.model.attribute.Gender.class))); final String ageGroups = StringUtils.trimToNull(makeAttributeString( anomaly.getSet().getAttribute(com.hmsinc.epicenter.model.attribute.AgeGroup.class))); final StringBuilder sb = new StringBuilder(); if (genders != null || ageGroups != null) { if (ageGroups != null) { sb.append("grouped by age as ").append(ageGroups); }//from w ww . j a v a 2 s .co m if (genders != null) { if (sb.length() > 0) { sb.append("; and "); } sb.append("grouped by gender as ").append(genders); } sb.append(") "); sb.insert(0, "(for patients "); } return sb.toString(); }