List of usage examples for java.lang StringBuffer insert
@Override public StringBuffer insert(int offset, double d)
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++;// w w w . jav a 2 s.c om } } return newName.toString().toUpperCase().trim(); }
From source file:org.chiba.xml.xforms.xpath.ExtensionFunctionsHelper.java
/** * Returns a date formatted according to ISO 8601 rules. * * @param date the date to format.//from w w w . j a va 2 s . c o m * @return the formmatted date. */ public static String formatISODate(Date date) { // always set time zone on formatter TimeZone timeZone = TimeZone.getDefault(); boolean utc = TimeZone.getTimeZone("UTC").equals(timeZone) || TimeZone.getTimeZone("GMT").equals(timeZone); String pattern = utc ? "yyyy-MM-dd'T'HH:mm:ss'Z'" : "yyyy-MM-dd'T'HH:mm:ssZ"; SimpleDateFormat format = new SimpleDateFormat(pattern); format.setTimeZone(timeZone); StringBuffer buffer = new StringBuffer(format.format(date)); if (!utc) { buffer.insert(buffer.length() - 2, ':'); } return buffer.toString(); }
From source file:org.ops4j.pax.web.service.internal.WelcomeFilesFilter.java
private static String addPaths(final String path1, final String path2) { if (path1 == null || path1.length() == 0) { if (path1 != null && path2 == null) { return path1; }//from w w w.ja va 2 s. c o m return path2; } if (path2 == null || path2.length() == 0) { return path1; } int split = path1.indexOf(';'); if (split < 0) { split = path1.indexOf('?'); } if (split == 0) { return path2 + path1; } if (split < 0) { split = path1.length(); } StringBuffer buf = new StringBuffer(path1.length() + path2.length() + 2); buf.append(path1); if (buf.charAt(split - 1) == '/') { if (path2.startsWith("/")) { buf.deleteCharAt(split - 1); buf.insert(split - 1, path2); } else { buf.insert(split, path2); } } else { if (path2.startsWith("/")) { buf.insert(split, path2); } else { buf.insert(split, '/'); buf.insert(split + 1, path2); } } return buf.toString(); }
From source file:com.abstratt.mdd.frontend.textuml.renderer.TextUMLRenderingUtils.java
public static String qualifiedName(NamedElement named) { StringBuffer qualifiedName = new StringBuffer(name(named)); for (Namespace namespace : named.allNamespaces()) { String namespaceName = name(namespace); if (namespaceName == null || namespaceName.isEmpty()) return null; qualifiedName.insert(0, NamedElement.SEPARATOR); qualifiedName.insert(0, namespaceName); }/*from w w w .j a v a 2 s. c om*/ return qualifiedName.toString(); }
From source file:com.griddynamics.jagger.diagnostics.visualization.GraphVisualizationHelper.java
private static String formatLabel(String string, int maxLength) { StringBuffer buffer = new StringBuffer(string); int runLength = 0; for (int i = 0; i < buffer.length(); i++) { if (buffer.charAt(i) != '\n') { runLength++;/*from w w w . j a v a2s . c om*/ } else { runLength = 0; } if (runLength >= maxLength) { buffer.insert(i, '\n'); runLength = 0; } } return buffer.toString().replaceAll("\\n", "<br/>"); }
From source file:ac.elements.parser.SimpleDBConverter.java
/** * Encodes real integer value into a string by offsetting and zero-padding * number up to the specified number of digits. Use this encoding method if * the data range set includes both positive and negative values. * //w ww. j a v a2s .com * com.xerox.amazonws.sdb.DataUtils * * @param number * int to be encoded * @return string representation of the int */ private static String encodeInt(int number) { int maxNumDigits = BigInteger.valueOf(Integer.MAX_VALUE).subtract(BigInteger.valueOf(Integer.MIN_VALUE)) .toString(RADIX).length(); long offsetValue = Integer.MIN_VALUE; BigInteger offsetNumber = BigInteger.valueOf(number).subtract(BigInteger.valueOf(offsetValue)); String longString = offsetNumber.toString(RADIX); int numZeroes = maxNumDigits - longString.length(); StringBuffer strBuffer = new StringBuffer(numZeroes + longString.length()); for (int i = 0; i < numZeroes; i++) { strBuffer.insert(i, '0'); } strBuffer.append(longString); return strBuffer.toString(); }
From source file:ac.elements.parser.SimpleDBConverter.java
/** * Encodes real long value into a string by offsetting and zero-padding * number up to the specified number of digits. Use this encoding method if * the data range set includes both positive and negative values. * //from www. j av a 2 s . co m * com.xerox.amazonws.sdb.DataUtils * * @param number * short to be encoded * @return string representation of the short */ private static String encodeShort(short number) { int maxNumDigits = BigInteger.valueOf(Short.MAX_VALUE).subtract(BigInteger.valueOf(Short.MIN_VALUE)) .toString(RADIX).length(); long offsetValue = Short.MIN_VALUE; BigInteger offsetNumber = BigInteger.valueOf(number).subtract(BigInteger.valueOf(offsetValue)); String longString = offsetNumber.toString(RADIX); int numZeroes = maxNumDigits - longString.length(); StringBuffer strBuffer = new StringBuffer(numZeroes + longString.length()); for (int i = 0; i < numZeroes; i++) { strBuffer.insert(i, '0'); } strBuffer.append(longString); return strBuffer.toString(); }
From source file:ac.elements.parser.SimpleDBConverter.java
/** * Encodes real long value into a string by offsetting and zero-padding * number up to the specified number of digits. Use this encoding method if * the data range set includes both positive and negative values. * // w ww . j a v a 2 s .c om * com.xerox.amazonws.sdb.DataUtils * * @param number * long to be encoded * @return string representation of the long */ private static String encodeLong(long number) { int maxNumDigits = BigInteger.valueOf(Long.MAX_VALUE).subtract(BigInteger.valueOf(Long.MIN_VALUE)) .toString(RADIX).length(); long offsetValue = Long.MIN_VALUE; BigInteger offsetNumber = BigInteger.valueOf(number).subtract(BigInteger.valueOf(offsetValue)); String longString = offsetNumber.toString(RADIX); int numZeroes = maxNumDigits - longString.length(); StringBuffer strBuffer = new StringBuffer(numZeroes + longString.length()); for (int i = 0; i < numZeroes; i++) { strBuffer.insert(i, '0'); } strBuffer.append(longString); return strBuffer.toString(); }
From source file:org.eclipse.wb.internal.swing.databinding.model.generic.GenericUtils.java
private static String resolveTypeName(ITypeBinding binding) throws Exception { if (binding.isArray()) { StringBuffer fullName = new StringBuffer(); for (int i = 0; i < binding.getDimensions(); i++) { fullName.append("[]"); }//from w ww . j a v a 2 s . c o m fullName.insert(0, resolveTypeName(binding.getElementType())); return fullName.toString(); } if (binding.isWildcardType()) { ITypeBinding boundType = binding.getBound(); if (boundType == null) { return "?"; } String fullName = binding.isUpperbound() ? "? extends " : "? super "; return fullName + resolveTypeName(boundType); } if (binding.isTypeVariable()) { return binding.getName(); } String className = AstNodeUtils.getFullyQualifiedName(binding, false); if (binding.isParameterizedType()) { StringBuffer fullName = new StringBuffer(); fullName.append(className); fullName.append("<"); ITypeBinding[] types = binding.getTypeArguments(); for (int i = 0; i < types.length; i++) { if (i > 0) { fullName.append(", "); } fullName.append(resolveTypeName(types[i])); } fullName.append(">"); return fullName.toString(); } return convertPrimitiveType(className); }
From source file:SystemIDResolver.java
/** * Replace spaces with "%20" and backslashes with forward slashes in * the input string to generate a well-formed URI string. * * @param str The input string//from ww w. j a v a 2s .c o m * @return The string after conversion */ private static String replaceChars(String str) { StringBuffer buf = new StringBuffer(str); int length = buf.length(); for (int i = 0; i < length; i++) { char currentChar = buf.charAt(i); // Replace space with "%20" if (currentChar == ' ') { buf.setCharAt(i, '%'); buf.insert(i + 1, "20"); length = length + 2; i = i + 2; } // Replace backslash with forward slash else if (currentChar == '\\') { buf.setCharAt(i, '/'); } } return buf.toString(); }