List of usage examples for java.lang StringBuffer length
@Override public synchronized int length()
From source file:com.cenrise.test.azkaban.Utils.java
public static String flattenToString(final Collection<?> collection, final String delimiter) { final StringBuffer buffer = new StringBuffer(); for (final Object obj : collection) { buffer.append(obj.toString());//from w w w . jav a2s .c om buffer.append(delimiter); } if (buffer.length() > 0) { buffer.setLength(buffer.length() - 1); } return buffer.toString(); }
From source file:Main.java
public static String getNodeHierarchy(Node node) { StringBuffer sb = new StringBuffer(); if (node != null) { Stack<Node> st = new Stack<Node>(); st.push(node);/*from w ww .ja v a2 s. com*/ Node parent = node.getParentNode(); while ((parent != null) && (parent.getNodeType() != Node.DOCUMENT_NODE)) { st.push(parent); parent = parent.getParentNode(); } // constructs node hierarchy Node n = null; while (!st.isEmpty() && null != (n = st.pop())) { if (n instanceof Element) { Element e = (Element) n; if (sb.length() == 0) { sb.append(e.getTagName()); } else { sb.append("/" + e.getTagName()); } } } } return sb.toString(); }
From source file:com.flattr4android.rest.FlattrRestClient.java
private static String getParameterString(String paramName, List<String> params) { if ((params == null) || (params.size() <= 0)) { return ""; }//from ww w . j a va2 s . c om StringBuffer result = new StringBuffer("/"); result.append(paramName); result.append("/"); for (String s : params) { result.append(s); result.append(","); } return result.substring(0, result.length() - 1); }
From source file:gr.abiss.calipso.wicket.customattrs.CustomAttributeUtils.java
public static void buildStringOptionTranslations(CalipsoService calipso, Language language, StringBuffer languageOptions, CustomAttributeLookupValue value) { // TODO:load in single query //logger.info("buildStringOptionTranslations lookup value: "+ value.getId()+", language: "+language); I18nStringResource res = calipso.loadI18nStringResource( new I18nStringIdentifier(value.getNameTranslationResourceKey(), language.getId())); if (res != null && value.isActive()) { // new line if not first if (languageOptions.length() > 0) { languageOptions.append("\n"); }//from w ww . jav a 2 s. c om // indent to resemble tree level for (int level = 1; level < value.getLevel(); level++) { languageOptions.append("\t"); } languageOptions.append(res.getValue()); if (value.getChildren() != null) { for (CustomAttributeLookupValue child : value.getChildren()) { buildStringOptionTranslations(calipso, language, languageOptions, child); } } } }
From source file:UUIDUtils.java
/** * @param secure Boolean indicating whether to create a secure UUID. * @see #createUUID()//w ww . j a v a2 s . c om */ public static String createUUID(boolean secure) { Random rand = secure ? _rand : _weakRand; StringBuffer s = new StringBuffer(36); appendHexString(uniqueTOD(), false, 11, s); // Just use random padding characters, but ensure that the high bit // is set to eliminate chances of collision with an IEEE 802 address. s.append(alphaNum.charAt(rand.nextInt(16) | 8)); // Add random padding characters. appendRandomHexChars(32 - s.length(), rand, s); //insert dashes in proper position. so the format matches CF s.insert(8, "-"); s.insert(13, "-"); s.insert(18, "-"); s.insert(23, "-"); return s.toString(); }
From source file:net.duckling.ddl.service.task.TakerWrapper.java
private static String getSome(List<TaskTaker> takers, int index) { StringBuffer sb = new StringBuffer(); String split = " | "; if (CommonUtil.isNullArray(takers)) { sb.append(""); return sb.toString(); }//from w w w . j a v a2s . co m for (TaskTaker taker : takers) { if (taker == null || CommonUtil.isNullStr(taker.getUserId())) { continue; } try { sb.append(taker.getUserId().split("%")[index]).append(split); } catch (Exception e) { continue; } } if (sb.indexOf(split) > 0) { sb.delete(sb.length() - split.length(), sb.length()); } return sb.toString(); }
From source file:org.hardisonbrewing.s3j.FileSyncer.java
static String getBucketPath(File file) { StringBuffer stringBuffer = new StringBuffer(); while (file != null && file.getParent() != null) { if (stringBuffer.length() > 0) { stringBuffer.insert(0, File.separator); }// w w w .jav a 2 s. co m stringBuffer.insert(0, file.getName()); file = file.getParentFile(); } String path = stringBuffer.toString(); path = path.replace(' ', '_'); return path; }
From source file:com.microsoft.tfs.core.httpclient.HttpState.java
/** * Returns a string representation of the credentials. * * @param credMap// ww w .j a va 2 s. co m * The credentials. * @return The string representation. */ private static String getCredentialsStringRepresentation(final Map<AuthScope, Credentials> credMap) { final StringBuffer sbResult = new StringBuffer(); final Iterator<AuthScope> iter = credMap.keySet().iterator(); while (iter.hasNext()) { final Object key = iter.next(); final Credentials cred = credMap.get(key); if (sbResult.length() > 0) { sbResult.append(", "); } sbResult.append(key); sbResult.append("#"); sbResult.append(cred.toString()); } return sbResult.toString(); }
From source file:com.qk.applibrary.db.sqlite.SqlBuilder.java
public static SqlInfo getUpdateSqlAsSqlInfo(Object entity, String strWhere) { TableInfo table = TableInfo.get(entity.getClass()); List<KeyValue> keyValueList = new ArrayList<KeyValue>(); //// www. ja v a 2s .c o m Collection<Property> propertys = table.propertyMap.values(); for (Property property : propertys) { KeyValue kv = property2KeyValue(property, entity); if (kv != null) keyValueList.add(kv); } if (keyValueList == null || keyValueList.size() == 0) { throw new DbException("this entity[" + entity.getClass() + "] has no property"); } SqlInfo sqlInfo = new SqlInfo(); StringBuffer strSQL = new StringBuffer("UPDATE "); strSQL.append(table.getTableName()); strSQL.append(" SET "); for (KeyValue kv : keyValueList) { strSQL.append(kv.getKey()).append("=?,"); sqlInfo.addValue(kv.getValue()); } strSQL.deleteCharAt(strSQL.length() - 1); if (!TextUtils.isEmpty(strWhere)) { strSQL.append(" WHERE ").append(strWhere); } sqlInfo.setSql(strSQL.toString()); return sqlInfo; }
From source file:com.qk.applibrary.db.sqlite.SqlBuilder.java
public static SqlInfo getUpdateSqlAsSqlInfo(Object entity) { TableInfo table = TableInfo.get(entity.getClass()); Object idvalue = table.getId().getValue(entity); if (null == idvalue) {//?null?? throw new DbException("this entity[" + entity.getClass() + "]'s id value is null"); }/*from w ww. ja va2 s .c o m*/ List<KeyValue> keyValueList = new ArrayList<KeyValue>(); // Collection<Property> propertys = table.propertyMap.values(); for (Property property : propertys) { KeyValue kv = property2KeyValue(property, entity); if (kv != null) keyValueList.add(kv); } if (keyValueList == null || keyValueList.size() == 0) return null; SqlInfo sqlInfo = new SqlInfo(); StringBuffer strSQL = new StringBuffer("UPDATE "); strSQL.append(table.getTableName()); strSQL.append(" SET "); for (KeyValue kv : keyValueList) { strSQL.append(kv.getKey()).append("=?,"); sqlInfo.addValue(kv.getValue()); } strSQL.deleteCharAt(strSQL.length() - 1); strSQL.append(" WHERE ").append(table.getId().getColumn()).append("=?"); sqlInfo.addValue(idvalue); sqlInfo.setSql(strSQL.toString()); return sqlInfo; }