List of usage examples for java.lang StringBuilder insert
@Override public StringBuilder insert(int offset, double d)
From source file:Main.java
public static String toIsoDateFormat(Date date) { 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);//from w w w. ja va 2 s .c o m StringBuilder buffer = new StringBuilder(format.format(date)); if (!utc) { buffer.insert(buffer.length() - 2, ':'); } return buffer.toString(); }
From source file:Main.java
public static String getFullPath(Node node) { StringBuilder buffer = new StringBuilder(); while (node != null) { buffer.insert(0, node.getNodeName()); char separator = '/'; if (node instanceof Attr) { separator = '@'; }//from w w w . j a v a 2s. co m buffer.insert(0, separator); node = node.getParentNode(); } return buffer.toString(); }
From source file:Main.java
public static String toRegularHashCode(String string) { final String hexHashCode = Integer.toHexString(string.hashCode()); final StringBuilder stringBuilder = new StringBuilder(hexHashCode); while (stringBuilder.length() < 8) { stringBuilder.insert(0, '0'); }//w w w .ja va2s. c o m return stringBuilder.toString(); }
From source file:Main.java
public static String validateBluetoothAddress(String address) { if (BluetoothAdapter.checkBluetoothAddress(address)) { return address; } else {//ww w. java2s . c om StringBuilder buf = new StringBuilder(17); buf.append(address.toUpperCase()); buf.insert(2, ':'); buf.insert(5, ':'); buf.insert(8, ':'); buf.insert(11, ':'); buf.insert(14, ':'); return buf.toString(); } }
From source file:Main.java
public static SpannableStringBuilder getFrontTextStyle(String frontText, String afterText, int frontColor, int frontTextSize) { StringBuilder sb = new StringBuilder(); sb.append("/").append(afterText); int len = sb.length(); sb.insert(0, frontText); SpannableStringBuilder style = new SpannableStringBuilder(sb); style.setSpan(new ForegroundColorSpan(frontColor), 0, sb.length() - len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); style.setSpan(new AbsoluteSizeSpan(frontTextSize), 0, sb.length() - len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); return style; }
From source file:Main.java
/** * this method expects the attributes in pairwise name, value form e.g. </br> attributes = [ "id", "12345", "size", * "15" ]/* w w w .ja v a2 s . c om*/ * * @param offset * TODO * @param bldr * @param surroundingTag * @param attributes * * @return */ public static void surround(int offset, StringBuilder bldr, String surroundingTag, String... attributes) { // TODO addTab bldr.insert(offset, '>'); for (int i = 0; i < attributes.length; i += 2) { // insert in reverted order bldr.insert(offset, "\" "); bldr.insert(offset, attributes[i + 1]); bldr.insert(offset, "=\""); bldr.insert(offset, attributes[i]); } bldr.insert(offset, ' '); bldr.insert(offset, surroundingTag); bldr.insert(offset, '<'); bldr.append("</"); bldr.append(surroundingTag); bldr.append('>'); }
From source file:Main.java
public static String int2String(int i, int digits, boolean leadingZero) { StringBuilder s = new StringBuilder(digits); s.append(Integer.toString(i)); while (s.length() < digits) { s.insert(0, (leadingZero ? "0" : " ")); }// ww w . jav a2s. c o m return s.toString(); }
From source file:Main.java
/** * @param subdocumento Subdocumento que queremos añadir * @param nombreEtiquetaPadre Nombre de la etiqueta padre de la cual va a colgar el subdocumento * @param documento documento con el que vamos a trabajar y al que se le va a añadir el subdocumento indicado * @return documento con el subdocumento añadido. *///from www.java 2 s .c o m public static String aniadeSubdocumento(String subdocumento, String nombreEtiquetaPadre, String documento) { StringBuilder stTmp = new StringBuilder(); stTmp.append("</").append(nombreEtiquetaPadre).append(">"); StringBuilder st = new StringBuilder(documento); int posicionEtiqueta = documento.indexOf(stTmp.toString()); st.insert(posicionEtiqueta, subdocumento); return st.toString(); }
From source file:Main.java
public static String long2String(long l, int minDigits) { StringBuilder s = new StringBuilder(minDigits); s.append(Long.toString(l));/* ww w. ja v a 2 s . c om*/ while (s.length() < minDigits) { s.insert(0, "0"); } return s.toString(); }
From source file:Main.java
public static String formatValue(long value) throws NumberFormatException { if (value < 0) { throw new NumberFormatException("Negative value " + value); }/*from ww w . j av a2 s.c o m*/ StringBuilder sb = new StringBuilder(Long.toString(value)); while (sb.length() <= 8) { sb.insert(0, '0'); } sb.insert(sb.length() - 8, '.'); while (sb.length() > 1 && (sb.charAt(sb.length() - 1) == '0' || sb.charAt(sb.length() - 1) == '.')) { sb.setLength(sb.length() - 1); } return sb.toString(); }