List of usage examples for java.lang StringBuffer delete
@Override public synchronized StringBuffer delete(int start, int end)
From source file:ro.cs.cm.common.TextTable.java
public void addRow(String theRow, byte aRowAlign) { // dk am speficat ca nu avem nici o linie (doar headerul) // nu face nimic // adaug inca o linie la matricea tabel // log.debug("addRow() -> CurrentRowNo begin = " + currentRowNo); if (currentRowNo > MAX_NO_OF_ROWS_ALLOWED) { logger.info("No of allowed cols ".concat(String.valueOf(MAX_NO_OF_ROWS_ALLOWED))); }/*from w w w .j a va 2s . c om*/ ArrayList<String> row = new ArrayList<String>(); StringTokenizer st = new StringTokenizer(theRow, ELEMENT_SEPARATOR); rowAlign.add(new Byte(aRowAlign)); int j = 0; boolean amAvutCaracterEndLine = false; StringBuffer sb = new StringBuffer(); while (st.hasMoreElements()) { // punem un spatiu in stanga si in dreapta continutului sb.delete(0, sb.length()); // resetez StringBufferul sb.append(" "); String s = (String) st.nextElement(); if (s.indexOf('\n') != -1) { s = s.replace('\n', '?'); amAvutCaracterEndLine = true; } sb.append(s); sb.append(" "); row.add(sb.toString()); } // in cazul in care o linie nu este completa (ca numar de coloane), // completez if (j < header.length) { for (int i = j; i < header.length; row.add(" "), i++) { ; } } if (amAvutCaracterEndLine) { row.add(" (? = \\n)"); } table.add(row); // incrementez variabila statica currentRow pentru // a stii nr. de ordine al urmatoarei linii adaugate currentRowNo++; // log.debug("addRow() -> CurrentRowNo end = " + currentRowNo); }
From source file:org.eclipse.wb.internal.swt.model.layout.form.FormLayoutPreferences.java
/** * Returns space-separated string of percent values to be stored. *//*from w w w .j a va 2 s. com*/ private String getPercentsString(Collection<Integer> percents) { final StringBuffer buffer = new StringBuffer(); for (Integer percent : percents) { buffer.append(percent); buffer.append(" "); } buffer.delete(buffer.length() - 1, buffer.length()); return buffer.toString(); }
From source file:com.asociate.dao.UsuarioDAO.java
/** * * @param amigos/*from ww w . j a v a 2 s . c o m*/ * @return */ public List<Usuario> getAmigosDeLista(List<Amistad> amigos) { List<Usuario> salida = new ArrayList(); Session sesion = HibernateUtil.getSessionFactory().openSession(); StringBuffer sb = new StringBuffer(); for (Amistad am : amigos) { sb.append(" "); sb.append(am.getIdAmigo()); sb.append(" ,"); } sb.delete(sb.lastIndexOf(",") - 1, sb.length()); try { Query qu = sesion.createQuery("Select U from Usuario U where U.persona.idPersona in(:list)"); qu.setParameter("list", sb.toString()); salida = qu.list(); } catch (RuntimeException e) { e.printStackTrace(); } finally { sesion.flush(); sesion.close(); } return salida; }
From source file:model.manager.AdministrationManager.java
/** * Method getClinicAccessString./*from ww w . j a v a 2 s . c o m*/ * * @param u * User * @return String */ public static String getClinicAccessString(User u) { StringBuffer clinicList = new StringBuffer(); for (Clinic s : u.getClinics()) { clinicList.append(s.getClinicName()); clinicList.append(", "); } // remove last comma and spac if (clinicList.length() > 2) { clinicList = clinicList.delete(clinicList.length() - 2, clinicList.length()); } return clinicList.toString(); }
From source file:org.qedeq.base.utility.StringUtility.java
/** * Search for first line followed by whitespace and delete this string within the whole * text.// w w w. ja v a 2 s . c om * <p> * For example the following text *<pre> * Do you know the muffin man, * The muffin man, the muffin man, * Do you know the muffin man, * Who lives on Drury Lane? *</pre> * will be converted into: *<pre> *Do you know the muffin man, *The muffin man, the muffin man, *Do you know the muffin man, *Who lives on Drury Lane? *</pre> * * @param buffer Work on this text. */ public static void deleteLineLeadingWhitespace(final StringBuffer buffer) { int current = 0; int lastLf = -1; // detect position of last line feed before content starts (lastLf) while (current < buffer.length()) { if (!Character.isWhitespace(buffer.charAt(current))) { break; } if ('\n' == buffer.charAt(current)) { lastLf = current; } current++; } // string from last whitespace line feed until first non whitespace final String empty = buffer.substring(lastLf + 1, current); // delete this string out of the text if (empty.length() > 0) { // System.out.println(string2Hex(empty)); buffer.delete(lastLf + 1, current); // delete first occurence replace(buffer, "\n" + empty, "\n"); // delete same whitespace on all following lines } }
From source file:net.riezebos.thoth.configuration.persistence.dbs.DDLExecuter.java
private StringBuffer stripMultiLineComment(StringBuffer commandBuffer) { int beginComment = commandBuffer.indexOf("/*", 0); int endComment = 0;/* w w w . jav a 2s . c om*/ while (beginComment != -1) { endComment = commandBuffer.indexOf("*/", beginComment); commandBuffer = commandBuffer.delete(beginComment, endComment + 2); beginComment = commandBuffer.indexOf("/*"); } return commandBuffer; }
From source file:org.apache.lucene.analysis.de.GermanStemmer.java
/** * Removes a particle denotion ("ge") from a term. *//* w ww. j a va2s . co m*/ private void removeParticleDenotion(StringBuffer buffer) { if (buffer.length() > 4) { for (int c = 0; c < buffer.length() - 3; c++) { if (buffer.substring(c, c + 4).equals("gege")) { buffer.delete(c, c + 2); return; } } } }
From source file:org.kuali.rice.kim.impl.type.KimTypeAttributesHelper.java
public String getCommaDelimitedAttributesLabels(String commaDelimitedAttributesNamesList) { String[] names = StringUtils.splitByWholeSeparator(commaDelimitedAttributesNamesList, KimConstants.KimUIConstants.COMMA_SEPARATOR); StringBuffer commaDelimitedAttributesLabels = new StringBuffer(); for (String name : names) { commaDelimitedAttributesLabels//from ww w. j ava 2 s . c o m .append(getAttributeEntry().get(name.trim()) + KimConstants.KimUIConstants.COMMA_SEPARATOR); } if (commaDelimitedAttributesLabels.toString().endsWith(KimConstants.KimUIConstants.COMMA_SEPARATOR)) commaDelimitedAttributesLabels.delete( commaDelimitedAttributesLabels.length() - KimConstants.KimUIConstants.COMMA_SEPARATOR.length(), commaDelimitedAttributesLabels.length()); return commaDelimitedAttributesLabels.toString(); }
From source file:org.owasp.jbrofuzz.graph.canvas.ResponseSizeChart.java
private int calculateValue(final File inputFile) { if (inputFile.isDirectory()) { return -1; }/*from w ww . j a va 2 s .co m*/ long headerLength = 0L; BufferedReader inBuffReader = null; try { inBuffReader = new BufferedReader(new FileReader(inputFile)); final StringBuffer one = new StringBuffer(); int counter = 0; int got; while (((got = inBuffReader.read()) > 0) && (counter < MAX_CHARS)) { one.append((char) got); counter++; } inBuffReader.close(); one.delete(0, 5); one.delete(one.indexOf("\n--"), one.length()); headerLength = (one.indexOf(END_SIGNATURE) + END_SIGNATURE.length()); } catch (final IOException e1) { return -2; } catch (final StringIndexOutOfBoundsException e2) { return -3; } catch (final NumberFormatException e3) { return -4; } finally { IOUtils.closeQuietly(inBuffReader); } return (int) (inputFile.length() - headerLength); }
From source file:org.etudes.jforum.dao.generic.GenericSearchDAO.java
private void topicsByKeyword(SearchData sd) throws Exception { boolean isLike = "like".equals(SystemGlobals.getValue(ConfigKeys.SEARCH_WORD_MATCHING).trim()); String sql = isLike ? SystemGlobals.getSql("SearchModel.searchByLikeWord") : SystemGlobals.getSql("SearchModel.searchByWord"); PreparedStatement p = JForum.getConnection().prepareStatement(sql); Map eachWordMap = new HashMap(); String context = ToolManager.getCurrentPlacement().getContext(); // Get the post ids to which the words are associated to for (int i = 0; i < sd.getKeywords().length; i++) { if (isLike) { //Mallika's new code beg p.setString(1, context);//from w w w .ja va 2 s .co m //Mallika's new code end, line below changes from 1 to 2 p.setString(2, "%" + sd.getKeywords()[i].toLowerCase() + "%"); } else { //Mallika's new code beg p.setString(1, context); //Mallika's new code end, line below changes from 1 to 2 p.setString(2, sd.getKeywords()[i].toLowerCase()); } Set postsIds = new HashSet(); ResultSet rs = p.executeQuery(); while (rs.next()) { postsIds.add(new Integer(rs.getInt("post_id"))); } if (postsIds.size() > 0) { eachWordMap.put(sd.getKeywords()[i], postsIds); } } // [wordName] = { each, post, id } // If seach type is OR, then get all words // If it is AND, then we want only the ids common to all words Set postsIds = null; if (sd.getUseAllWords()) { for (Iterator iter = eachWordMap.values().iterator(); iter.hasNext();) { if (postsIds == null) { postsIds = new HashSet(eachWordMap.values().size()); postsIds.addAll((HashSet) iter.next()); } else { postsIds.retainAll((HashSet) iter.next()); } } } else { postsIds = new HashSet(); for (Iterator iter = eachWordMap.values().iterator(); iter.hasNext();) { postsIds.addAll((HashSet) iter.next()); } } if (postsIds == null || postsIds.size() == 0) { return; } // Time to get ready to search for the topics ids StringBuffer sb = new StringBuffer(1024); for (Iterator iter = postsIds.iterator(); iter.hasNext();) { sb.append(iter.next()).append(","); } sb.delete(sb.length() - 1, sb.length()); // Search for the ids, inserting them in the helper table sql = SystemGlobals.getSql("SearchModel.insertTopicsIds"); sql = sql.replaceAll(":posts:", sb.toString()); p = JForum.getConnection().prepareStatement(sql); p.setString(1, SessionFacade.getUserSession().getSessionId()); p.executeUpdate(); // Now that we have the topics ids, it's time to make a copy from the // topics table, to make the search faster ( damn, next version I'll // remove the search functionality. Look for this code's size ) this.selectTopicData(); p.close(); }