List of usage examples for java.lang StringBuilder length
int length();
From source file:com.imaginary.home.cloud.Configuration.java
static public @Nonnull String generateToken(int minLen, int maxLen) { int len = (maxLen > minLen ? minLen + random.nextInt(maxLen - minLen) : minLen); StringBuilder str = new StringBuilder(); while (str.length() < len) { char c = (char) random.nextInt(255); if (c >= 'a' && c <= 'z' && c != 'l' && c != 'o' && c != 'i') { str.append(c);// w w w . j ava 2 s . c om } else if (c >= 'A' && c <= 'Z' && c != 'I' && c != 'O') { str.append(c); } else if (c >= '2' && c <= '9') { str.append(c); } } return str.toString(); }
From source file:Main.java
/** * @param genotype//from w w w. j ava 2 s . co m * @param treatment * @return */ private static String getGenotypeAndTreatment(String genotype, String treatment) { StringBuilder res = new StringBuilder(); if (genotype != null && genotype.length() > 0) res.append(genotype); if (treatment != null && treatment.length() > 0) { if (res.length() > 0) res.append("/"); res.append(treatment); } if (res.length() > 0) return " (" + res.toString() + ")"; else return ""; }
From source file:com.predic8.membrane.core.util.TextUtil.java
public static Object removeFinalChar(String s) { StringBuilder sb = new StringBuilder(s); if (sb.length() > 0) sb.deleteCharAt(sb.length() - 1); return sb.toString(); }
From source file:Main.java
/** * Splits a string into a number of tokens. * The text is split by '?' and '*'./*from w w w .jav a 2 s. c o m*/ * Where multiple '*' occur consecutively they are collapsed into a single '*'. * * @param text the text to split * @return the array of tokens, never null */ static String[] splitOnTokens(String text) { // used by wildcardMatch // package level so a unit test may run on this if (text.indexOf('?') == -1 && text.indexOf('*') == -1) { return new String[] { text }; } char[] array = text.toCharArray(); ArrayList<String> list = new ArrayList<String>(); StringBuilder buffer = new StringBuilder(); for (int i = 0; i < array.length; i++) { if (array[i] == '?' || array[i] == '*') { if (buffer.length() != 0) { list.add(buffer.toString()); buffer.setLength(0); } if (array[i] == '?') { list.add("?"); } else if (list.isEmpty() || i > 0 && list.get(list.size() - 1).equals("*") == false) { list.add("*"); } } else { buffer.append(array[i]); } } if (buffer.length() != 0) { list.add(buffer.toString()); } return list.toArray(new String[list.size()]); }
From source file:com.intuit.tank.util.TestParamUtil.java
private static void addArgToBuilder(StringBuilder sb, String s) { if (sb.length() != 0) { sb.append(" "); }//from ww w . j a va 2 s .co m sb.append(s); }
From source file:com.mawujun.utils.ArrayUtils.java
/** * //ww w . j a va 2 s . co m * @param array * @param sperator * @return */ public static String toString(String[] array, String sperator) { if (array == null) { return null; } StringBuilder builder = new StringBuilder(); for (String str : array) { builder.append(str); builder.append(sperator); } return builder.substring(0, builder.length() - 1); }
From source file:Main.java
/** * @param s A string with commas./*from w w w. ja v a2s . com*/ * @return The same string, a newline appended after every comma. */ public static String commaToNewline(String s) { StringBuilder sb = new StringBuilder(); String[] split = s.split(","); for (String splitString : split) { sb.append(splitString).append(",").append("\n"); } if (sb.length() > 2) { sb.deleteCharAt(sb.length() - 2); } return sb.toString(); }
From source file:ClassUtil.java
/** * Report the full name of the object class, without the package information * * @param obj the object to name//from w w w . j a v a 2 s .c o m * @return the concatenation of (enclosing) simple names */ public static String nameOf(Object obj) { StringBuilder sb = new StringBuilder(); for (Class cl = obj.getClass(); cl != null; cl = cl.getEnclosingClass()) { if (sb.length() > 0) { sb.insert(0, "-"); } sb.insert(0, cl.getSimpleName()); } return sb.toString(); }
From source file:Main.java
public static String convertToString(Collection<String> strings, String delimiter) { if (strings != null) { StringBuilder result = new StringBuilder(); for (String string : strings) { result.append(string);//from w w w . j a v a 2s. c o m result.append(delimiter); } return result.substring(0, result.length() - 1); } return null; }
From source file:Main.java
public static String getArguments(ExecutableElement d) { Collection<? extends VariableElement> params = d.getParameters(); if (params.size() == 0) return ""; StringBuilder sbuf = new StringBuilder(params.size() * 20); for (VariableElement param : params) { sbuf.append(param.getSimpleName()); sbuf.append(','); }//from w w w . ja v a 2 s . com sbuf.setLength(sbuf.length() - 1); return sbuf.toString(); }