List of usage examples for java.lang StringBuilder lastIndexOf
@Override public int lastIndexOf(String str)
From source file:Main.java
public static String removeFromCollection(String collectionString, String content) { String[] elements = collectionString.split(SPLITER); StringBuilder builder = new StringBuilder(); for (String element : elements) { if (element.equals(content)) { continue; }/*from ww w .j a v a 2 s. c o m*/ builder.append(element).append(","); } if (builder.length() > 0) { builder.deleteCharAt(builder.lastIndexOf(",")); } return builder.toString(); }
From source file:com.bazaarvoice.seo.sdk.util.BVUtility.java
/** * Utility method to replace the string from StringBuilder. * * @param sb StringBuilder object.// w ww .j a v a 2 s . c o m * @param toReplace The String that should be replaced. * @param replacement The String that has to be replaced by. * */ public static void replaceString(StringBuilder sb, String toReplace, String replacement) { int index = -1; while ((index = sb.lastIndexOf(toReplace)) != -1) { sb.replace(index, index + toReplace.length(), replacement); } }
From source file:org.eclipse.virgo.ide.runtime.core.ServerUtils.java
/** * Returns the name of the source jar following the BRITS conventions *//* ww w . j a v a2 s . c o m*/ public static File getSourceFile(URI uri) { File file = new File(uri); StringBuilder builder = new StringBuilder(file.getName()); int ix = builder.lastIndexOf("-"); if (ix > 0) { builder.insert(ix, SOURCES_SUFFIX); File sourceFile = new File(file.getParentFile(), builder.toString()); return sourceFile; } return null; }
From source file:Dengue.CDengueManager.java
public static void loadDengueCluster() { List<CDengueCluster> lstCluster = new ArrayList<>(); String strJson = ""; try {//from www . ja v a2s .c om strJson = CNetworkFactory.createDengueClusterRequest().sendRequest(); } catch (IOException ex) { } if (strJson.isEmpty()) { return; } JSONArray objArray = new JSONObject(strJson).getJSONArray("SrchResults"); int intCount = objArray.getJSONObject(0).getInt("FeatCount"); for (int intCounter = 1; intCounter <= intCount; intCounter++) { lstCluster.add(CDengueFactory.loadCluster(objArray.getJSONObject(intCounter))); } StringBuilder objSB = new StringBuilder(); objSB.append("["); for (CDengueCluster objCluster : lstCluster) { objSB.append(objCluster.toJSON()); objSB.append(","); } objSB.deleteCharAt(objSB.lastIndexOf(",")); objSB.append("]"); sendInfoToCPU(objSB.toString(), 33009); }
From source file:net.sourceforge.vulcan.subversion.SubversionProjectConfigurator.java
protected static SubversionRepositoryProfileDto findOrCreateProfile(SVNRepository repo, SubversionConfigDto globalConfig, ProjectConfigDto project, SubversionProjectConfigDto raProjectConfig, String absoluteUrl, String username, String password) throws SVNException { SubversionRepositoryProfileDto profile = findProfileByUrlPrefix(globalConfig, absoluteUrl); if (profile == null) { if (isNotBlank(username)) { repo.setAuthenticationManager(new BasicAuthenticationManager(username, password)); }//from w ww. j a v a 2 s . c om final String root = repo.getRepositoryRoot(true).toString(); profile = new SubversionRepositoryProfileDto(); profile.setRootUrl(root); profile.setUsername(username); profile.setPassword(password); try { profile.setDescription(new URL(root).getHost()); } catch (MalformedURLException e) { profile.setDescription(root); } } project.setRepositoryAdaptorPluginId(SubversionConfigDto.PLUGIN_ID); project.setRepositoryAdaptorConfig(raProjectConfig); raProjectConfig.setRepositoryProfile(profile.getDescription()); final StringBuilder relativePath = new StringBuilder(absoluteUrl.substring(profile.getRootUrl().length())); relativePath.delete(relativePath.lastIndexOf("/"), relativePath.length()); raProjectConfig.setPath(relativePath.toString()); return profile; }
From source file:org.exoplatform.outlook.forum.ForumUtils.java
/** * Builds the forum link.// ww w.j a va 2 s .c o m * * @param url the url * @param type the type * @param id the id * @return the string */ private static String buildForumLink(String url, String type, String id) { StringBuilder link = new StringBuilder(url); if (!isEmpty(type) && !isEmpty(id)) { if (link.lastIndexOf(SLASH) == (link.length() - 1)) link.append(type); else link.append(SLASH).append(type); if (!id.equals(Utils.FORUM_SERVICE)) link.append(SLASH).append(id); } return link.toString(); }
From source file:org.geoserver.wms.animate.FrameCatalogVisitor.java
private static String mergeParams(List<String> kvps) { StringBuilder sb = new StringBuilder(); for (String k : kvps) { sb.append(k).append(";"); }/*from w ww. j av a 2 s .c o m*/ sb.deleteCharAt(sb.lastIndexOf(";")); return sb.toString(); }
From source file:Main.java
/** * Sanitizes the XML represented by {@code xml} by replacing dirty header XML * snippets in the {@code dirtyXmlMap} map with clean header XML snippets from * the {@code cleanXmlMap} map.//from w w w . ja va2s .c o m * * @param xml the XML to sanitize * @param dirtyXmlMap a map of tag name to dirty XML header * @param cleanXmlMap a map of tag name to clean XML header * @return a sanitized copy of the XML with all sensitive tags masked */ private static String sanitizeXml(StringBuilder xml, Map<String, String> dirtyXmlMap, Map<String, String> cleanXmlMap) { for (Entry<String, String> cleanXml : cleanXmlMap.entrySet()) { String dirtyXml = dirtyXmlMap.get(cleanXml.getKey()); String endTag = cleanXml.getKey() + ">"; int startIndex = xml.indexOf(dirtyXml.split(" ")[0]); int endIndex = xml.lastIndexOf(endTag) + endTag.length(); xml = xml.replace(startIndex, endIndex, cleanXml.getValue()); } return xml.toString(); }
From source file:com.gallatinsystems.survey.dao.SurveyUtils.java
/** * Given the path of an object, return a list of the paths of all its parent objects * * @param objectPath the path of an object * @param includeRootPath include the root path in the list of parent paths * @return/*from w ww .j a v a 2s . c om*/ */ public static List<String> listParentPaths(String objectPath, boolean includeRootPath) { List<String> parentPaths = new ArrayList<String>(); StringBuilder path = new StringBuilder(objectPath); while (path.length() > 1) { path.delete(path.lastIndexOf("/"), path.length()); if (StringUtils.isNotBlank(path.toString())) { parentPaths.add(path.toString().trim()); } } if (includeRootPath) { parentPaths.add("/"); } return parentPaths; }
From source file:com.taobao.datax.common.util.StrUtils.java
License:asdf
public static String removeSpace(final String str, final String sep) { assert str != null; assert sep != null; StringBuilder sb = new StringBuilder(str.length()); String[] items = str.trim().split(sep); for (String item : items) { sb.append(item.trim()).append(sep); }/*www .ja va2 s.co m*/ return sb.substring(0, sb.lastIndexOf(sep)); }