List of usage examples for java.lang StringBuilder delete
@Override public StringBuilder delete(int start, int end)
From source file:HashTagSegmenter.java
private List<String> segment(String text) { List<String> segments = new ArrayList<String>(); String currentSegment = ""; StringBuilder trimmedText = new StringBuilder(text); StringBuilder finalText = new StringBuilder(text); boolean foundLastWord = true; while (trimmedText.length() >= 0) { // returns text if text is empty or the last word is not found if ((trimmedText.length() == 0 && segments.size() == 0) || foundLastWord == false) { segments.clear();//from w w w . j av a2 s . co m segments.add(text); return segments; } // returns the segments if crude segment text has no more characters else if (trimmedText.length() == 0 && segments.size() > 0) { return segments; } // segments the crude segment text if not empty else if (trimmedText.length() > 0) { // adds text to segments list if text exists in Hashtable if (wordHashTable.containsKey(trimmedText.toString())) { // stores the segment for easy removal currentSegment = trimmedText.toString(); // newText only contains the key, adds it to list segments.add(currentSegment); // deletes the current segment from front of finalText finalText = new StringBuilder(finalText.delete(0, currentSegment.length())); // resets newText trimmedText = new StringBuilder(finalText.toString()); } // trims last letter of crude segment text if key doesn't exist else { trimmedText = trimmedText.deleteCharAt(trimmedText.length() - 1); if (trimmedText.length() == 0) { foundLastWord = false; } } } } // returns null if unable to segment return null; }
From source file:com.skilrock.lms.web.scratchService.gameMgmt.common.GameUploadAction.java
public void displayTicketsUploadInventoryAjax() { System.out.println("displayTicketsUploadInventoryAjax == " + getGameType() + " ,callFlag = " + callFlag); PrintWriter out;//from w w w . java 2 s . c o m try { out = getResponse().getWriter(); response.setContentType("text/html"); GameuploadHelper gameuploadHelper = new GameuploadHelper(); ArrayList<GameBean> gameList = gameuploadHelper.fatchGameList(getGameType()); StringBuilder gameString = new StringBuilder(); ; for (GameBean gameBean : gameList) { gameString.append("," + gameBean.getGameName()); } gameString.delete(0, 1); // get the supplier list first time if (callFlag != null && "FIRST".equalsIgnoreCase(callFlag.trim())) { Map<Integer, String> supplierList = gameuploadHelper.fatchSupplierList(); String supplierString = supplierList.toString().replace("{", "").replace("}", ""); gameString = gameString.append("||" + supplierString); } out.print(gameString.toString()); System.out.println("commited data == " + gameString); } catch (IOException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.cloud.server.ConfigurationServerImpl.java
private String cleanupTags(String tags) { if (tags != null) { String[] tokens = tags.split(","); StringBuilder t = new StringBuilder(); for (int i = 0; i < tokens.length; i++) { t.append(tokens[i].trim()).append(","); }//from www. ja v a 2 s. c o m t.delete(t.length() - 1, t.length()); tags = t.toString(); } return tags; }
From source file:net.sf.jabref.sql.exporter.DatabaseExporter.java
/** * Generates the SQL required to populate the entry_types table with jabref data. * * @param out The output (PrintSream or Connection) object to which the DML should be written. * @param type//w ww . j a va 2s . c o m */ private void populateEntryTypesTable(Connection out, BibDatabaseMode type) throws SQLException { List<String> fieldRequirement = new ArrayList<>(); List<String> existentTypes = new ArrayList<>(); try (Statement sm = out.createStatement(); ResultSet rs = sm.executeQuery("SELECT label FROM entry_types")) { while (rs.next()) { existentTypes.add(rs.getString(1)); } } for (EntryType val : EntryTypes.getAllValues(type)) { StringBuilder querySB = new StringBuilder(); fieldRequirement.clear(); for (int i = 0; i < SQLUtil.getAllFields().size(); i++) { fieldRequirement.add(i, "gen"); } List<String> reqFields = val.getRequiredFieldsFlat(); List<String> optFields = val.getOptionalFields(); List<String> utiFields = Collections.singletonList("search"); fieldRequirement = SQLUtil.setFieldRequirement(SQLUtil.getAllFields(), reqFields, optFields, utiFields, fieldRequirement); if (existentTypes.contains(val.getName().toLowerCase())) { String[] update = SQLUtil.getFieldStr().split(","); querySB.append("UPDATE entry_types SET \n"); for (int i = 0; i < fieldRequirement.size(); i++) { querySB.append(update[i]).append("='").append(fieldRequirement.get(i)).append("',"); } querySB.delete(querySB.lastIndexOf(","), querySB.length()); querySB.append(" WHERE label='").append(val.getName().toLowerCase()).append("';"); } else { querySB.append("INSERT INTO entry_types (label, ").append(SQLUtil.getFieldStr()) .append(") VALUES ('").append(val.getName().toLowerCase()).append('\''); for (String aFieldRequirement : fieldRequirement) { querySB.append(", '").append(aFieldRequirement).append('\''); } querySB.append(");"); } SQLUtil.processQuery(out, querySB.toString()); } }
From source file:net.sf.xfd.provider.ProviderBase.java
public static void removeDotSegments(StringBuilder chars) { if (chars.charAt(0) != '/') return;//w w w . ja va2s . co m /** * / proc / self / .. / vmstat */ int seg1 = 0, seg2 = 0, seg3 = 0, seg4 = 0; int segCnt = 0; for (int i = 1; i < chars.length(); ++i) { if ('/' == chars.charAt(i)) { int segStart = 0; switch (segCnt) { case 0: // seg2 == 0 seg2 = i; segStart = seg1; ++segCnt; break; case 1: // seg3 = 0 seg3 = i; segStart = seg2; ++segCnt; break; case 2: // seg4 = 0 seg4 = i; segStart = seg3; ++segCnt; break; case 3: // seg4 > 0, carry seg1 = seg2; seg2 = seg3; seg3 = seg4; seg4 = i; segStart = seg3; } final int segLength = i - segStart; switch (segLength) { default: break; case 2: if (chars.charAt(segStart + 1) == '.') { chars.delete(segStart, i); --segCnt; i = segStart; } break; case 3: if (chars.charAt(segStart + 1) == '.' && chars.charAt(segStart + 2) == '.') { final int prevSegmentStart; if (segCnt == 3) { prevSegmentStart = seg2; segCnt = 1; } else { prevSegmentStart = seg1; segCnt = 0; } chars.delete(prevSegmentStart, i); i = prevSegmentStart; } } } } final int resultLength = chars.length(); if ('/' != chars.charAt(resultLength - 1)) { int lastSlash, prevSlash = 0; switch (segCnt) { case 3: lastSlash = seg4; prevSlash = seg3; break; case 2: lastSlash = seg3; prevSlash = seg2; break; case 1: lastSlash = seg2; prevSlash = seg1; break; default: lastSlash = 0; } switch (resultLength - lastSlash) { case 2: if (chars.charAt(lastSlash + 1) == '.') { chars.delete(lastSlash + 1, resultLength + 1); } break; case 3: if (chars.charAt(lastSlash + 1) == '.' && chars.charAt(lastSlash + 2) == '.') { chars.delete(prevSlash + 1, resultLength + 1); } break; } } }
From source file:com.skilrock.lms.web.scratchService.gameMgmt.common.GameUploadAction.java
public void checkPackSeriesValidityAjax() throws LMSException { List<PackSeriesFlagBean> list = new ArrayList<PackSeriesFlagBean>(); System.out.println("from = " + packNumberFrom + " To = " + packNumberTo + " totalpack = " + totalPackStr); packNumberFrom = packNumberFrom[0].split(","); packNumberTo = packNumberTo[0].split(","); String tpStr[] = totalPackStr.split(","); int[] arr = new int[tpStr.length]; for (int i = 0; i < tpStr.length; i++) { arr[i] = Integer.parseInt(tpStr[i].trim()); }/*from w w w . j a v a2 s . c o m*/ totalpack = arr; PackSeriesFlagBean flagBean = null; int packfromsize = getPackNumberFrom().length; // int totPk = getTotalpack().length; // int packto = getPackNumberTo().length; System.out.println("fromLength = " + packNumberFrom.length + " ToLength = " + packNumberTo.length + " totalpackLength = " + totalpack.length); for (int i = 0; i < packfromsize; i++) { String pnf = packNumberFrom[i]; int totpack = totalpack[i]; String pnt = packNumberTo[i]; System.out.println("packnumber Series Start From(pnf) " + pnf + " End At(pnt) " + pnt); // check the pack series validity if (pnf != null && pnf != null && pnt != null && pnt != null) { flagBean = checkPackSeriesValidity(pnf, pnt, totpack); list.add(flagBean); } } setPackSeriesFlagList(list); HttpSession session = getRequest().getSession(); session.setAttribute("VERIFIED_PACKSERIES_FLAGBEAN_LIST", getPackSeriesFlagList()); System.out.println("VERIFIED_PACKSERIES_FLAGBEAN_LIST" + list); PrintWriter out; try { out = getResponse().getWriter(); response.setContentType("text/html"); StringBuilder responseStr = new StringBuilder(""); for (PackSeriesFlagBean bean : list) { responseStr.append("," + bean.getStatus()); } out.print(responseStr.delete(0, 1).toString()); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.example.nitish.welcomapp.activitypt.ElementDetailsFragment.java
/** * Get the electron configuration./*from w w w . j a va 2s . c om*/ */ @SuppressWarnings("deprecation") private void getElectronConfiguration() { final StringBuilder builder = new StringBuilder(); final StringBuilder descBuilder = new StringBuilder(); if (mElement.configuration.baseElement != null) { builder.append('[').append(mElement.configuration.baseElement).append("] "); final Element baseElement = Elements.getElement(mElement.configuration.baseElement); if (baseElement != null) { descBuilder.append(getString(ElementUtils.getElementName(baseElement.number))); descBuilder.append(", "); } } for (Element.Orbital orbital : mElement.configuration.orbitals) { builder.append(orbital.shell).append(orbital.orbital); builder.append("<sup><small>").append(orbital.electrons).append("</small></sup> "); descBuilder.append(orbital.shell).append(' '); descBuilder.append(String.valueOf(orbital.orbital).toUpperCase()).append(' '); descBuilder.append(orbital.electrons).append(", "); } descBuilder.delete(descBuilder.length() - 2, descBuilder.length() - 1); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { mTxtConfiguration.setText(Html.fromHtml(builder.toString().trim(), 0)); mTxtConfiguration.setContentDescription(Html.fromHtml(descBuilder.toString(), 0)); } else { mTxtConfiguration.setText(Html.fromHtml(builder.toString().trim())); mTxtConfiguration.setContentDescription(Html.fromHtml(descBuilder.toString())); } }
From source file:org.jspresso.hrsample.backend.JspressoModelTest.java
/** * Tests that 3+ level nested property changes get notified. *//*ww w . j a v a 2s . co m*/ @Test public void testSubNestedPropertyChange() { final HibernateBackendController hbc = (HibernateBackendController) getBackendController(); EnhancedDetachedCriteria crit = EnhancedDetachedCriteria.forClass(Department.class); final Department d = hbc.findFirstByCriteria(crit, EMergeMode.MERGE_LAZY, Department.class); final StringBuilder buff = new StringBuilder(); d.addPropertyChangeListener( OrganizationalUnit.MANAGER + "." + Employee.CONTACT + "." + ContactInfo.CITY + "." + Nameable.NAME, new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { buff.append(evt.getNewValue()); } }); City currentCity = d.getManager().getContact().getCity(); currentCity.setName("testSubNotif"); assertEquals("Sub-nested notification did not arrive correctly", currentCity.getName(), buff.toString()); buff.delete(0, buff.length()); City newCity = hbc.getEntityFactory().createEntityInstance(City.class); newCity.setName("newSubNotif"); newCity.setZip("12345"); d.getManager().getContact().setCity(newCity); assertEquals("Sub-nested notification did not arrive correctly", newCity.getName(), buff.toString()); buff.delete(0, buff.length()); newCity.setName("anotherOne"); assertEquals("Sub-nested notification did not arrive correctly", newCity.getName(), buff.toString()); buff.delete(0, buff.length()); currentCity.setName("noNotifExpected"); assertEquals("Sub-nested notification arrived whereas is shouldn't", "", buff.toString()); buff.delete(0, buff.length()); City anotherNewCity = hbc.getEntityFactory().createEntityInstance(City.class); anotherNewCity.setName("anotherNewCity"); anotherNewCity.setZip("12345"); Employee newManager = hbc.getEntityFactory().createEntityInstance(Employee.class); newManager.getContact().setCity(anotherNewCity); newManager.setCompany(d.getCompany()); d.setManager(newManager); assertEquals("Sub-nested notification did not arrive correctly", anotherNewCity.getName(), buff.toString()); buff.delete(0, buff.length()); anotherNewCity.setName("anotherNewNotif"); assertEquals("Sub-nested notification did not arrive correctly", anotherNewCity.getName(), buff.toString()); buff.delete(0, buff.length()); }
From source file:com.evolveum.midpoint.model.common.expression.functions.BasicExpressionFunctions.java
/** * Concatenates the arguments to create a name. * Each argument is stringified, trimmed and the result is concatenated by spaces. *///from w w w . ja v a 2s.c om public String concatName(Object... components) { if (components == null || components.length == 0) { return ""; } boolean endsWithSeparator = false; StringBuilder sb = new StringBuilder(); for (int i = 0; i < components.length; i++) { Object component = components[i]; if (component == null) { continue; } String stringComponent = stringify(component); if (stringComponent == null) { continue; } String trimmedStringComponent = trim(stringComponent); if (trimmedStringComponent.isEmpty()) { continue; } sb.append(trimmedStringComponent); if (i < (components.length - 1)) { sb.append(NAME_SEPARATOR); endsWithSeparator = true; } else { endsWithSeparator = false; } } if (endsWithSeparator) { sb.delete(sb.length() - NAME_SEPARATOR.length(), sb.length()); } return sb.toString(); }
From source file:com.virtusa.akura.reporting.controller.BestStudentAttendanceReportController.java
/** * Method is to return GradeClass list.//from w ww. ja v a2 s .com * * @param request - HttpServletRequest * @param modelMap - ModelMap attribute. * @return list of classGrade * @throws AkuraAppException - Detailed exception */ @RequestMapping(value = REQ_MAP_GRADECLASS_VALUE) @ResponseBody public String populateGradeClass(ModelMap modelMap, HttpServletRequest request) throws AkuraAppException { StringBuilder allGradeClass = new StringBuilder(); // get the selected grade id from UI int gradeId = Integer.parseInt(request.getParameter(REQ_SELECTED_VALUE)); // find grade object by grade id Grade grade = commonService.findGradeById(gradeId); // get all the classes under that grade List<ClassGrade> classGrades = SortUtil.sortClassGradeList(commonService.getClassGradeListByGrade(grade)); boolean isFirst = true; StringBuilder classes = new StringBuilder(); // get classes for (ClassGrade classGrade : classGrades) { classes.append(classGrade.getDescription()); classes.append(AkuraWebConstant.UNDERSCORE_STRING); classes.append(classGrade.getClassGradeId()); if (isFirst) { allGradeClass.append(classes.toString()); // append with no comma isFirst = false; } else { allGradeClass.append(AkuraWebConstant.STRING_COMMA); // append with comma allGradeClass.append(classes.toString()); } classes.delete(0, classes.length()); } // return all grades by appending class name with grade name , and with comma seperate grade id return allGradeClass.toString(); }