List of usage examples for java.lang StringBuffer length
@Override public synchronized int length()
From source file:TokenizerUtil.java
public static String convertMapToCSVString(Map<String, String> urlDefaultMap) { StringBuffer sb = new StringBuffer(); Iterator<String> it = urlDefaultMap.keySet().iterator(); while (it.hasNext()) { if (sb.length() > 0) { sb.append("|"); }/*from ww w . jav a 2 s . c o m*/ String jdbcDriver = it.next(); String defaultURL = urlDefaultMap.get(jdbcDriver); sb.append(jdbcDriver + "|" + defaultURL); } return sb.toString(); }
From source file:com.redhat.rhn.common.util.ServletUtils.java
private static boolean endsWith(StringBuffer buffer, char c) { if (buffer.length() == 0) { return false; }//from ww w.j a v a2s . co m return buffer.charAt(buffer.length() - 1) == c; }
From source file:Main.java
/** * Converts a {@link Collection} to a {@link String} separating entries by * <code>, </code>.//w ww .ja va 2 s .com */ public static String toString(Collection<?> collection) { final StringBuffer string = new StringBuffer(); for (final Object object : collection) { string.append(object.toString()); string.append(", "); } string.delete(string.length() - 2, string.length()); return string.toString(); }
From source file:Main.java
/** * calculates the path of the node up in the hierarchy, example of result is * project/build/plugins/plugin level parameter designates the number of * parents to climb eg. for level 2 the result would be plugins/plugin level * -1 means all the way to the top.//from www.j ava2 s . c o m */ public static String pathUp(Node node, int level) { StringBuffer buf = new StringBuffer(); int current = level; while ((node != null) && (current > 0)) { if (node instanceof Element) { if (buf.length() > 0) { buf.insert(0, "/"); } buf.insert(0, node.getNodeName()); current = current - 1; } node = node.getParentNode(); } return buf.toString(); }
From source file:org.apache.bigtop.bigpetstore.qstream.Utils.java
/** * Borrowed from apache StringUtils./*w w w. j a v a 2 s . co m*/ */ public static String join(Collection var0, Object var1) { StringBuffer var2 = new StringBuffer(); for (Iterator var3 = var0.iterator(); var3.hasNext(); var2.append(var3.next())) { if (var2.length() != 0) { var2.append(var1); } } return var2.toString(); }
From source file:com.zimbra.common.util.RandomPassword.java
public static String generate(int minLength, int maxLength, String alphabet) { SecureRandom random = new SecureRandom(); // Calculate the desired length of the password int length;//from w ww . j a va 2 s . c om if (minLength > maxLength) { throw new IllegalArgumentException("minLength=" + minLength + " > maxLength=" + maxLength); } else if (minLength < maxLength) { length = minLength + random.nextInt(1 + maxLength - minLength); } else { length = maxLength; } int alphabetLength = alphabet.length(); int limit = byteLimit(alphabetLength); StringBuffer password = new StringBuffer(length); byte[] randomByte = new byte[1]; while (password.length() < length) { random.nextBytes(randomByte); int i = randomByte[0] + 128; if (i < limit) { password.append(alphabet.charAt(i % alphabetLength)); } } return password.toString(); }
From source file:NumberUtils.java
/** * Method to make specified length digit number string representation from particular * input number.//w ww . jav a 2s . c om * For example, if there will be send input number 32 and digit lenhth = 8, output * will be string '00000032' * * @param iInputNumber - input number that will be converted into 8 digit number * string representation * @param iDigitLength - length of the output digit number string * * @return String - digit number string representation */ public static String getDigitNumberString(int iInputNumber, int iDigitLength) { StringBuffer idString = new StringBuffer(Integer.toString(iInputNumber)); if (iDigitLength - idString.length() > 0) { idString.insert(0, ZEROCHARS, 0, iDigitLength - idString.length()); } return idString.toString(); }
From source file:Main.java
public static String wrap(String str, int w) { StringBuffer sb = new StringBuffer(); String line = ""; for (String s : regex_ws.split(str)) { if (!line.isEmpty() && line.length() + s.length() >= w) { if (sb.length() != 0) sb.append('\n'); sb.append(line);// ww w . ja v a 2 s . c o m line = s; } else { line = (line.isEmpty()) ? s : line + ' ' + s; } } if (!line.isEmpty()) { if (sb.length() != 0) sb.append('\n'); sb.append(line); } return sb.toString(); }
From source file:Main.java
/** * //from ww w.j a v a 2 s . c o m * @param array * @return String */ public static String toString(double[][] array) { final StringBuffer buffer = new StringBuffer(ARRAY_OPEN_TAG); for (int i = 0; i < array.length; i++) { final StringBuffer tempBuffer = new StringBuffer(Arrays.toString(array[i])); buffer.append(tempBuffer.substring(1, tempBuffer.length() - 1)); buffer.append(ARRAY_SEPARATOR); } buffer.append(ARRAY_CLOSE_TAG); return buffer.toString(); }
From source file:Main.java
public static String MapToUrl(Map<?, ?> data) { StringBuffer queryString = new StringBuffer(); for (Map.Entry<?, ?> pair : data.entrySet()) { queryString.append(pair.getKey() + "="); queryString.append(pair.getValue() + "&"); }//from w ww. j a v a 2 s. co m if (queryString.length() > 0) { queryString.deleteCharAt(queryString.length() - 1); } return queryString.toString(); }