List of usage examples for java.lang StringBuilder length
int length();
From source file:com.msopentech.odatajclient.testservice.utils.Commons.java
public static String getEntityKey(final String entityId) { if (multiKeyPattern.matcher(entityId).matches()) { // assume correct multi-key final String[] keys = entityId.split(","); final StringBuilder keyBuilder = new StringBuilder(); for (String part : keys) { if (keyBuilder.length() > 0) { keyBuilder.append(" "); }/*from w w w.j a v a 2 s .co m*/ keyBuilder.append(part.split("=")[1].replaceAll("'", "").trim()); } return keyBuilder.toString(); } else { return entityId.trim(); } }
From source file:mrcg.utils.Utils.java
public static String toSpacedCamelCase(String s) { StringBuilder b = new StringBuilder(s.length() + 5); for (char c : s.toCharArray()) { if (Character.isUpperCase(c) && b.length() > 0) { b.append(' '); }/*from w w w. j av a 2 s. c o m*/ b.append(c); } return b.toString(); }
From source file:mrcg.utils.Utils.java
public static String toDatabaseFormat(String s) { StringBuilder b = new StringBuilder(s.length() + 5); for (char c : s.toCharArray()) { if (Character.isUpperCase(c) && b.length() > 0) { b.append('_'); }/*w ww . j av a 2s . c o m*/ b.append(Character.toLowerCase(c)); } return b.toString(); }
From source file:Main.java
public static String join(Map<? extends Object, ? extends Object> map, String keyValueSeparator, String entrySeparator) {//from w w w . ja v a 2 s . com StringBuilder sb = new StringBuilder(); for (Entry<? extends Object, ? extends Object> entry : map.entrySet()) { sb.append(entry.getKey().toString()); sb.append(keyValueSeparator); sb.append(entry.getValue().toString()); sb.append(entrySeparator); } if (sb.length() > 0 && entrySeparator.length() > 0) { sb.delete(sb.length() - entrySeparator.length(), sb.length()); } return sb.toString(); }
From source file:com.emc.ecs.sync.config.ConfigUtil.java
public static String labelize(String name) { StringBuilder label = new StringBuilder(); for (char c : name.toCharArray()) { if (Character.isUpperCase(c) && label.length() > 0) label.append(' '); label.append(label.length() == 0 ? Character.toUpperCase(c) : c); }/*from w w w . ja v a2 s . com*/ return label.toString(); }
From source file:hudson.plugins.ec2.EC2PrivateKey.java
static String digestOpt(Key k, String dg) throws IOException { try {//from w w w . j av a2s. co m MessageDigest md5 = MessageDigest.getInstance(dg); DigestInputStream in = new DigestInputStream(new ByteArrayInputStream(k.getEncoded()), md5); try { while (in.read(new byte[128]) > 0) ; // simply discard the input } finally { in.close(); } StringBuilder buf = new StringBuilder(); char[] hex = Hex.encodeHex(md5.digest()); for (int i = 0; i < hex.length; i += 2) { if (buf.length() > 0) buf.append(':'); buf.append(hex, i, 2); } return buf.toString(); } catch (NoSuchAlgorithmException e) { throw new AssertionError(e); } }
From source file:Main.java
public static String getRequestParamValue(Object obj, String charset) { if (obj == null) { return ""; }/* www . ja v a2s . c om*/ String value; if (obj instanceof List) { StringBuilder sb = new StringBuilder(); if (obj != null) { for (Object o : (List<?>) obj) { if (o != null) { sb.append(o.toString()); sb.append(','); } } } if (sb.length() > 0) { sb.deleteCharAt(sb.length() - 1); } value = sb.toString(); } else { value = obj.toString(); } try { return URLEncoder.encode(value, charset); } catch (UnsupportedEncodingException e) { return value; } }
From source file:com.seajas.search.utilities.web.WebPages.java
public static String joinText(Node[] html, String separator) { int count = html.length; if (logger.isDebugEnabled()) { String msg = "Joining %d nodes with '%s'"; logger.debug(String.format(msg, count, separator)); }/*from www. j a v a 2 s .com*/ StringBuilder text = new StringBuilder(); for (int i = 0; i < count; ++i) { String addition = getText(html[i]); if (addition.isEmpty()) continue; if (text.length() != 0 && separator != null) text.append(separator); text.append(addition); } return text.toString(); }
From source file:Main.java
public static List<String> splitSqlScript(String script, char delim) { List<String> statements = new ArrayList<String>(); StringBuilder sb = new StringBuilder(); boolean inLiteral = false; char[] content = script.toCharArray(); for (int i = 0; i < script.length(); i++) { if (content[i] == '"') { inLiteral = !inLiteral;/*from w ww .j av a 2 s . c om*/ } if (content[i] == delim && !inLiteral) { if (sb.length() > 0) { statements.add(sb.toString().trim()); sb = new StringBuilder(); } } else { sb.append(content[i]); } } if (sb.length() > 0) { statements.add(sb.toString().trim()); } return statements; }
From source file:com.emc.ecs.sync.config.ConfigUtil.java
public static String hyphenate(String name) { StringBuilder hyphenated = new StringBuilder(); for (char c : name.toCharArray()) { if (Character.isUpperCase(c) && hyphenated.length() > 0) hyphenated.append('-'); hyphenated.append(Character.toLowerCase(c)); }/*from w ww.j av a2s .c o m*/ return hyphenated.toString(); }