List of usage examples for java.lang StringBuilder deleteCharAt
@Override public StringBuilder deleteCharAt(int index)
From source file:com.networknt.registry.support.command.CommandServiceManager.java
private List<URL> mergeResult(URL url, Map<String, Integer> weights) { List<URL> finalResult = new ArrayList<URL>(); if (weights.size() > 1) { // construct a rule url with all groups and added as first URL ruleUrl = new URLImpl("rule", url.getHost(), url.getPort(), url.getPath()); StringBuilder weightsBuilder = new StringBuilder(64); for (Map.Entry<String, Integer> entry : weights.entrySet()) { weightsBuilder.append(entry.getKey()).append(':').append(entry.getValue()).append(','); }/*from w w w . ja va 2 s .c o m*/ ruleUrl.addParameter(URLParamType.weights.getName(), weightsBuilder.deleteCharAt(weightsBuilder.length() - 1).toString()); finalResult.add(ruleUrl); } for (String key : weights.keySet()) { if (groupServiceCache.containsKey(key)) { finalResult.addAll(groupServiceCache.get(key)); } else { URL urlTemp = url.createCopy(); urlTemp.addParameter(URLParamType.group.getName(), key); finalResult.addAll(discoverOneGroup(urlTemp)); registry.subscribeService(urlTemp, this); } } return finalResult; }
From source file:com.vmware.photon.controller.api.client.resource.ApiBase.java
/** * Generates query string from query params. * * @param queryParams// w ww. j ava2 s .c o m * @return * @throws UnsupportedEncodingException */ public String generateQueryString(Map<String, String> queryParams) throws UnsupportedEncodingException { StringBuilder query = new StringBuilder(); if (queryParams == null) { return query.toString(); } if (queryParams != null && queryParams.size() > 0) { query.append("?"); } for (Entry<String, String> param : queryParams.entrySet()) { query.append(String.format("%s=%s&", URLEncoder.encode(param.getKey(), "UTF-8"), URLEncoder.encode(param.getValue(), "UTF-8"))); } return query.deleteCharAt(query.length() - 1).toString(); }
From source file:ca.uhn.fhir.rest.method.MethodUtil.java
private static void parseTagValue(TagList theTagList, String theCompleteHeaderValue, StringBuilder theBuffer) { int firstSemicolon = theBuffer.indexOf(";"); int deleteTo; if (firstSemicolon == -1) { firstSemicolon = theBuffer.indexOf(","); if (firstSemicolon == -1) { firstSemicolon = theBuffer.length(); deleteTo = theBuffer.length(); } else {/*from ww w .j av a2 s. c om*/ deleteTo = firstSemicolon; } } else { deleteTo = firstSemicolon + 1; } String term = theBuffer.substring(0, firstSemicolon); String scheme = null; String label = null; if (isBlank(term)) { return; } theBuffer.delete(0, deleteTo); while (theBuffer.length() > 0 && theBuffer.charAt(0) == ' ') { theBuffer.deleteCharAt(0); } while (theBuffer.length() > 0) { boolean foundSomething = false; if (theBuffer.length() > SCHEME.length() && theBuffer.substring(0, SCHEME.length()).equals(SCHEME)) { int closeIdx = theBuffer.indexOf("\"", SCHEME.length()); scheme = theBuffer.substring(SCHEME.length(), closeIdx); theBuffer.delete(0, closeIdx + 1); foundSomething = true; } if (theBuffer.length() > LABEL.length() && theBuffer.substring(0, LABEL.length()).equals(LABEL)) { int closeIdx = theBuffer.indexOf("\"", LABEL.length()); label = theBuffer.substring(LABEL.length(), closeIdx); theBuffer.delete(0, closeIdx + 1); foundSomething = true; } // TODO: support enc2231-string as described in // http://tools.ietf.org/html/draft-johnston-http-category-header-02 // TODO: support multiple tags in one header as described in // http://hl7.org/implement/standards/fhir/http.html#tags while (theBuffer.length() > 0 && (theBuffer.charAt(0) == ' ' || theBuffer.charAt(0) == ';')) { theBuffer.deleteCharAt(0); } if (!foundSomething) { break; } } if (theBuffer.length() > 0 && theBuffer.charAt(0) == ',') { theBuffer.deleteCharAt(0); while (theBuffer.length() > 0 && theBuffer.charAt(0) == ' ') { theBuffer.deleteCharAt(0); } theTagList.add(new Tag(scheme, term, label)); parseTagValue(theTagList, theCompleteHeaderValue, theBuffer); } else { theTagList.add(new Tag(scheme, term, label)); } if (theBuffer.length() > 0) { ourLog.warn("Ignoring extra text at the end of " + Constants.HEADER_CATEGORY + " tag '" + theBuffer.toString() + "' - Complete tag value was: " + theCompleteHeaderValue); } }
From source file:com.vmm.storefront.controllers.pages.ProductPageController.java
/** * @param lastBrowsedProducts//from w w w. j av a2s .co m * @param productCode * @param count * @return list */ private String listLatestBrowsedProducts(final String lastBrowsedProducts, final String productCode, final int count) { final String[] result = lastBrowsedProducts.split(","); final Set<String> uniqueList = new LinkedHashSet<String>(Arrays.asList(result)); if (result.length >= count) { uniqueList.remove(result[0]); uniqueList.add(productCode); } else if (result.length < count) { uniqueList.remove(productCode); uniqueList.add(productCode); } final StringBuilder list = new StringBuilder(); for (final String str : uniqueList) { list.append(str); list.append(','); } list.deleteCharAt(list.length() - 1); return list.toString(); }
From source file:com.vmware.certificate.Client.java
private String encodeX509CertificatesToString(X509Certificate[] certs) throws Exception { if (certs == null || certs.length == 0) { return null; }//from w ww . j ava 2s . c o m int stringBuilderSize = certs.length * 1024; // approximate string builder // size StringBuilder sb = new StringBuilder(stringBuilderSize); for (X509Certificate cert : certs) { String pem = getEncodedStringFromCertificate(cert); sb.append(pem); sb.append('\n'); } if (sb.length() > 0) { sb.deleteCharAt(sb.length() - 1); } return sb.toString(); }
From source file:hudson.plugins.sonar.utils.MaskPasswordsOutputStream.java
public MaskPasswordsOutputStream(OutputStream logger, Charset charset, Collection<String> passwords) { this.logger = logger; this.charset = charset; if (passwords != null && !passwords.isEmpty()) { // passwords are aggregated into a regex which is compiled as a pattern // for efficiency StringBuilder regex = new StringBuilder().append('('); int nbMaskedPasswords = 0; for (String password : passwords) { // we must not handle empty passwords if (StringUtils.isNotEmpty(password)) { regex.append(Pattern.quote(password)); regex.append('|'); nbMaskedPasswords++;//from w ww. j av a2s . c o m } } // is there at least one password to mask? if (nbMaskedPasswords >= 1) { // removes the last unuseful pipe regex.deleteCharAt(regex.length() - 1); regex.append(')'); passwordsAsPattern = Pattern.compile(regex.toString()); } else { // no passwords to hide passwordsAsPattern = null; } } else { // no passwords to hide passwordsAsPattern = null; } }
From source file:com.redhat.lightblue.metadata.rdbms.converter.Translator.java
protected void generateResultColumns(SelectStmt selectStmt, StringBuilder queryStringBuilder, List<String> resultColumns) { for (String resultColumn : resultColumns) { queryStringBuilder.append(resultColumn).append(" ,"); }/* w w w . j a v a 2 s . co m*/ queryStringBuilder.deleteCharAt(queryStringBuilder.length() - 1); //remove the last ',' }
From source file:org.apache.olingo.client.core.uri.AbstractURIBuilder.java
protected String buildMultiKeySegment(final Map<String, Object> segmentValues, final boolean escape) { if (segmentValues == null || segmentValues.isEmpty()) { return StringUtils.EMPTY; } else {/*w w w.ja va 2 s. c om*/ final StringBuilder keyBuilder = new StringBuilder().append('('); for (Map.Entry<String, Object> entry : segmentValues.entrySet()) { keyBuilder.append(entry.getKey()).append('=') .append(escape ? URIUtils.escape(version, entry.getValue()) : entry.getValue()); keyBuilder.append(','); } keyBuilder.deleteCharAt(keyBuilder.length() - 1).append(')'); return keyBuilder.toString(); } }
From source file:com.sap.dirigible.ide.designer.ui.DesignerEditorWidget.java
private String buildFunctionCall(String function, Object... arguments) { StringBuilder call = new StringBuilder(); call.append(function).append('('); if (arguments != null) { for (Object argument : arguments) { String strArg = null; if (argument instanceof String) { strArg = prepareStringArgument((String) argument); } else { strArg = String.valueOf(argument); }/*from w ww .java2 s . c o m*/ call.append(strArg).append(","); //$NON-NLS-1$ } if (arguments.length > 0) { call.deleteCharAt(call.length() - 1); } } call.append(')'); return call.toString(); }
From source file:com.redhat.lightblue.metadata.rdbms.converter.Translator.java
protected void generateFrom(SelectStmt selectStmt, StringBuilder queryStringBuilder, List<String> fromTables) { queryStringBuilder.append("FROM "); for (String table : fromTables) { queryStringBuilder.append(table).append(" ,"); }/*from w w w. j a v a 2s.c o m*/ queryStringBuilder.deleteCharAt(queryStringBuilder.length() - 1); //remove the last ',' }