/** * Inserts the string representation of the specified boolean into this * buffer at the specified offset. * * @param index * the index at which to insert. * @param b * the boolean to insert. * @return this buffer. * @throws StringIndexOutOfBoundsException * if {@code index < 0} or {@code index > length()}. */ public StringBuffer insert(int index, boolean b) { return insert(index, b ? "true" : "false"); }
@Override public StringBuffer format(final Date date, final StringBuffer toAppendTo, final FieldPosition fieldPosition) { final StringBuffer formatted = this.dateFormat.format(date, toAppendTo, fieldPosition); formatted.insert(26, ':'); return formatted; }
String str = Integer.toString(j); str = new StringBuffer(str).insert(str.length()-2, ".").toString();
/** * Abbreviate element of name. * @param buf buffer to receive element. * @param startPos starting index of name element. * @return starting index of next element. */ public int abbreviate(final StringBuffer buf, final int startPos) { int nextDot = buf.toString().indexOf(".", startPos); if (nextDot != -1) { if ((nextDot - startPos) > charCount) { buf.delete(startPos + charCount, nextDot); nextDot = startPos + charCount; if (ellipsis != '\0') { buf.insert(nextDot, ellipsis); nextDot++; } } nextDot++; } return nextDot; } }
private CtClass toCtClass(Class rtclass) throws NotFoundException { String name; if (!rtclass.isArray()) name = rtclass.getName(); else { StringBuffer sbuf = new StringBuffer(); do { sbuf.append("[]"); rtclass = rtclass.getComponentType(); } while(rtclass.isArray()); sbuf.insert(0, rtclass.getName()); name = sbuf.toString(); } return classPool.get(name); }
/** * Inserts a backslash before every comma and backslash. */ private static String escape(String s) { StringBuffer buf = new StringBuffer(s); for (int i = 0; i < buf.length(); i++) { char c = buf.charAt(i); if (c == ',' || c == '\\') { buf.insert(i, '\\'); i++; } } return buf.toString(); }
private static String convertFromArray(String classname) { int index = classname.indexOf("[]"); if (index != -1) { String rawType = classname.substring(0, index); StringBuffer sb = new StringBuffer(Descriptor.of(rawType)); while (index != -1) { sb.insert(0, "["); index = classname.indexOf("[]", index + 1); } return sb.toString().replace('/', '.'); } return classname; }
private String createClassName(File root, File file) { StringBuffer sb = new StringBuffer(); String fileName = file.getName(); sb.append(fileName.substring(0, fileName.lastIndexOf(".class"))); file = file.getParentFile(); while (file != null && !file.equals(root)) { sb.insert(0, '.').insert(0, file.getName()); file = file.getParentFile(); } return sb.toString(); }
private String createGroovyClassName(File root, File file) { StringBuffer sb = new StringBuffer(); String fileName = file.getName(); sb.append(fileName.substring(0, fileName.lastIndexOf(".groovy"))); file = file.getParentFile(); while (file != null && !file.equals(root)) { sb.insert(0, '.').insert(0, file.getName()); file = file.getParentFile(); } return sb.toString(); }
/** * Inserts a backslash before every comma and backslash. */ private static String escape(String s) { StringBuffer buf = new StringBuffer(s); for (int i = 0; i < buf.length(); i++) { char c = buf.charAt(i); if (c == ',' || c == '\\') { buf.insert(i, '\\'); i++; } } return buf.toString(); }
/** * escape any occurrence of "/", "." and "\" */ private static String escape(String s) { StringBuffer sb = new StringBuffer(s); for (int i = 0; i < sb.length(); i++) { if (sb.charAt(i) == '/' || sb.charAt(i) == '\\' || sb.charAt(i) == '.') { sb.insert(i, '\\'); i++; } } return sb.toString(); }
private CtClass toCtClass(Class<?> rtclass) throws NotFoundException { String name; if (!rtclass.isArray()) name = rtclass.getName(); else { StringBuffer sbuf = new StringBuffer(); do { sbuf.append("[]"); rtclass = rtclass.getComponentType(); } while(rtclass.isArray()); sbuf.insert(0, rtclass.getName()); name = sbuf.toString(); } return classPool.get(name); }
public void insertData(int offset, String arg) throws DOMException { try { buffer.insert(offset, arg); } catch (ArrayIndexOutOfBoundsException ex) { throw new DOMException(DOMException.INDEX_SIZE_ERR, null); } }
public static void main(String[] args) { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ") { public StringBuffer format(Date date, StringBuffer toAppendTo, java.text.FieldPosition pos) { StringBuffer toFix = super.format(date, toAppendTo, pos); return toFix.insert(toFix.length()-2, ':'); }; }; // Usage: System.out.println(dateFormat.format(new Date())); }
static String mangle(String nodeName, int limit) { if (nodeName == null) throw new NullPointerException("The 'nodeName' parameter must not be null."); if (nodeName.equals("")) throw new IllegalArgumentException("The 'nodeName' parameter must not be empty."); if (nodeName.length() > limit) // create node name hash return getHash(nodeName); // escape any '/' and '\' characters in the node name StringBuffer nameBuffer = new StringBuffer(nodeName); for (int i = 0; i < nameBuffer.length(); i++) // 'i' can increase in loop if (nameBuffer.charAt(i) == '\\' || nameBuffer.charAt(i) == '/') nameBuffer.insert(i++, '\\'); return nameBuffer.toString(); }
private static String convertFromArray(String classname) { int index = classname.indexOf("[]"); if (index != -1) { String rawType = classname.substring(0, index); StringBuffer sb = new StringBuffer(Descriptor.of(rawType)); while (index != -1) { sb.insert(0, "["); index = classname.indexOf("[]", index + 1); } return sb.toString().replace('/', '.'); } return classname; }
/** * Gets the value as a String in the ISO8601 duration format including * only seconds and milliseconds. * <p> * For example, "PT72.345S" represents 1 minute, 12 seconds and 345 milliseconds. * <p> * For more control over the output, see * {@link com.facebook.presto.jdbc.internal.joda.time.format.PeriodFormatterBuilder PeriodFormatterBuilder}. * * @return the value as an ISO8601 string */ @ToString public String toString() { long millis = getMillis(); StringBuffer buf = new StringBuffer(); buf.append("PT"); boolean negative = (millis < 0); FormatUtils.appendUnpaddedInteger(buf, millis); while (buf.length() < (negative ? 7 : 6)) { buf.insert(negative ? 3 : 2, "0"); } if ((millis / 1000) * 1000 == millis) { buf.setLength(buf.length() - 3); } else { buf.insert(buf.length() - 3, "."); } buf.append('S'); return buf.toString(); }
/** Prepends one character, as a lump, to this string. @param ch the character to prepend */ void prepend(char ch) { assert checkInvariants(); int oldLen = string.length(); ensureCapacity(1 + oldLen); string.insert(0, ch); System.arraycopy(aux, 0, aux, 1, oldLen); aux[0] = LUMP_BEGIN | LUMP_END; assert checkInvariants(); }
private void init() { StringBuffer buf = new StringBuffer(200); for (Node temp = node; temp != null; temp = temp.jjtGetParent()) { buf.insert(0, "/" + temp.toString()); } add(new XPathFragmentAddingItem(NLS.nls("AST.MENU.NODE.ADD_ABSOLUTE_PATH"), model, buf.toString())); add(new XPathFragmentAddingItem(NLS.nls("AST.MENU.NODE.ADD_ALLDESCENDANTS"), model, "//" + node.toString())); } }