List of usage examples for java.lang StringBuffer insert
@Override public StringBuffer insert(int offset, double d)
From source file:org.dataconservancy.dcs.integration.main.IngestTest.java
private String pad(String s, int length, char pad) { StringBuffer buffer = new StringBuffer(s); while (buffer.length() < length) { buffer.insert(0, pad); }/*from ww w .j a v a2s . c o m*/ return buffer.toString(); }
From source file:org.apache.myfaces.application.jsp.JspStateManagerImpl.java
private static void getPathToComponent(UIComponent component, StringBuffer buf) { if (component == null) return;//w w w. j a v a 2s . c o m StringBuffer intBuf = new StringBuffer(); intBuf.append("[Class: "); intBuf.append(component.getClass().getName()); if (component instanceof UIViewRoot) { intBuf.append(",ViewId: "); intBuf.append(((UIViewRoot) component).getViewId()); } else { intBuf.append(",Id: "); intBuf.append(component.getId()); } intBuf.append("]"); buf.insert(0, intBuf.toString()); if (component != null) { getPathToComponent(component.getParent(), buf); } }
From source file:by.iharkaratkou.TestServlet.java
private File checkExist(String fileName) { File f = new File(saveFile + "/" + fileName); // File f = new File("d:\\eclipse_workspace\\upload\\LICENSE"); System.out.println("fileName: " + saveFile + "/" + fileName); System.out.println("f.exists(): " + f.exists()); if (f.exists()) { StringBuffer sb = new StringBuffer(fileName); System.out.println("sb: " + sb); sb.insert(sb.lastIndexOf("."), "-" + new Date().getTime()); f = new File(saveFile + "/" + sb.toString()); System.out.println("sb.toString(): " + sb.toString()); }// w w w.j a va 2 s. c o m return f; }
From source file:com.zuoxiaolong.niubi.job.persistent.BaseDaoImpl.java
private <T extends AbstractEntity> int getTotalCount(StringBuffer sqlBuffer, List<Object> valueList) { sqlBuffer.insert(0, "select count(id) "); Query query = getHibernateSession().createQuery(sqlBuffer.toString()); setParameters(query, valueList);// w w w . j a v a 2s . c o m return ((Long) query.uniqueResult()).intValue(); }
From source file:co.id.app.sys.util.StringUtils.java
/** * To left pad the string with the format until it achieve the maximum length that specified * @param string//from w w w. j a va 2 s .co m * @param format * @param len * @return */ public static String lpad(String string, String format, int len) { StringBuffer buffer = new StringBuffer(string); while (buffer.length() < len) { buffer.insert(0, format); } return buffer.toString(); }
From source file:com.doculibre.constellio.wicket.components.form.LoggingTextArea.java
public LoggingTextArea(String id, final LineProvider lineProvider, long refreshDelayMillis) { super(id);/*ww w .jav a2 s. c o m*/ setModel(new LoadableDetachableModel() { @Override protected Object load() { List<String> potentialNewLines; if (lastLoggingDate == null) { potentialNewLines = lineProvider.getFirstLines(); lastLoggingDate = new Date(); } else { potentialNewLines = lineProvider.getLatestLines(DateUtils.addSeconds(lastLoggingDate, -30)); } // Remove unnecessary lines to avoid a slllloooooowwww memory leak! ;) int maxRows = 100; while (!loggedLines.isEmpty() && loggedLines.size() > maxRows) { // Remove oldest loggedLines.remove(0); } int firstLineToAdd = 0; for (String potentialNewLine : potentialNewLines) { if (!loggedLines.contains(potentialNewLine)) { break; } else { firstLineToAdd++; } } if (firstLineToAdd < potentialNewLines.size()) { loggedLines.addAll(potentialNewLines.subList(firstLineToAdd, potentialNewLines.size())); } StringBuffer sb = new StringBuffer(); for (String loggedLine : loggedLines) { sb.insert(0, loggedLine + "\n"); } if (!potentialNewLines.isEmpty()) { lastLoggingDate = new Date(); } return sb.toString(); } }); initComponents(refreshDelayMillis); }
From source file:com.eryansky.common.utils.DateUtil.java
/** * /* w ww. j a v a2 s. c om*/ * * @param canlendar * 2009080120090802080808 * @return 2009/08/012009/08/01 08:08:08 */ public static String toString(long canlendar) { try { StringBuffer sbCalendar = new StringBuffer(); sbCalendar.insert(0, canlendar); // ?? if (sbCalendar.length() == 8) { sbCalendar.insert(6, "/"); sbCalendar.insert(4, "/"); } else if (sbCalendar.length() == 14) { sbCalendar.insert(12, ":"); sbCalendar.insert(10, ":"); sbCalendar.insert(8, " "); sbCalendar.insert(6, "/"); sbCalendar.insert(4, "/"); } else { // ? return null; } // ?? return sbCalendar.toString(); } catch (Exception Exp) { // ? return null; } }
From source file:corner.orm.gae.impl.PaginatedJapEntityService.java
License:asdf
public long count(final Class<?> persistClass, final Object conditions) { return (Long) this.template.execute(new JpaCallback() { @Override/*www . j av a 2 s . c o m*/ public Object doInJpa(EntityManager entityManager) throws PersistenceException { Iterable con = typeCoercer.coerce(conditions, Iterable.class); final Iterator it = con == null ? null : con.iterator(); final StringBuffer sb = buildConditionJPQL(persistClass, it); sb.insert(0, "select count(root) "); Query query = entityManager.createQuery(sb.toString()); if (it != null) { int i = 0; while (it.hasNext()) { query.setParameter(i++, it.next()); } } return Long.parseLong(query.getSingleResult().toString()); } }); }
From source file:com.hihframework.core.utils.StringHelpers.java
/** * ??'a'-'z';1='a'...26='z',27='aa'...52='zz' * ??????/*www . j a va2 s . co m*/ * * @param num the num * @return the string */ public static String toAbcNumber(final int num) { int i = num; final StringBuffer str = new StringBuffer(); if (i <= 0) { return ""; } do { str.insert(0, chr[(i - 1) % chr.length]); i = i / chr.length; if ((i > 0) && (i < chr.length)) { str.insert(0, chr[i - 1]); } } while (i > chr.length); return str.toString(); }
From source file:jdiff.API.java
/** * <b>NOT USED</b>. /*from w w w .j a v a2s.c om*/ * * Replace all instances of <p> with <p/>. Just for the small number * of HMTL tags which don't require a matching end tag. * Also make HTML conform to the simple HTML requirements such as * no double hyphens. Double hyphens are replaced by - and the character * entity for a hyphen. * * Cases where this fails and has to be corrected in the XML by hand: * Attributes' values missing their double quotes , e.g. size=-2 * Mangled HTML tags e.g. <ttt> * * <p><b>NOT USED</b>. There is often too much bad HTML in * doc blocks to try to handle every case correctly. Better just to * stuff the *lt; and &: characters with stuffHTMLTags(). Though * the resulting XML is not as elegant, it does the job with less * intervention by the user. */ public static String convertHTMLTagsToXHTML(String htmlText) { StringBuffer sb = new StringBuffer(htmlText); int i = 0; boolean inTag = false; String tag = null; // Needs to re-evaluate this length at each loop while (i < sb.length()) { char c = sb.charAt(i); if (inTag) { if (c == '>') { // OPTION Could fail at or fix some errorneous tags here // Make the best guess as to whether this tag is terminated if (Comments.isMinimizedTag(tag) && htmlText.indexOf("</" + tag + ">", i) == -1) sb.insert(i, "/"); inTag = false; } else { // OPTION could also make sure that attribute values are // surrounded by quotes. tag += c; } } if (c == '<') { inTag = true; tag = ""; } // -- is not allowed in XML, but !-- is part of an comment, // and --> is also part of a comment if (c == '-' && i > 0 && sb.charAt(i - 1) == '-') { if (!(i > 1 && sb.charAt(i - 2) == '!')) { sb.setCharAt(i, '&'); sb.insert(i + 1, "#045;"); i += 5; } } i++; } if (inTag) { // Oops. Someone forgot to close their HTML tag, e.g. "<code." // Close it for them. sb.insert(i, ">"); } return sb.toString(); }