List of usage examples for java.lang StringBuilder length
int length();
From source file:ke.co.tawi.babblesms.server.utils.StringUtil.java
/** * Converts a String {@link Map} into a String, for example for logging purposes * /* w ww . j a v a 2 s . c om*/ * @param map * @return a String representation of a Map. */ public static String mapToString(Map<String, String> map) { StringBuilder stringBuilder = new StringBuilder(); for (String key : map.keySet()) { if (stringBuilder.length() > 0) { stringBuilder.append("&"); } String value = map.get(key); stringBuilder.append(StringUtils.trimToEmpty(key)); stringBuilder.append("="); stringBuilder.append(StringUtils.trimToEmpty(value)); } return stringBuilder.toString(); }
From source file:ke.co.tawi.babblesms.server.utils.StringUtil.java
/** * Converts a {@link Map} into a String, for example for logging purposes * //from w w w . j av a 2s. co m * @param map * @return a String representation of a Map. */ public static String objMapToString(Map map) { StringBuilder stringBuilder = new StringBuilder(); for (Object key : map.keySet()) { if (stringBuilder.length() > 0) { stringBuilder.append("&"); } String value = map.get(key).toString(); stringBuilder.append(key.toString()); stringBuilder.append("="); stringBuilder.append(value.toString()); } return stringBuilder.toString(); }
From source file:Main.java
public static String join(int[] paramArrayOfInt) { StringBuilder localStringBuilder = new StringBuilder(11 * paramArrayOfInt.length); int i = paramArrayOfInt.length; for (int j = 0; j < i; j++) { int k = paramArrayOfInt[j]; if (localStringBuilder.length() != 0) localStringBuilder.append(","); localStringBuilder.append(k);/*from ww w . j a v a2 s . co m*/ } return localStringBuilder.toString(); }
From source file:Main.java
public static CharSequence readFile(Resources resources, int id) { BufferedReader in = null;/*from ww w. j a v a 2 s. c o m*/ try { in = new BufferedReader(new InputStreamReader(resources.openRawResource(id)), 8192); String line; StringBuilder buffer = new StringBuilder(); while ((line = in.readLine()) != null) { buffer.append(line).append('\n'); } // Chomp the last newline if (buffer.length() > 0) { buffer.deleteCharAt(buffer.length() - 1); } return buffer; } catch (IOException e) { return ""; } finally { closeStream(in); } }
From source file:Main.java
/** * Set the <code>schemaLocationAttribute</code> to the values of the * <code>schemaLocationMap</code>. * /* ww w. ja v a 2 s. c om*/ * @see <a href="http://www.w3.org/TR/xmlschema-0/#schemaLocation">XML Schema * Part 0: Primer Second Edition | 5.6 schemaLocation</a> * * @param schemaLocationMap * {@link Map} to get schema locations from. * @since 8.1 */ private static final String getSchemaLocationValue(final Map<String, List<String>> schemaLocationMap) { final StringBuilder sb = new StringBuilder(); for (final Map.Entry<String, List<String>> entry : schemaLocationMap.entrySet()) { for (final String schemaLocation : entry.getValue()) { if (sb.length() > 0) { sb.append(' '); } sb.append(entry.getKey()).append(' ').append(schemaLocation); } } return sb.toString(); }
From source file:max.hubbard.bettershops.Utils.ItemUtils.java
private static String mapToString(Map<String, Object> map) { StringBuilder stringBuilder = new StringBuilder(); for (String key : map.keySet()) { if (stringBuilder.length() > 0) { stringBuilder.append("&"); }//from w w w .ja v a 2s.co m String value = map.get(key).toString(); try { stringBuilder.append((key != null ? URLEncoder.encode(key, "UTF-8") : "")); stringBuilder.append("="); stringBuilder.append(value != null ? URLEncoder.encode(value, "UTF-8") : ""); } catch (UnsupportedEncodingException e) { throw new RuntimeException("This method requires UTF-8 encoding support", e); } } return stringBuilder.toString(); }
From source file:com.hmsinc.epicenter.webapp.util.URLUtils.java
/** * @param map//from w ww . ja v a 2s . c o m * @return */ public static String mapToQueryString(final Map<String, ? extends Object> map) { final StringBuilder sb = new StringBuilder(); if (map != null) { for (Map.Entry<String, ? extends Object> entry : map.entrySet()) { if (sb.length() > 0) { sb.append("&"); } try { sb.append(codec.encode(entry.getKey())).append("=") .append(codec.encode(entry.getValue().toString())); } catch (EncoderException e) { throw new IllegalArgumentException(e); } } } return sb.toString(); }
From source file:Main.java
/** * For logging./*from w ww. ja v a 2 s.c o m*/ * * @param arr * @return */ public static <T> String array2str(T[] arr) { StringBuilder sb = new StringBuilder("["); try { if (arr != null && arr.length > 0) { for (T elem : arr) { sb.append(elem.toString()).append(", "); } sb.delete(sb.length() - 2, sb.length()); } sb.append("]"); } catch (Exception e) { } return sb.toString(); }
From source file:Main.java
public static String join(long[] paramArrayOfLong) { StringBuilder localStringBuilder = new StringBuilder(11 * paramArrayOfLong.length); int i = paramArrayOfLong.length; for (int j = 0; j < i; j++) { long l = paramArrayOfLong[j]; if (localStringBuilder.length() != 0) localStringBuilder.append(","); localStringBuilder.append(l);// w w w. ja v a2 s . c om } return localStringBuilder.toString(); }
From source file:Main.java
/** * Trim leading whitespace from the given String. * @param str the String to check/*from w w w.ja v a2s . c o m*/ * @return the trimmed String * @see java.lang.Character#isWhitespace */ public static String trimLeadingWhitespace(String str) { if (!hasLength(str)) { return str; } StringBuilder sb = new StringBuilder(str); while (sb.length() > 0 && Character.isWhitespace(sb.charAt(0))) { sb.deleteCharAt(0); } return sb.toString(); }