List of usage examples for java.lang StringBuilder replace
@Override public StringBuilder replace(int start, int end, String str)
From source file:com.ctriposs.rest4j.tools.idlcheck.Rest4JResourceModelCompatibilityChecker.java
private static String listCompatLevelOptions() { final StringBuilder options = new StringBuilder("<"); for (CompatibilityLevel compatLevel : CompatibilityLevel.values()) { options.append(compatLevel.name().toLowerCase()).append("|"); }// ww w . j a v a 2s . co m options.replace(options.length() - 1, options.length(), ">"); return options.toString(); }
From source file:com.mongodb.hadoop.splitter.MongoCollectionSplitter.java
/** * Takes an existing {@link MongoClientURI} and returns a new modified URI which replaces the original's server host + port with a * supplied new server host + port, but maintaining all the same original options. This is useful for generating distinct URIs for each * mongos instance so that large batch reads can all target them separately, distributing the load more evenly. It can also be used to * force a block of data to be read directly from the shard's servers directly, bypassing mongos entirely. * * @param originalUri the URI to rewrite * @param newServerUri the new host(s) to target, e.g. server1:port1[,server2:port2,...] *//*from www . j a v a 2 s . co m*/ protected static MongoClientURI rewriteURI(final MongoClientURI originalUri, final String newServerUri) { String originalUriString = originalUri.toString(); originalUriString = originalUriString.substring(MongoURI.MONGODB_PREFIX.length()); // uris look like: mongodb://fred:foobar@server1[,server2]/path?options // //Locate the last character of the original hostname int serverEnd; int idx = originalUriString.lastIndexOf("/"); serverEnd = idx < 0 ? originalUriString.length() : idx; //Locate the first character of the original hostname idx = originalUriString.indexOf("@"); int serverStart = idx > 0 ? idx + 1 : 0; StringBuilder sb = new StringBuilder(originalUriString); sb.replace(serverStart, serverEnd, newServerUri); String ans = MongoURI.MONGODB_PREFIX + sb.toString(); return new MongoClientURI(ans); }
From source file:Main.java
/** * Notice that,/*from w ww . jav a 2 s . c o m*/ * If we split the signature string with ", ", * a value (like "Google, Inc") may be broke up unexpectedly. * So we check "=" at the same time. * (AppXplore v2.5.0 makes a mistake, too.) * * An example from Google Pinyin Input: * CN=Unknown, OU="Google, Inc", O="Google, Inc", L=Mountain View, ST=CA, C=US */ public static String analyseSignature(Principal principal, String str_nl) { //The result of principal.toString() is like this "x, x, x"; StringBuilder stringBuilder = new StringBuilder(principal.toString().replaceAll(", ", str_nl)); int index1 = 0; int index2; while (index1 >= 0) { if ((index2 = stringBuilder.indexOf(str_nl, index1)) < 0) { break; } if (!stringBuilder.substring(index1, index2).contains("=")) { stringBuilder.replace(index1 - str_nl.length(), index1, ", "); } index1 = stringBuilder.indexOf(str_nl, index1) + str_nl.length(); } return stringBuilder.toString(); }
From source file:com.bazaarvoice.seo.sdk.util.BVUtility.java
/** * Utility method to replace the string from StringBuilder. * * @param sb StringBuilder object./*from w w w . j a va 2 s. c om*/ * @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:fr.irit.sparql.Proxy.SparqlProxy.java
public static void replaceAll(StringBuilder builder, String from, String to) { int index = builder.indexOf(from); while (index != -1) { builder.replace(index, index + from.length(), to); index += to.length(); // Move to the end of the replacement index = builder.indexOf(from, index); }//from w w w . ja v a 2 s .c o m }
From source file:no.sesat.search.site.config.AbstractDocumentFactory.java
/** The reverse transformation to beanToXmlName(string). * * @param xmlName/*from ww w . j a v a 2 s .c o m*/ * @return */ public static String xmlToBeanName(final String xmlName) { final StringBuilder beanName = new StringBuilder(xmlName); for (int i = 0; i < beanName.length(); ++i) { final char c = beanName.charAt(i); if ('-' == c) { beanName.replace(i, i + 2, String.valueOf(Character.toUpperCase(beanName.charAt(i + 1)))); ++i; } } return beanName.toString(); }
From source file:Main.java
/** * Read a file into a StringBuilder./*from w w w . j a v a2 s .c om*/ * * @param paramFile * The file to read. * @param paramWhitespaces * Retrieve file and don't remove any whitespaces. * @return StringBuilder instance, which has the string representation of * the document. * @throws IOException * throws an IOException if any I/O operation fails. */ public static StringBuilder readFile(final File paramFile, final boolean paramWhitespaces) throws IOException { final BufferedReader in = new BufferedReader(new FileReader(paramFile)); final StringBuilder sBuilder = new StringBuilder(); for (String line = in.readLine(); line != null; line = in.readLine()) { if (paramWhitespaces) { sBuilder.append(line + "\n"); } else { sBuilder.append(line.trim()); } } // Remove last newline. if (paramWhitespaces) { sBuilder.replace(sBuilder.length() - 1, sBuilder.length(), ""); } in.close(); return sBuilder; }
From source file:no.sesat.search.site.config.AbstractDocumentFactory.java
/*** * <p>The words within the bean name are deduced assuming the * first-letter-capital (for example camel's hump) naming convention. For * example, the words in <code>FooBar</code> are <code>foo</code> * and <code>bar</code>.</p> * * <p>Then the {@link #getSeparator} property value is inserted so that it separates * each word.</p>/*from ww w. j ava2 s. c om*/ * * @param beanName The name string to convert. If a JavaBean * class name, should included only the last part of the name * rather than the fully qualified name (e.g. FooBar rather than * org.example.FooBar). * @return the bean name converted to either upper or lower case with words separated * by the separator. **/ public static String beanToXmlName(final String beanName) { final StringBuilder xmlName = new StringBuilder(beanName); for (int i = 0; i < xmlName.length(); ++i) { final char c = xmlName.charAt(i); if (Character.isUpperCase(c)) { xmlName.replace(i, i + 1, "-" + Character.toLowerCase(c)); ++i; } } return xmlName.toString(); }
From source file:Main.java
public static String restoreWithEndnote(String text, String holderString, String replacement, String noteTag, String noteSplit) {//from w w w . j av a 2 s . co m int start = text.lastIndexOf(noteTag); String note = text.substring(start); text = text.substring(0, start); if (note.length() == noteTag.length()) return text; StringBuilder sb = new StringBuilder(text); StringTokenizer token = new StringTokenizer(note.substring(1), noteSplit); int[] index = new int[token.countTokens()]; for (int i = index.length - 1; i >= 0; i--) { index[i] = Integer.parseInt(token.nextToken()); } int h_length = holderString.length(); for (int i = 0; i < index.length; i++) { sb.replace(index[i], index[i] + h_length, replacement); } return sb.toString(); }
From source file:com.indoqa.lang.util.URLStringUtils.java
public static String replaceParameter(String path, String parameterName, Object parameterValue) { StringBuilder stringBuilder = new StringBuilder(path); String searchString = "{" + parameterName + "}"; while (true) { int index = stringBuilder.indexOf(searchString); if (index == -1) { break; }/*from ww w .java 2 s .c o m*/ stringBuilder.replace(index, index + searchString.length(), String.valueOf(parameterValue)); } return stringBuilder.toString(); }