List of usage examples for java.lang StringBuilder delete
@Override public StringBuilder delete(int start, int end)
From source file:net.sf.jabref.gui.AutoCompleteListener.java
private void cycle(JTextComponent comp, int increment) { assert (lastCompletions != null); assert (lastCompletions.length > 0); lastShownCompletion += increment;/*from ww w. j av a2 s .co m*/ if (lastShownCompletion >= lastCompletions.length) { lastShownCompletion = 0; } else if (lastShownCompletion < 0) { lastShownCompletion = lastCompletions.length - 1; } String sno = lastCompletions[lastShownCompletion]; toSetIn = sno.substring(lastBeginning.length() - 1); StringBuilder alltext = new StringBuilder(comp.getText()); int oldSelectionStart = comp.getSelectionStart(); int oldSelectionEnd = comp.getSelectionEnd(); // replace prefix with new prefix int startPos = comp.getSelectionStart() - lastBeginning.length(); alltext.delete(startPos, oldSelectionStart); alltext.insert(startPos, sno.subSequence(0, lastBeginning.length())); // replace suffix with new suffix alltext.delete(oldSelectionStart, oldSelectionEnd); //int cp = oldSelectionEnd - deletedChars; alltext.insert(oldSelectionStart, toSetIn.substring(1)); //Util.pr(alltext.toString()); comp.setText(alltext.toString()); //comp.setCaretPosition(cp+toSetIn.length()-1); comp.select(oldSelectionStart, (oldSelectionStart + toSetIn.length()) - 1); lastCaretPosition = comp.getCaretPosition(); //System.out.println("ToSetIn: '"+toSetIn+"'"); }
From source file:org.alfresco.module.vti.handler.alfresco.VtiPathHelper.java
protected String[] doDecomposeURLWork(final String alfrescoContext, final String uri, final QName spaceType) { // Office 2008/2011 for Mac fix if (uri.equals("") || uri.equals("/")) { return new String[] { "", "" }; }//from ww w.j a va2 s . co m // We require the path to start with the context if (!uri.startsWith(alfrescoContext)) { if (logger.isDebugEnabled()) { logger.debug("Url must start with alfresco context."); } throw new VtiHandlerException(VtiHandlerException.BAD_URL); } // Handle the case of the context with no site/document // MNT-10128 : delete the last "/" from the requested URI if (uri.equalsIgnoreCase(alfrescoContext) || (uri.endsWith("/") ? alfrescoContext.equalsIgnoreCase(uri.substring(0, uri.length() - 1)) : false)) { if (logger.isDebugEnabled()) { logger.debug("WebUrl: " + alfrescoContext + ", fileUrl: ''"); } return new String[] { alfrescoContext, "" }; } // Strip off the context before continuing with the path resolution String pathUri = getPathForURL(uri); // Decode the URL before doing path resolution, so that we correctly // match documents or paths containing special characters pathUri = URLDecoder.decode(pathUri); // Split it into parts based on slashes pathUri = removeSlashes(pathUri); String[] splitPath = pathUri.split("/"); // Build up the path String webUrl = ""; String fileUrl = ""; StringBuilder tempWebUrl = new StringBuilder(); for (int i = splitPath.length; i > 0; i--) { tempWebUrl.delete(0, tempWebUrl.length()); for (int j = 0; j < i; j++) { if (j < i - 1) { tempWebUrl.append(splitPath[j] + "/"); } else { tempWebUrl.append(splitPath[j]); } } FileInfo fileInfo = resolvePathFileInfo(tempWebUrl.toString()); if (fileInfo != null) { QName nodeType = nodeService.getType(fileInfo.getNodeRef()); if (dictionaryService.isSubClass(nodeType, spaceType)) { webUrl = alfrescoContext + "/" + tempWebUrl; if (uri.replaceAll(webUrl, "").startsWith("/")) { fileUrl = uri.replaceAll(webUrl, "").substring(1); } else { fileUrl = uri.replaceAll(webUrl, ""); } if (logger.isDebugEnabled()) { logger.debug("WebUrl: " + webUrl + ", fileUrl: '" + fileUrl + "'"); } return new String[] { webUrl, fileUrl }; } } } if (webUrl.equals("")) { throw new VtiHandlerException(VtiHandlerException.BAD_URL); } return new String[] { webUrl, fileUrl }; }
From source file:password.pwm.svc.stats.StatisticsManager.java
public String toString() { final StringBuilder sb = new StringBuilder(); for (final Statistic m : Statistic.values()) { sb.append(m.toString());/*from ww w. j av a 2s .c o m*/ sb.append("="); sb.append(statsCurrent.getStatistic(m)); sb.append(", "); } if (sb.length() > 2) { sb.delete(sb.length() - 2, sb.length()); } return sb.toString(); }
From source file:com.haulmont.cuba.web.gui.components.WebDateField.java
@Override public void setDateFormat(String dateFormat) { dateTimeFormat = dateFormat;//from w w w .jav a 2 s . co m StringBuilder date = new StringBuilder(dateFormat); StringBuilder time = new StringBuilder(dateFormat); int timeStartPos = findTimeStartPos(dateFormat); if (timeStartPos >= 0) { time.delete(0, timeStartPos); date.delete(timeStartPos, dateFormat.length()); timeFormat = StringUtils.trimToEmpty(time.toString()); timeField.setFormat(timeFormat); setResolution(resolution); } else if (resolution.ordinal() < Resolution.DAY.ordinal()) { setResolution(Resolution.DAY); } this.dateFormat = StringUtils.trimToEmpty(date.toString()); dateField.setDateFormat(this.dateFormat); }
From source file:org.alfresco.module.vti.handler.alfresco.VtiPathHelper.java
/** * Format FrontPageExtension URL path from file information * * @param fileInfo file information ({@link FileInfo}) * @return URL path//from w w w . java2 s . c om */ public String toUrlPath(FileInfo fileInfo) { String urlPath; NodeRef rootNodeRef = getRootNodeRef(); if (fileInfo.getNodeRef().equals(rootNodeRef)) { urlPath = ""; } else { StringBuilder builder = new StringBuilder( nodeService.getPath(fileInfo.getNodeRef()).toDisplayPath(nodeService, permissionService)); builder.delete(0, nodeService.getPath(rootNodeRef).toDisplayPath(nodeService, permissionService).length() + ((String) nodeService.getProperty(rootNodeRef, ContentModel.PROP_NAME)).length() + 1); if (builder.length() != 0) { builder.deleteCharAt(0); builder.append("/"); } builder.append(fileInfo.getName()); urlPath = builder.toString(); } if (logger.isDebugEnabled()) { logger.debug("Convert " + fileInfo + " to url path '" + urlPath + "'"); } return urlPath; }
From source file:edu.chalmers.dat076.moviefinder.service.TitleParser.java
/** * returns next number in mySb and deletes it and everything before it in * mySb./*w ww .ja v a2s .c o m*/ * * @param mySb * @return */ public int getNextNumber(StringBuilder mySb) { int value = -1; boolean deleteAll = true; for (int i = 0; i < mySb.length(); i++) { // Character.isDigit(i) better or worse? if ('0' <= mySb.charAt(i) && mySb.charAt(i) <= '9') { if (value < 0) { value = 0; } else { value = value * 10; } value = value + Character.getNumericValue(mySb.charAt(i)); } else if (value > 0) { mySb.delete(0, i); deleteAll = false; break; } } if (deleteAll && value > 0) { mySb.setLength(0); } return value; }
From source file:com.etiansoft.haier.service.ManagerService.java
/** * /*from w w w. java 2s .c om*/ * @Title: * @Description: TODO * @param @param code * @param @param * @param @return * @param @throws Exception * @return Result * @throws */ public String getPicturesUrl(List<MerchantPicture> merchantPictures) throws Exception { StringBuilder urls = new StringBuilder(); if (merchantPictures != null) { for (MerchantPicture merchantPicture : merchantPictures) { urls.append(merchantPicture.getUrl()).append(","); } urls.delete(urls.length() - 1, urls.length()); } return urls.toString(); }
From source file:jp.primecloud.auto.process.nifty.NiftyInstanceProcess.java
protected String createUserData(Long instanceNo) { Map<String, String> map = createUserDataMap(instanceNo); if (map.isEmpty()) { return ""; }// w ww .ja v a 2s . com StringBuilder sb = new StringBuilder(); for (Entry<String, String> entry : map.entrySet()) { String key = entry.getKey(); String value = entry.getValue(); if (key != null && value != null) { sb.append(key).append("=").append(value).append(";"); } } sb.delete(sb.length() - 1, sb.length()); return sb.toString(); }
From source file:de.tudarmstadt.ukp.wikipedia.parser.mediawiki.FrenchTemplateParser.java
public ResolvedTemplate parseTemplate(Template t, ParsedPage pp) { final String templateName = t.getName(); // Show Name and Parameters as Standart treatment. ResolvedTemplate result = new ResolvedTemplate(t); result.setPreParseReplacement(ResolvedTemplate.TEMPLATESPACER); StringBuilder sb = new StringBuilder(); sb.append(templatePrefix);//from w w w. j av a 2 s.co m sb.append(t.getName() + parameterDivisor); for (String s : t.getParameters()) { sb.append(s + parameterDivisor); } sb.delete(sb.length() - parameterDivisor.length(), sb.length()); sb.append(templatePostfix); result.setPostParseReplacement(sb.toString()); result.setParsedObject(t); /** * 1 DeleteTempaltes : On enlve tout */ for (String s : deleteTemplates) { s = s.toLowerCase(); String templateName_lower = templateName.toLowerCase(); if (templateName_lower.matches(s)) { result.setPostParseReplacement(""); result.setParsedObject(null); return result; } } /** * 2. Parse Template */ // System.out.println(templateName); String templateName_lower = templateName.toLowerCase(); for (String s : parseTemplates) { s = s.toLowerCase(); if (templateName_lower.matches(s)) { List<String> templateParameters = t.getParameters(); /** * Template to Parse French */ if (parsing.containsKey(templateName)) { String value = parsing.get(templateName); // System.out.println("TemplateName:"+templateName); // System.out.println("TemplateValue:"+value); String[] args = value.split(" "); String remplacement = ""; for (int i = 0; i < args.length; i++) { String currArg = args[i]; if (currArg.equals("all")) { // On prend ce qui est crit dans le texte for (int j = 0; j < templateParameters.size(); j++) { remplacement += templateParameters.get(j) + " "; } if (remplacement.equals("")) { remplacement = templateName; } // System.out.println("Remplacement:"+remplacement); } // simple index (e.g: TEMPLATE 1 2 4 5) else if (currArg.matches("[0-9]+")) { int index_params = Integer.parseInt(currArg); if (index_params < templateParameters.size()) { remplacement += templateParameters.get(index_params) + " "; } } else { // On prend ce qui est crit dans parser_templates.txt remplacement += currArg + " "; } } // System.out.println(templateName_lower); // System.out.println("Remplacement:"+remplacement); // System.out.println(); result.setPostParseReplacement(remplacement); result.setParsedObject(null); return result; } } } /** * 3. Non delete and non pars */ // System.out.println("#########"+templateName); String remplacement = ""; List<String> templateParameters = t.getParameters(); for (int j = 0; j < templateParameters.size(); j++) { remplacement += templateParameters.get(j) + " "; } if (remplacement.equals("")) { remplacement = templateName; } result.setPostParseReplacement(remplacement); result.setParsedObject(null); return result; // /** // * 2 ParseTemplate // */ // // for (String s : parseTemplates) { // // s = s.toLowerCase(); // String templateName_lower = templateName.toLowerCase(); // // List<String> templateParameters = t.getParameters(); // // if (s.equals(templateName_lower)) { // logger.info("ParseTemplate: " + templateName); // // /** // * Template to Parse French // */ // if(parsing.containsKey(templateName)){ // String value = parsing.get(templateName); //// System.out.println("TemplateName:"+templateName); //// System.out.println("TemplateValue:"+value); // // String [] args = value.split(" "); // // String remplacement = ""; // // // for(int i=0;i< args.length;i++){ // String currArg = args[i]; // // // if(currArg.equals("all")){ // // On prend ce qui est crit dans le texte // for(int j=0;j<templateParameters.size();j++){ // remplacement += templateParameters.get(j) + " "; // } // if(remplacement.equals("")){ // remplacement = templateName; // } //// System.out.println("Remplacement:"+remplacement); // } // // simple index (e.g: TEMPLATE 1 2 4 5) // else if(currArg.matches("[0-9]+")){ // int index_params = Integer.parseInt(currArg); // // if(index_params < templateParameters.size()){ // remplacement += templateParameters.get(index_params) + " "; // } // } // else if(currArg.matches("[a-z]*")){ // // // On prend ce qui est crit dans parser_templates.txt // remplacement += currArg + " "; // } // // } // // result.setPostParseReplacement(remplacement); // result.setParsedObject(null); // return result; // } //// if (templateName.equals("lang")) { //// //// result.setPostParseReplacement(templateParameters.get(1)); //// result.setParsedObject(null); //// return result; //// //// } else if (templateName.equals("s-")) { //// result.setPostParseReplacement(templateParameters.get(0) //// + " sicle"); //// result.setParsedObject(null); //// return result; //// } // //// else if (templateName.equals("Xe sicle")) { //// result.setPostParseReplacement("Xe sicle"); //// result.setParsedObject(null); //// return result; //// } else if (templateName.equals("XIe sicle")) { //// result.setPostParseReplacement("XIe sicle"); //// result.setParsedObject(null); //// return result; //// } else if (templateName.equals("XIIe_sicle")) { //// result.setPostParseReplacement("XIIe sicle"); //// result.setParsedObject(null); //// return result; //// } else if (templateName.equals("VXIIIe_sicle")) { //// result.setPostParseReplacement("XIIIe sicle"); //// result.setParsedObject(null); //// return result; //// } else if (templateName.equals("XIVe_sicle")) { //// result.setPostParseReplacement("XIVe sicle"); //// result.setParsedObject(null); //// return result; //// } else if (templateName.equals("XVe_sicle")) { //// result.setPostParseReplacement("XVe sicle"); //// result.setParsedObject(null); //// return result; //// } else if (templateName.equals("XVIe_sicle")) { //// result.setPostParseReplacement("XVI sicle"); //// result.setParsedObject(null); //// return result; //// } else if (templateName.equals("XVIIe_sicle")) { //// result.setPostParseReplacement("XVIIe sicle"); //// result.setParsedObject(null); //// return result; //// } else if (templateName.equals("XVIIIe_sicle")) { //// result.setPostParseReplacement("XVIIIe sicle"); //// result.setParsedObject(null); //// return result; //// } else if (templateName.equals("XIXe_sicle")) { //// result.setPostParseReplacement("XIX sicle"); //// result.setParsedObject(null); //// return result; //// } else if (templateName.equals("XXe_sicle")) { //// result.setPostParseReplacement("XX sicle"); //// result.setParsedObject(null); //// return result; //// } // } // //// else{ //// System.out.println("NO MATCH:"+s); //// System.out.println(); //// //// String remplacement = ""; //// for(int j=0;j<templateParameters.size();j++){ //// remplacement += templateParameters.get(j) + " "; //// } //// if(remplacement.equals("")){ //// remplacement = templateName; //// } //// //// result.setPostParseReplacement(remplacement); //// result.setParsedObject(null); //// return result; //// } // } }
From source file:edu.ku.brc.specify.tasks.subpane.wb.GridTableModel.java
public Object getValueAt(int row, int column) { if (row < 0 || row >= getRowCount() || column < 0 || column >= getColumnCount()) { return null; }//from w w w .jav a2 s .c om // if this is the image column... if (headers.get(column) == imageMappingItem) { WorkbenchRow rowObj = getWorkbench().getRow(row); Set<WorkbenchRowImage> images = rowObj.getWorkbenchRowImages(); if (images != null && images.size() > 0) { StringBuilder sb = new StringBuilder(); for (WorkbenchRowImage rowImg : images) { String fullPath = rowImg.getCardImageFullPath(); String filename = FilenameUtils.getName(fullPath); sb.append(filename + "; "); } sb.delete(sb.length() - 2, sb.length()); return sb.toString(); } // else return ""; } if (headers.get(column) == sgrHeading) { SGRPluginImpl sgr = (SGRPluginImpl) workbenchPaneSS.getPlugin(SGRPluginImpl.class); if (sgr != null) { WorkbenchColorizer colorizer = sgr.getColorizer(); Float score = colorizer.getScoreForRow(workbenchPaneSS.getWorkbench().getRow(row)); return score != null ? String.format("%1$.2f", score) : ""; } return 0; } // otherwise... if (getRowCount() > row) { return getWorkbench().getWorkbenchRowsAsList().get(row).getData(column); } return null; }