List of usage examples for java.lang StringBuffer charAt
@Override public synchronized char charAt(int index)
From source file:org.eclim.plugin.jdt.command.junit.JUnitUtils.java
private static void appendParameterNamesToMethodName(StringBuffer buffer, String[] parameters) { for (String parameter : parameters) { final StringBuffer buf = new StringBuffer( Signature.getSimpleName(Signature.toString(Signature.getElementType(parameter)))); final char character = buf.charAt(0); if (buf.length() > 0 && !Character.isUpperCase(character)) { buf.setCharAt(0, Character.toUpperCase(character)); }//from w ww . ja v a 2 s .c o m buffer.append(buf.toString()); for (int j = 0, arrayCount = Signature.getArrayCount(parameter); j < arrayCount; j++) { buffer.append("Array"); } } }
From source file:ubic.basecode.util.StringUtil.java
/** * Made by Nicolas/* www . j a va 2 s .c o m*/ * * @param a line in a file cvs format * @return the same line but in tsv format */ public static String cvs2tsv(String line) { StringBuffer newLine = new StringBuffer(line); boolean change = true; for (int position = 0; position < newLine.length(); position++) { if (newLine.charAt(position) == ',' && change) { newLine.setCharAt(position, '\t'); } else if (newLine.charAt(position) == '"') { if (change) { change = false; } else { change = true; } } } return newLine.toString().replaceAll("\"", ""); }
From source file:org.nuxeo.theme.styling.service.palettes.PaletteParser.java
public static String rgbToHex(int r, int g, int b) { final StringBuffer hexcolor = new StringBuffer("#"); final int[] rgb = { r, g, b }; for (final int val : rgb) { if (val < 16) { hexcolor.append("0"); }//from www. j av a 2s. c o m hexcolor.append(Integer.toHexString(val)); } // optimize #aabbcc to #abc if (hexcolor.charAt(1) == hexcolor.charAt(2) && hexcolor.charAt(3) == hexcolor.charAt(4) && hexcolor.charAt(5) == hexcolor.charAt(6)) { return "#" + hexcolor.charAt(1) + hexcolor.charAt(4) + hexcolor.charAt(6); } return hexcolor.toString(); }
From source file:org.kuali.rice.devtools.generators.dd.MaintDocDDCreator.java
public static String camelCaseToHelpParm(String className) { StringBuffer newName = new StringBuffer(className); // lower case the 1st letter newName.replace(0, 1, newName.substring(0, 1).toLowerCase()); // loop through, inserting spaces when cap for (int i = 0; i < newName.length(); i++) { if (Character.isUpperCase(newName.charAt(i))) { newName.insert(i, '_'); i++;//from w w w.j ava 2s. c om } } return newName.toString().toUpperCase().trim(); }
From source file:Main.java
/** * Normalize a uri containing ../ and ./ paths. * * @param uri The uri path to normalize//from w ww .j a v a 2 s .c o m * @return The normalized uri */ public static String normalize(String uri) { if ("".equals(uri)) { return uri; } int leadingSlashes; for (leadingSlashes = 0; leadingSlashes < uri.length() && uri.charAt(leadingSlashes) == '/'; ++leadingSlashes) { } boolean isDir = (uri.charAt(uri.length() - 1) == '/'); StringTokenizer st = new StringTokenizer(uri, "/"); LinkedList clean = new LinkedList(); while (st.hasMoreTokens()) { String token = st.nextToken(); if ("..".equals(token)) { if (!clean.isEmpty() && !"..".equals(clean.getLast())) { clean.removeLast(); if (!st.hasMoreTokens()) { isDir = true; } } else { clean.add(".."); } } else if (!".".equals(token) && !"".equals(token)) { clean.add(token); } } StringBuffer sb = new StringBuffer(); while (leadingSlashes-- > 0) { sb.append('/'); } for (Iterator it = clean.iterator(); it.hasNext();) { sb.append(it.next()); if (it.hasNext()) { sb.append('/'); } } if (isDir && sb.length() > 0 && sb.charAt(sb.length() - 1) != '/') { sb.append('/'); } return sb.toString(); }
From source file:info.magnolia.cms.core.Path.java
/** * <p>/*from w ww . j a v a2s. c o m*/ * Replace illegal characters by [_] [0-9], [A-Z], [a-z], [-], [_] * </p> * @param label label to validate * @return validated label */ public static String getValidatedLabel(String label) { StringBuffer s = new StringBuffer(label); StringBuffer newLabel = new StringBuffer(); for (int i = 0; i < s.length(); i++) { int charCode = s.charAt(i); // charCodes: 48-57: [0-9]; 65-90: [A-Z]; 97-122: [a-z]; 45: [-]; 95:[_] if (((charCode >= 48) && (charCode <= 57)) || ((charCode >= 65) && (charCode <= 90)) || ((charCode >= 97) && (charCode <= 122)) || charCode == 45 || charCode == 95) { newLabel.append(s.charAt(i)); } else { newLabel.append("-"); //$NON-NLS-1$ } } if (newLabel.length() == 0) { newLabel.append(DEFAULT_UNTITLED_NODE_NAME); } return newLabel.toString(); }
From source file:TimeUtils.java
public static String toBinaryText(StringBuffer buf) { boolean bufHasBinary = false; int len = buf.length(); for (int i = 0; i < len; i++) { if (buf.charAt(i) < ' ') { bufHasBinary = true;/*from w ww.j ava 2s. c om*/ break; } } if (bufHasBinary) { StringBuffer formatedDataBuf = new StringBuffer(); for (int k = 0; k < len; k++) { formatedDataBuf.append(printable(buf.charAt(k))); } formatedDataBuf.append(" 0x["); for (int k = 0; k < len; k++) { formatedDataBuf.append(toHex00String(buf.charAt(k))).append(' '); } formatedDataBuf.append("]"); buf = formatedDataBuf; } return buf.toString(); }
From source file:org.nuxeo.theme.presets.PaletteParser.java
public static String rgbToHex(int r, int g, int b) { final StringBuffer hexcolor = new StringBuffer("#"); final int[] rgb = { r, g, b }; for (final int val : rgb) { if (val < 16) { hexcolor.append("0"); }/*from ww w . j a v a2 s . c o m*/ hexcolor.append(Integer.toHexString(val)); } // optimize #aabbcc to #abc if (hexcolor.charAt(1) == hexcolor.charAt(2) && hexcolor.charAt(3) == hexcolor.charAt(4) && hexcolor.charAt(5) == hexcolor.charAt(6)) { return String.format("#%s%s%s", hexcolor.charAt(1), hexcolor.charAt(4), hexcolor.charAt(6)); } return hexcolor.toString(); }
From source file:net.duckling.ddl.util.StringUtil.java
License:asdf
public static String getRandomString(int length) { StringBuffer buffer = new StringBuffer("qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM"); StringBuffer sb = new StringBuffer(); Random r = new Random(); int range = buffer.length(); for (int i = 0; i < length; i++) { sb.append(buffer.charAt(r.nextInt(range))); }/* www. j a v a2 s . co m*/ return sb.toString(); }
From source file:org.kuali.continuity.security.SecurityUtil.java
/** * Inverse operation of decodeCookie./*from w w w .j a v a 2 s .c o m*/ * * @param cookieTokens the tokens to be encoded. * @return base64 encoding of the tokens concatenated with the ":" delimiter. */ public static String encodeCookie(String[] cookieTokens) { StringBuffer sb = new StringBuffer(); for (int i = 0; i < cookieTokens.length; i++) { sb.append(cookieTokens[i]); if (i < cookieTokens.length - 1) { sb.append("::"); } } String value = sb.toString(); sb = new StringBuffer(encode(value)); while (sb.charAt(sb.length() - 1) == '=') { sb.deleteCharAt(sb.length() - 1); } return sb.toString(); }