List of usage examples for java.lang StringBuilder delete
@Override public StringBuilder delete(int start, int end)
From source file:com.cloud.utils.db.SqlGenerator.java
protected StringBuilder buildInsertSql(String table, ArrayList<Attribute> attrs) { StringBuilder sql = new StringBuilder("INSERT INTO "); sql.append(table).append(" ("); for (Attribute attr : attrs) { sql.append(table).append(".").append(attr.columnName).append(", "); }/*from www . j av a 2 s.co m*/ if (attrs.size() > 0) { sql.delete(sql.length() - 2, sql.length()); } sql.append(") VALUES ("); for (int i = 0; i < attrs.size(); i++) { sql.append("?, "); } if (attrs.size() > 0) { sql.delete(sql.length() - 2, sql.length()); } sql.append(")"); return sql; }
From source file:edu.chalmers.dat076.moviefinder.service.TitleParser.java
private TemporaryMedia getInformation(StringBuilder mySb) { TemporaryMedia returnMedia = new TemporaryMedia(); StringBuilder wordSb = new StringBuilder(); int tmpYear;/*from ww w.ja v a 2s . com*/ int year = -1; int thisYear = Calendar.getInstance().get(Calendar.YEAR); boolean deleteYear = false; boolean finalWord = true; for (int i = 0; i < mySb.length(); i++) { if (mySb.charAt(i) == '.' || mySb.charAt(i) == ' ' || mySb.charAt(i) == '-' || mySb.charAt(i) == '_') { if (Constants.MOVIE_FILE_ENDING_WORDS.contains(wordSb.toString())) { mySb.delete(i - (wordSb.length() + 1), mySb.length()); finalWord = false; // final useful word found. No point in continuing. break; } mySb.replace(i, i + 1, " "); tmpYear = checkForYear(wordSb); if (tmpYear > 1900 && tmpYear <= thisYear) { year = tmpYear; deleteYear = true; } wordSb.setLength(0); } else if (wordSb.length() == 0 && (mySb.charAt(i) == 'S' || mySb.charAt(i) == 's' || Character.isDigit(mySb.charAt(i)))) { // See if new word contains series and episode information. StringBuilder whatsLeft = new StringBuilder(mySb.subSequence(i, mySb.length())); if (getEpisodePotential(whatsLeft)) { TemporaryMedia tmpMedia = getEpisodeInfo(whatsLeft); returnMedia.setIsMovie(false); returnMedia.setSeason(tmpMedia.getSeason()); returnMedia.setEpisode(tmpMedia.getEpisode()); mySb.delete(i, mySb.length()); // series and episode information saved. No point in continuing. break; } else { wordSb.append(mySb.charAt(i)); } } else if (mySb.charAt(i) == '[' || mySb.charAt(i) == '(') { // Brackets shoudl usually be removed. They could possibly contain realease year. if (Constants.MOVIE_FILE_ENDING_WORDS.contains(wordSb.toString())) { mySb.delete(i - (wordSb.length() + 1), mySb.length()); finalWord = false; // final useful word found. No point in continuing. break; } tmpYear = checkForYear(wordSb); if (tmpYear > 1900 && tmpYear <= thisYear) { year = tmpYear; deleteYear = true; } wordSb.setLength(0); if (mySb.charAt(i) == '[') { tmpYear = removeUntil(mySb, i, ']'); } else if (mySb.charAt(i) == '(') { tmpYear = removeUntil(mySb, i, ')'); } if (tmpYear > 1900 && tmpYear <= thisYear) { year = tmpYear; deleteYear = false; } i--; // Need to compensate for removing bracket. } else { // Nothing useful here. Save the char and continue. wordSb.append(mySb.charAt(i)); } } if (finalWord && Constants.MOVIE_FILE_ENDING_WORDS.contains(wordSb.toString())) { mySb.delete(mySb.length() - wordSb.length(), mySb.length()); } else { tmpYear = checkForYear(wordSb); if (tmpYear > 1900 && tmpYear <= thisYear) { year = tmpYear; deleteYear = true; } } if (deleteYear && returnMedia.IsMovie()) { int i = mySb.lastIndexOf(year + ""); mySb.delete(i, i + 4); } returnMedia.setYear(year); returnMedia.setName(mySb.toString().trim()); return returnMedia; }
From source file:com.bazaarvoice.seo.sdk.BVManagedUIContent.java
public String getAggregateRating(BVParameters bvQueryParams) { long startTime = System.currentTimeMillis(); postProcess(bvQueryParams);/*from w w w .j a v a 2 s . com*/ StringBuilder uiContent = null; if (StringUtils.isBlank(validationError)) { if (bvUiContentService.isSdkEnabled()) { uiContent = bvUiContentService.executeCall(reloadContent); } else { _logger.info(BVMessageUtil.getMessage("MSG0003")); uiContent = new StringBuilder(); } if (uiContent != null) { int startIndex = uiContent.indexOf("<!--begin-reviews-->"); if (startIndex != -1) { String endReviews = "<!--end-reviews-->"; int endIndex = uiContent.indexOf(endReviews) + endReviews.length(); uiContent.delete(startIndex, endIndex); startIndex = uiContent.indexOf("<!--begin-pagination-->"); if (startIndex != -1) { String endPagination = "<!--end-pagination-->"; endIndex = uiContent.indexOf(endPagination) + endPagination.length(); uiContent.delete(startIndex, endIndex); } } startIndex = uiContent.indexOf("<!--begin-aggregate-rating-->"); if (startIndex == -1 && bvUiContentService.getMessage().length() == 0) { message.append(BVMessageUtil.getMessage("ERR0003")); } } else { uiContent = new StringBuilder(); } bvFooter.addMessage(bvUiContentService.getMessage().toString()); } else { uiContent = new StringBuilder(); bvFooter.addMessage(validationError); } bvFooter.addMessage(message.toString()); bvFooter.setExecutionTime(System.currentTimeMillis() - startTime); uiContent.append(bvFooter.displayFooter("getAggregateRating")); return uiContent.toString(); }
From source file:com.doctor.other.concurrent_hash_map_based_table.ConcurrentHashMapBasedTable.java
@Override public String toString() { final String padding = "-----------"; StringBuilder stringBuilder = new StringBuilder(256); table.forEach((row, value) -> {/*from w ww.jav a2 s. co m*/ stringBuilder.append("row: ").append(row).append(", "); value.forEach((colum, value2) -> { stringBuilder.append("colum: ").append(colum).append(", "); value2.forEach((timesplice, value3) -> { stringBuilder.append("timesplice: [").append(timesplice).append("] "); stringBuilder.append(" values: ").append(value3).append("; "); }); stringBuilder.append("\n").append(padding); }); int index = stringBuilder.lastIndexOf(padding); index = index == -1 ? 0 : index; stringBuilder.delete(index, stringBuilder.length()); stringBuilder.append("\n"); }); return stringBuilder.toString(); }
From source file:org.alfresco.repo.content.transform.EMLParser.java
/** * Convert addresses to string.//from w w w . j a va 2s .c o m * * @param addresses * the addresses * @return the string */ private String convertAddressesToString(Address[] addresses) { StringBuilder result = new StringBuilder(); if (addresses != null) { String addressToAdd; for (int i = 0; i < addresses.length; i++) { addressToAdd = addresses[i].toString().replaceAll("<", "").replaceAll(">", ""); result.append(addressToAdd).append("; "); } int resultLength = result.length(); if (resultLength > 1) result.delete(resultLength - 2, resultLength); } return result.toString(); }
From source file:com.virtusa.akura.reporting.controller.CRExamAbsentListController.java
/** * Method is to return GradeClass list.// w w w.ja v a2 s . c om * * @param request - HttpServletRequest * @param modelMap - ModelMap attribute. * @return list of classGrade * @throws AkuraAppException - Detailed exception */ @RequestMapping(value = GRADE_CLASS_HTM) @ResponseBody public String populateGradeClass(ModelMap modelMap, HttpServletRequest request) throws AkuraAppException { StringBuilder allGradeClass = new StringBuilder(); int gradeId = Integer.parseInt(request.getParameter(SELECTED_VALUE)); Grade grade = commonService.findGradeById(gradeId); List<ClassGrade> classGrades = SortUtil.sortClassGradeList(commonService.getClassGradeListByGrade(grade)); boolean isFirst = true; StringBuilder classes = new StringBuilder(); for (ClassGrade classGrade : classGrades) { classes.append(classGrade.getDescription()); classes.append(STRING_UNDERSCORE); classes.append(classGrade.getClassGradeId()); if (isFirst) { allGradeClass.append(classes.toString()); // no comma isFirst = false; } else { allGradeClass.append(STRING_COMMA); // comma allGradeClass.append(classes.toString()); } classes.delete(0, classes.length()); } return allGradeClass.toString(); }
From source file:com.bazaarvoice.seo.sdk.BVManagedUIContent.java
public String getReviews(BVParameters bvQueryParams) { long startTime = System.currentTimeMillis(); postProcess(bvQueryParams);/*w ww . j av a 2s .co m*/ StringBuilder uiContent = null; if (StringUtils.isBlank(validationError)) { if (bvUiContentService.isSdkEnabled()) { uiContent = bvUiContentService.executeCall(reloadContent); } else { _logger.info(BVMessageUtil.getMessage("MSG0003")); uiContent = new StringBuilder(); } if (uiContent != null) { int startIndex = uiContent.indexOf("<!--begin-aggregate-rating-->"); if (startIndex != -1) { String endReviews = "<!--end-aggregate-rating-->"; int endIndex = uiContent.indexOf(endReviews) + endReviews.length(); uiContent.delete(startIndex, endIndex); } startIndex = uiContent.indexOf("<!--begin-reviews-->"); if (startIndex == -1 && bvUiContentService.getMessage().length() == 0) { message.append(BVMessageUtil.getMessage("ERR0013")); } } else { uiContent = new StringBuilder(); } bvFooter.addMessage(bvUiContentService.getMessage().toString()); bvFooter.addMessage(message.toString()); } else { uiContent = new StringBuilder(); bvFooter.addMessage(validationError); } /* * Remove schema.org text from reviews if one exists * itemscope itemtype="http://schema.org/Product" */ String schemaOrg = "itemscope itemtype=\"http://schema.org/Product\""; int startIndex = uiContent.indexOf(schemaOrg); if (startIndex != -1) { uiContent.delete(startIndex, startIndex + schemaOrg.length()); } bvFooter.setExecutionTime(System.currentTimeMillis() - startTime); uiContent.append(bvFooter.displayFooter("getReviews")); return uiContent.toString(); }
From source file:br.com.nordestefomento.jrimum.utilix.AbstractLineOfFields.java
/** * <p>// w w w .ja va2s . c om * Ler a string de a cordo com a configurao de campos * </p> * * @see TextStream#read(String) * @param lineOfFields * @since 0.2 */ public void read(String lineOfFields) { if (isNotNull(lineOfFields, "lineOfFields")) { isConsistent(lineOfFields); StringBuilder builder = new StringBuilder(lineOfFields); for (Field<?> field : fields) { try { field.read(builder.substring(0, field.getLength())); } catch (Exception e) { log.error("ERRO DE LEITURA"); throw new IllegalStateException( "Erro na leitura do campo de posio [ " + fields.indexOf(field) + " ]", e); } builder.delete(0, field.getLength()); } builder = null; } }
From source file:fr.gael.dhus.olingo.ODataClient.java
/** * Creates an OdataClient for the given service * and credentials (HTTP Basic authentication). * //from w w w . j av a 2 s . c o m * @param url an URL to an OData service, * does not have to be the root service URL. * this parameter must follow this syntax : * {@code odata://hostname:port/path/...} * @param username Username * @param password Password * * @throws URISyntaxException when the {@code url} parameter is invalid. * @throws IOException when the OdataClient fails to contact the server * at {@code url}. * @throws ODataException when no OData service have been found at the * given url. */ public ODataClient(String url, String username, String password) throws URISyntaxException, IOException, ODataException { this.username = username; this.password = password; // Find the service root URL and retrieve the Entity Data Model (EDM). URI uri = new URI(url); String metadata = "/$metadata"; URI svc = null; Edm edm = null; String[] pathSegments = uri.getPath().split("/"); StringBuilder sb = new StringBuilder(); // for each possible service root URL. for (int i = 1; i < pathSegments.length; i++) { sb.append('/').append(pathSegments[i]).append(metadata); svc = new URI(uri.getScheme(), uri.getAuthority(), sb.toString(), null, null); sb.delete(sb.length() - metadata.length(), sb.length()); // Test if `svc` is the service root URL. try { InputStream content = execute(svc.toString(), ContentType.APPLICATION_XML, "GET"); edm = EntityProvider.readMetadata(content, false); svc = new URI(uri.getScheme(), uri.getAuthority(), sb.toString(), null, null); break; } catch (HttpException | EntityProviderException e) { LOGGER.debug("URL not root " + svc, e); } } // no OData service have been found at the given URL. if (svc == null || edm == null) throw new ODataException("No service found at " + url); this.serviceRoot = svc; this.serviceEDM = edm; this.uriParser = RuntimeDelegate.getUriParser(edm); }
From source file:com.norconex.collector.http.url.impl.GenericLinkExtractor.java
@Override public Set<Link> extractLinks(InputStream input, String reference, ContentType contentType) throws IOException { ContentType[] cTypes = contentTypes; if (ArrayUtils.isEmpty(cTypes)) { cTypes = DEFAULT_CONTENT_TYPES;// ww w . j a v a 2 s. com } // Do not extract if not a supported content type if (!ArrayUtils.contains(cTypes, contentType)) { return null; } // Do it, extract Links Referer urlParts = new Referer(reference); Set<Link> links = new HashSet<>(); StringBuilder sb = new StringBuilder(); byte[] buffer = new byte[INPUT_READ_ARRAY_SIZE]; int length; while ((length = input.read(buffer)) != -1) { sb.append(new String(buffer, 0, length, CharEncoding.UTF_8)); if (sb.length() >= MAX_BUFFER_SIZE) { extractLinks(sb.toString(), urlParts, links); sb.delete(0, sb.length() - OVERLAP_SIZE); } } extractLinks(sb.toString(), urlParts, links); sb.setLength(0); return links; }