List of usage examples for java.lang StringBuilder lastIndexOf
@Override public int lastIndexOf(String str)
From source file:net.duckling.ddl.web.controller.DashboardController.java
private boolean generateApplicantMessage(List<TeamApplicantNoticeRender> tanr, StringBuilder waiting, StringBuilder reject) {/*from ww w . j a va2 s .com*/ boolean isEmpty = true; if (null != tanr && !tanr.isEmpty()) { for (TeamApplicantNoticeRender tanrItem : tanr) { String status = tanrItem.getTeamApplicant().getStatus(); if (TeamApplicant.STATUS_WAITING.equals(status)) { waiting.append(tanrItem.getTeamName() + ","); isEmpty = false; } else if (TeamApplicant.STATUS_REJECT.equals(status)) { reject.append(tanrItem.getTeamName() + ","); isEmpty = false; } else { LOG.info("????"); } } if (waiting.length() > 0) { waiting.replace(waiting.lastIndexOf(","), waiting.length(), ""); } if (reject.length() > 0) { reject.replace(reject.lastIndexOf(","), reject.length(), ""); } } return isEmpty; }
From source file:org.oscarehr.PMmodule.exporter.DATISMain.java
@Override protected String exportData() throws ExportException { List<IntakeNode> intakeNodes = intake.getNode().getChildren(); StringBuilder buf = new StringBuilder(); IntakeNode mainNode = null;//from w w w . j a va 2s . c o m IntakeNode gamblingNode = null; for (IntakeNode inode : intakeNodes) { if (inode.getLabelStr().startsWith(FILE_PREFIX_MAIN)) { mainNode = inode; } else if (inode.getLabelStr().startsWith(FILE_PREFIX_GAMBLING)) { gamblingNode = inode; } } Set<IntakeAnswer> answers = intake.getAnswers(); int counter = 0; for (IntakeAnswer ans : answers) { if (counter == fields.size()) { break; } if (ans.getNode().getGrandParent().equals(mainNode) || ans.getNode().getGrandParent().equals(gamblingNode)) { final String lbl = ans.getNode().getParent().getLabelStr().toUpperCase(); DATISField found = (DATISField) CollectionUtils.find(fields, new Predicate() { public boolean evaluate(Object arg0) { DATISField field = (DATISField) arg0; if (lbl.startsWith(field.getName())) { return true; } return false; } }); if (found != null) { writeCSV(buf, ans, found); //writeData(buf, ans, found); counter++; } } } if (buf.lastIndexOf(",") == -1) { return buf.toString(); } return buf.substring(0, buf.lastIndexOf(",")).toString(); }
From source file:com.sunsharing.eos.uddi.service.NodeJSService.java
private void createMockConfigFile(String path, List<TService> services) throws Exception { StringBuilder sb = new StringBuilder(); sb.append("module.exports = {\n" + " mock:{\n"); for (TService service : services) { TServiceVersion serviceVersion = service.getVersions().get(0); sb.append(" " + service.getServiceCode()).append(":{\n"); for (TMethod method : serviceVersion.getMethods()) { String methodName = method.getMethodName(); if (methodName.startsWith("void ")) { methodName = methodName.replace("void ", ""); }/* w w w . j a v a2 s . co m*/ sb.append(" " + methodName).append(":\"\", //"); JSONArray methodMockResult = JSON.parseArray(method.getMockResult()); if (methodMockResult.size() > 0) { for (int i = 0, l = methodMockResult.size(); i < l; i++) { JSONObject jo = methodMockResult.getJSONObject(i); sb.append(jo.getString("status")); sb.append(","); } sb.deleteCharAt(sb.lastIndexOf(",")); } sb.append("\n"); } int deleteIdx = sb.lastIndexOf(", //"); sb.deleteCharAt(deleteIdx); sb.append(" },\n"); } sb.deleteCharAt(sb.lastIndexOf(",")); sb.append(" },\n" + " offlineData:{\n"); for (TService service : services) { TServiceVersion serviceVersion = service.getVersions().get(0); sb.append(" " + service.getServiceCode()).append(":{\n"); for (TMethod method : serviceVersion.getMethods()) { String methodName = method.getMethodName(); if (methodName.startsWith("void ")) { methodName = methodName.replace("void ", ""); } sb.append(" " + methodName).append(":{\n"); JSONArray methodMockResult = JSON.parseArray(method.getMockResult()); if (methodMockResult.size() > 0) { for (int i = 0, l = methodMockResult.size(); i < l; i++) { JSONObject jo = methodMockResult.getJSONObject(i); sb.append(" //" + jo.getString("desc")); sb.append("\n"); sb.append(" " + jo.getString("status")); sb.append(":"); String content = jo.getString("content") == null ? "null" : jo.getString("content").trim(); if (!(content.startsWith("[") || content.startsWith("{"))) { // content = JSON.toJSONString(content); } sb.append(content); sb.append(","); sb.append("\n"); } sb.deleteCharAt(sb.lastIndexOf(",")); } sb.append(" },\n"); } int deleteIdx = sb.lastIndexOf(","); sb.deleteCharAt(deleteIdx); sb.append(" },\n"); } sb.deleteCharAt(sb.lastIndexOf(",")); sb.append(" }\n" + "}"); FileUtil.createFile(path + File.separator + "config_mock.js", sb.toString(), "utf-8"); }
From source file:org.idempiere.webservices.AbstractService.java
/** * Parse variables inside SQL/*w w w .j av a 2s. c o m*/ * @param sql * @param sqlParas * @param po * @param requestCtx * @return * @throws AdempiereException */ protected String parseSQL(String sql, ArrayList<Object> sqlParas, PO po, POInfo poInfo, Map<String, Object> requestCtx) throws AdempiereException { if (sql.startsWith("@SQL=")) sql = sql.substring(5); if (sql.toLowerCase().indexOf(" where ") == -1) throw new AdempiereException("Invalid SQL: Query do not have any filetering criteria"); StringBuilder sqlBuilder = new StringBuilder(); if (sql.indexOf('@') == -1) { sqlBuilder.append(sql); } else { int firstInd = sql.indexOf('@'); while (firstInd >= 0) { sqlBuilder.append(sql.substring(0, firstInd)); sql = sql.substring(firstInd + 1); firstInd = sql.indexOf('@'); if (firstInd == -1) { throw new AdempiereException("Missing closing '@' in SQL"); } String token = sql.substring(0, firstInd); boolean isNullable = false; if (token.charAt(0) == '!') { isNullable = true; token = token.substring(1); } sql = sql.substring(firstInd + 1); Object val = parseVariable(token, po, poInfo, requestCtx); if (val == null && isNullable) { int ind = sqlBuilder.lastIndexOf("="); sqlBuilder.replace(ind, sqlBuilder.length(), " Is Null "); } else if (val == null) throw new AdempiereException("Can not resolve varialbe '" + token + "' in sql"); else { sqlBuilder.append(" ? "); sqlParas.add(val); } firstInd = sql.indexOf('@'); } sqlBuilder.append(sql); } return sqlBuilder.toString(); }
From source file:org.apache.pulsar.proxy.server.AdminProxyHandler.java
@Override protected String rewriteTarget(HttpServletRequest request) { StringBuilder url = new StringBuilder(); boolean isFunctionsRestRequest = false; String requestUri = request.getRequestURI(); if (requestUri.startsWith("/admin/v2/functions") || requestUri.startsWith("/admin/functions")) { isFunctionsRestRequest = true;// w w w . j ava 2 s .c om } if (isFunctionsRestRequest && !isBlank(functionWorkerWebServiceUrl)) { url.append(functionWorkerWebServiceUrl); } else if (isBlank(brokerWebServiceUrl)) { try { ServiceLookupData availableBroker = discoveryProvider.nextBroker(); if (config.isTlsEnabledWithBroker()) { url.append(availableBroker.getWebServiceUrlTls()); } else { url.append(availableBroker.getWebServiceUrl()); } if (LOG.isDebugEnabled()) { LOG.debug("[{}:{}] Selected active broker is {}", request.getRemoteAddr(), request.getRemotePort(), url.toString()); } } catch (Exception e) { LOG.warn("[{}:{}] Failed to get next active broker {}", request.getRemoteAddr(), request.getRemotePort(), e.getMessage(), e); return null; } } else { url.append(brokerWebServiceUrl); } if (url.lastIndexOf("/") == url.length() - 1) { url.deleteCharAt(url.lastIndexOf("/")); } url.append(requestUri); String query = request.getQueryString(); if (query != null) { url.append("?").append(query); } URI rewrittenUrl = URI.create(url.toString()).normalize(); if (!validateDestination(rewrittenUrl.getHost(), rewrittenUrl.getPort())) { return null; } return rewrittenUrl.toString(); }
From source file:pt.webdetails.cpk.CpkApi.java
@GET @Path("/listDataAccessTypes") @Produces(MimeTypes.JSON)// ww w. j ava 2 s . c o m public void listDataAccessTypes(@Context HttpServletResponse response) throws Exception { //boolean refreshCache = Boolean.parseBoolean(getRequestParameters().getStringParameter("refreshCache", "false")); Set<DataSource> dataSources = new LinkedHashSet<DataSource>(); StringBuilder dsDeclarations = new StringBuilder("{"); Collection<IElement> endpoints = coreService.getElements(); String pluginId = cpkEnv.getPluginName(); //We need to make sure pluginId is safe - starts with a char and is only alphaNumeric String safePluginId = this.sanitizePluginId(pluginId); if (endpoints != null) { for (IElement endpoint : endpoints) { // filter endpoints that aren't data sources if (!(endpoint instanceof IDataSourceProvider)) { continue; } logger.info(String.format("DataSource Endpoint found: %s)", endpoint)); IDataSourceProvider dataSourceProvider = (IDataSourceProvider) endpoint; String endpointName = endpoint.getName(); DataSource dataSource = dataSourceProvider.getDataSource(); dataSource.getMetadata().setPluginId(pluginId); dataSources.add(dataSource); dsDeclarations.append(String.format("\"%s_%s_CPKENDPOINT\": ", safePluginId, endpointName)); dsDeclarations.append(mapper.writeValueAsString(dataSource)); dsDeclarations.append(","); } } int index = dsDeclarations.lastIndexOf(","); if (index > 0) { dsDeclarations.deleteCharAt(index); } dsDeclarations.append("}"); IOUtils.write(dsDeclarations.toString(), response.getOutputStream()); response.getOutputStream().flush(); }
From source file:fr.gael.dhus.olingo.v1.Processor.java
private URI makeLink(boolean remove_last_segment) throws ODataException { try {/*from ww w. ja v a2 s . c o m*/ URIBuilder ub = new URIBuilder(ServiceFactory.EXTERNAL_URL); StringBuilder sb = new StringBuilder(); String prefix = ub.getPath(); String path = getContext().getPathInfo().getRequestUri().getPath(); if (path == null || path.isEmpty() || prefix != null && !prefix.isEmpty() && !path.startsWith(ub.getPath())) { sb.append(prefix); if (path != null) { if (prefix.endsWith("/") && path.startsWith("/")) { sb.deleteCharAt(sb.length() - 1); } if (!prefix.endsWith("/") && !path.startsWith("/")) { sb.append('/'); } } } sb.append(path); if (remove_last_segment) { // Removes the last segment. int lio = sb.lastIndexOf("/"); while (lio != -1 && lio == sb.length() - 1) { sb.deleteCharAt(lio); lio = sb.lastIndexOf("/"); } if (lio != -1) { sb.delete(lio + 1, sb.length()); } // Removes the `$links` segment. lio = sb.lastIndexOf("$links/"); if (lio != -1) { sb.delete(lio, lio + 7); } } else if (!sb.toString().endsWith("/") && !sb.toString().endsWith("\\")) { sb.append("/"); } ub.setPath(sb.toString()); return ub.build(); } catch (NullPointerException | URISyntaxException e) { throw new ODataException(e); } }
From source file:com.impetus.client.cassandra.query.CassQuery.java
/** * Append in clause./*ww w. j a v a 2 s. co m*/ * * @param queryBuilder * the query builder * @param translator * the translator * @param value * the value * @param fieldClazz * the field clazz * @param columnName * the column name * @param isPresent * the is present * @return true, if successful */ private boolean appendInClause(StringBuilder queryBuilder, CQLTranslator translator, List<Object> value, Class fieldClazz, String columnName, boolean isPresent) { isPresent = appendIn(queryBuilder, translator, columnName); queryBuilder.append("("); for (Object objectvalue : value) { translator.appendValue(queryBuilder, fieldClazz, objectvalue, isPresent, false); queryBuilder.append(", "); } queryBuilder.deleteCharAt(queryBuilder.lastIndexOf(", ")); queryBuilder.append(") "); queryBuilder.append(" AND "); return isPresent; }
From source file:org.cloudifysource.dsl.cloud.compute.ComputeTemplate.java
/** * * @return .//from w w w .ja va2 s .c o m */ public String toFormatedString() { final StringBuilder sb = new StringBuilder(); sb.append("{"); sb.append(CloudifyConstants.NEW_LINE); sb.append(getFormatedLine("imageId", imageId)); sb.append(getFormatedLine("hardwareId", hardwareId)); sb.append(getFormatedLine("locationId", locationId)); sb.append(getFormatedLine("localDirectory", localDirectory)); sb.append(getFormatedLine("keyFile", keyFile)); sb.append(getFormatedLine("numberOfCores", numberOfCores)); sb.append(getFormatedLine("options", options)); sb.append(getFormatedLine("overrides", overrides)); sb.append(getFormatedLine("custom", custom)); sb.append(getFormatedLine("fileTransfer", fileTransfer)); sb.append(getFormatedLine("remoteExecution", remoteExecution)); sb.append(getFormatedLine("username", username)); sb.append(getFormatedLine("password", password)); sb.append(getFormatedLine("remoteDirectory", remoteDirectory)); sb.append(getFormatedLine("privileged", privileged)); sb.append(getFormatedLine("initializationCommand", initializationCommand)); sb.append(getFormatedLine("javaUrl", javaUrl)); sb.append(getFormatedLine("absoluteUploadDir", absoluteUploadDir)); sb.append(getFormatedLine("env ", env)); sb.append(getFormatedLine("machineMemoryMB", machineMemoryMB)); final String str = sb.substring(0, sb.lastIndexOf(",")); return str + CloudifyConstants.NEW_LINE + "}"; }
From source file:io.anserini.doc.DataModel.java
public String generateEffectiveness(String collection) { Map<String, Object> config = this.collections.get(collection); StringBuilder builder = new StringBuilder(); ObjectMapper oMapper = new ObjectMapper(); List models = oMapper.convertValue((List) safeGet(config, "models"), List.class); List topics = oMapper.convertValue((List) safeGet(config, "topics"), List.class); List evals = oMapper.convertValue((List) safeGet(config, "evals"), List.class); for (Object evalObj : evals) { Eval eval = oMapper.convertValue(evalObj, Eval.class); builder.append(String.format("%1$-40s|", eval.getMetric().toUpperCase())); for (Object modelObj : models) { Model model = oMapper.convertValue(modelObj, Model.class); builder.append(String.format(" %1$-10s|", model.getName().toUpperCase())); }/*from w w w.j a v a 2s .com*/ builder.append("\n"); builder.append(":").append(StringUtils.repeat("-", 39)).append("|"); for (Object modelObj : models) { builder.append(StringUtils.repeat("-", 11)).append("|"); } builder.append("\n"); for (int i = 0; i < topics.size(); i++) { Topic topic = oMapper.convertValue(topics.get(i), Topic.class); builder.append(String.format("%1$-40s|", topic.getName().toUpperCase())); for (Object modelObj : models) { Model model = oMapper.convertValue(modelObj, Model.class); builder.append(String.format(" %-10.4f|", model.getResults().get(eval.getMetric()).get(i))); } builder.append("\n"); } builder.append("\n\n"); } builder.delete(builder.lastIndexOf("\n"), builder.length()); return builder.toString(); }