List of usage examples for java.lang StringBuilder length
int length();
From source file:com.nokia.testfw.codegen.StringResourceLoader.java
public static String getString(InputStream is) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(is)); StringBuilder sb = new StringBuilder(); String line = null;//www.j a v a 2 s . co m while ((line = reader.readLine()) != null) { if (sb.length() == 0) { sb.append(line); } else { sb.append("\n").append(line); } } is.close(); return sb.toString(); }
From source file:Main.java
/** * @param str/*w w w .j a v a2s. c o m*/ * @param width * @param padding * @return the string left filled with padding character passed */ public static synchronized String leftPad(String str, int width, char padding) { StringBuilder buff = new StringBuilder(); for (int i = 0; i < width; ++i) { buff.append(padding); } buff.append(str); return buff.substring(buff.length() - width); }
From source file:Main.java
public static String encodeParam(Map<String, String> params) { if (params == null) return ""; StringBuilder sb = new StringBuilder(); for (String key : params.keySet()) { Object val = params.get(key); if (sb.length() != 0) sb.append("&"); if (val instanceof Long[]) { Long[] longval = (Long[]) val; try { for (int i = 0; i < longval.length; i++) { String valStr = (val == null) ? "" : URLEncoder.encode(longval[i].toString(), "utf-8"); if (i != longval.length - 1) sb.append(key + "=" + valStr + "&"); else sb.append(key + "=" + valStr); }//w w w . j a va2 s . co m } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } else { try { String valStr = (val == null) ? "" : URLEncoder.encode(val.toString(), "utf-8"); sb.append(key + "=" + valStr); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } } return sb.toString(); }
From source file:Main.java
public static String[] splitByWhitespace(String str) { ArrayList<String> list = new ArrayList<String>(); StringBuilder buf = new StringBuilder(); for (int i = 0; i < str.length(); i++) { char ch = str.charAt(i); if (ch == ' ' || ch == '\t') { if (buf.length() > 0) { list.add(buf.toString()); buf = new StringBuilder(); }//from w w w . j av a 2 s. com } else { buf.append(ch); } } if (buf.length() > 0) list.add(buf.toString()); return list.toArray(new String[list.size()]); }
From source file:ca.cutterslade.match.scheduler.Main.java
private static String teamsString(final Match m) { final StringBuilder b = new StringBuilder(); for (final Team t : m.getTeams()) b.append(t.getName()).append(','); b.setLength(b.length() - 1); return b.toString(); }
From source file:dk.dma.msiproxy.web.TldFunctions.java
/** * Appends the given part to the string separated using a "-" divider character * @param str the string to append to//from www. j a va2s . c om * @param part the part to append */ private static void appendPart(StringBuilder str, String part) { if (StringUtils.isNotBlank(part)) { if (str.length() > 0) { str.append(" - "); } str.append(part); } }
From source file:net.certiv.antlr.project.util.Strings.java
public static String camelCase(String in) { StringBuilder sb = new StringBuilder(in); for (int idx = sb.length() - 1; idx >= 0; idx--) { char c = sb.charAt(idx); if (c == '_') { sb.deleteCharAt(idx);/*from ww w . ja v a 2s . co m*/ sb.setCharAt(idx, Character.toUpperCase(sb.charAt(idx))); } else if (Character.isUpperCase(c)) { sb.setCharAt(idx, Character.toLowerCase(c)); } } sb.setCharAt(0, Character.toLowerCase(sb.charAt(0))); return sb.toString(); }
From source file:Main.java
/** * Helper method to build a field String for creating the table in the format (field1, field2, * ...)//from ww w.ja va2s . co m * * @param fields * @return String in the format (field1, field2, ...) */ private static String toSQLFields(List<String> fields) { StringBuilder s = new StringBuilder(); s.append("("); for (String field : fields) { s.append(field); s.append(","); } s.replace(s.length() - 1, s.length(), ""); s.append(")"); return s.toString(); }
From source file:com.jaxio.celerio.util.PackageUtil.java
static public String assemblePackage(String... packageChunks) { StringBuilder sb = new StringBuilder(); for (String packageChunk : packageChunks) { if (stripToNull(packageChunk) != null) { if (sb.length() > 0) { sb.append("."); }/*from ww w .j ava 2s . com*/ sb.append(packageChunk.trim()); } } Validate.isTrue(sb.length() > 0, "An assembled package is null or empty!"); return sb.toString(); }
From source file:Main.java
@SuppressLint("InlinedApi") public static String statesDebug(int[] states) { if (states == null) { return "null"; }/* ww w . j ava 2 s . c o m*/ if (states.length == 0) { return "[]"; } Map<Integer, String> map = new HashMap<>(); map.put(android.R.attr.state_above_anchor, "above_anchor"); map.put(android.R.attr.state_accelerated, "accelerated"); map.put(android.R.attr.state_activated, "activated"); map.put(android.R.attr.state_active, "active"); map.put(android.R.attr.state_checkable, "checkable"); map.put(android.R.attr.state_checked, "checked"); map.put(android.R.attr.state_drag_can_accept, "drag_can_accept"); map.put(android.R.attr.state_drag_hovered, "drag_hovered"); map.put(android.R.attr.state_empty, "empty"); map.put(android.R.attr.state_enabled, "enabled"); map.put(android.R.attr.state_expanded, "expanded"); map.put(android.R.attr.state_first, "first"); map.put(android.R.attr.state_focused, "focused"); map.put(android.R.attr.state_hovered, "hovered"); map.put(android.R.attr.state_last, "last"); map.put(android.R.attr.state_long_pressable, "long_pressable"); map.put(android.R.attr.state_middle, "middle"); map.put(android.R.attr.state_multiline, "multiline"); map.put(android.R.attr.state_pressed, "pressed"); map.put(android.R.attr.state_selected, "selected"); map.put(android.R.attr.state_single, "single"); map.put(android.R.attr.state_window_focused, "window_focused"); StringBuilder sb = new StringBuilder(); sb.append("["); for (int state : states) { if (sb.length() > 1) { sb.append(','); } String s = map.get(state); if (s == null) { sb.append(state); } else { sb.append(s); } } sb.append(']'); return sb.toString(); }