List of usage examples for java.lang StringBuilder lastIndexOf
@Override public int lastIndexOf(String str)
From source file:org.obiba.onyx.spring.context.OnyxMessageSourceFactoryBean.java
protected String resolveBasename(String pathPrefix, Resource bundleResource) { // Resource#getFilename() does not return the full path. As such, we must get the underlying File instance. // Since all Resource instances are not File instances, this will only work with resources on the filesystem. File bundleFile;/*from ww w .ja v a 2 s . c o m*/ try { bundleFile = bundleResource.getFile(); } catch (IOException e) { log.info("Cannot add resource {} to MessageSource because it is not on the filesystem.", bundleResource.getDescription()); return null; } String filename = bundleFile.getAbsolutePath(); // Make file pathname compatible with Spring's pathnames (if necessary) if (File.separatorChar != '/') { filename = filename.replace(File.separatorChar, '/'); } StringBuilder basename = new StringBuilder(filename); int rootDirIndex = basename.lastIndexOf(pathPrefix); // Remove everything before pathPrefix if (rootDirIndex > 0) { basename.delete(0, rootDirIndex); } // Find the last part that fits the bundle's name int basenameIndex = basename.lastIndexOf(MESSAGES_BUNDLENAME); int length = basename.length(); // Delete anything appearing after the bundle's name basename.delete(basenameIndex + MESSAGES_BUNDLENAME.length(), length); return basename.toString(); }
From source file:org.jts.docGenerator.indexFiles.MainMenu.java
private String getUrl(String url) { url = new File(new File(destDir.getPath()).toURI().relativize(new File(url).toURI()).getPath()).getPath(); StringBuilder urlBuilder = new StringBuilder(url); // add filename + html extension String filename = urlBuilder.substring(urlBuilder.lastIndexOf(File.separator) + 1, urlBuilder.length()) + ".html"; urlBuilder.append(File.separator); urlBuilder.append(filename);/*from ww w. ja va2s .com*/ URLHelpers.urlize(urlBuilder); return urlBuilder.toString(); }
From source file:org.apache.ambari.server.checks.AbstractCheckDescriptor.java
/** * Formats lists of given entities to human readable form: * [entity1] -> {entity1} {noun}// w w w .ja va 2s. c o m * [entity1, entity2] -> {entity1} and {entity2} {noun}s * [entity1, entity2, entity3] -> {entity1}, {entity2} and {entity3} {noun}s * The noun for the entities is taken from check type, it may be cluster, service or host. * * @param entities list of entities to format * @return formatted entity list */ protected String formatEntityList(List<String> entities) { if (entities == null || entities.isEmpty()) { return ""; } final StringBuilder formatted = new StringBuilder(StringUtils.join(entities, ", ")); if (entities.size() > 1) { formatted.replace(formatted.lastIndexOf(","), formatted.lastIndexOf(",") + 1, " and"); } return formatted.toString(); }
From source file:org.eclipse.jubula.client.ui.rcp.widgets.ParamProposalProvider.java
/** * /*w ww. j a va 2 s . com*/ * @param contents The text for which to generate content proposals. * @param position The current position in the text for which to generate * proposals. * @return the proposals for the given arguments. */ private Collection<IContentProposal> getValueSetProposals(String contents, int position) { List<IContentProposal> proposals = new ArrayList<IContentProposal>(); StringBuilder sb = new StringBuilder(contents); sb.delete(position, sb.length()); sb.delete(0, sb.lastIndexOf(TestDataConstants.COMBI_VALUE_SEPARATOR) + 1); for (String predefValue : m_valueSet) { if (predefValue.startsWith(sb.toString())) { proposals.add(new ParamProposal(predefValue.substring(sb.length()), predefValue)); } else if (predefValue.startsWith(contents)) { proposals.add(new ParamProposal(predefValue.substring(contents.length()), predefValue)); } } return proposals; }
From source file:com.svds.resttest.operator.BuildWhereClause.java
/** * Create a WHERE clause given parameters from GET request * //from w w w .j a v a2s.c om * @param requestParams query parameters form GET request * @return SQL WHERE clause * @throws BuildWhereException */ public static String buildWhereClause(MultiValueMap<String, String> requestParams) throws BuildWhereException { Set<String> columnNames = new HashSet<>(); for (String key : requestParams.keySet()) { for (String value : requestParams.get(key)) { LOG.info("key:" + key + " : value:" + value); } if (key.startsWith(COLUMN_TAG)) { LOG.info("key - substr: " + key.substring(8)); columnNames.add(key.substring(8)); } } StringBuilder whereClause = new StringBuilder(); for (String value : columnNames) { LOG.info("Column Name: " + value); LOG.info("Got this operator: " + requestParams.containsKey(OPERATOR_TAG + value)); LOG.info("Got this operator - value: " + requestParams.getFirst(OPERATOR_TAG + value)); LOG.info("Got this column: " + requestParams.containsKey(COLUMN_TAG + value)); LOG.info("Got this column - value: " + requestParams.get(COLUMN_TAG + value)); try { String operatorValue = requestParams.getFirst(OPERATOR_TAG + value); Operator operator = OperatorFactory.getOperatorClass(operatorValue); String operatorProcessValue; operatorProcessValue = operator.process(value, requestParams.get(COLUMN_TAG + value)); whereClause.append(operatorProcessValue).append(AND); } catch (OperatorsException ex) { LOG.error("OperatorException: " + ex.getMessage(), ex); throw new BuildWhereException(ex); } } LOG.info("Value whereClause: " + whereClause); String returnValue = whereClause.substring(0, whereClause.lastIndexOf(AND)); LOG.info("WhereClause: " + returnValue); return returnValue; }
From source file:org.pz.platypus.CommandLineArgs.java
private String getNameMinusExtension(String str) { String ret = str;/*from www . j a va2s .c o m*/ StringBuilder fileBuilder = new StringBuilder(str); int lastDotAt = fileBuilder.lastIndexOf("."); if (lastDotAt != -1) { ret = ret.substring(0, lastDotAt); } return ret; }
From source file:com.impetus.kundera.utils.KunderaCoreUtils.java
/** * Prepares composite key ./*from w ww .ja va 2 s . co m*/ * * @param m * entity metadata * @param compositeKey * composite key instance * @return redis key */ public static String prepareCompositeKey(final EntityMetadata m, final Object compositeKey) { Field[] fields = m.getIdAttribute().getBindableJavaType().getDeclaredFields(); StringBuilder stringBuilder = new StringBuilder(); for (Field f : fields) { if (!ReflectUtils.isTransientOrStatic(f)) { try { String fieldValue = PropertyAccessorHelper.getString(compositeKey, f); // what if field value is null???? stringBuilder.append(fieldValue); stringBuilder.append(COMPOSITE_KEY_SEPERATOR); } catch (IllegalArgumentException e) { logger.error("Error during prepare composite key, Caused by {}.", e); throw new PersistenceException(e); } } } if (stringBuilder.length() > 0) { stringBuilder.deleteCharAt(stringBuilder.lastIndexOf(COMPOSITE_KEY_SEPERATOR)); } return stringBuilder.toString(); }
From source file:org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidEntityException.java
@Override public String getMessage() { StringBuilder sb = new StringBuilder(); for (Class<?> entity : violations.keySet()) { sb.append(entity.getSimpleName()).append(' ').append(violations.get(entity).toString()).append(", "); }/* ww w. ja va 2 s. c o m*/ sb.delete(sb.lastIndexOf(", "), sb.length()); return sb.toString(); }
From source file:net.duckling.ddl.service.resource.dao.StarmarkDAOImpl.java
@Override public int batchDelete(String uid, int tid, List<Long> rids) { if (null == rids || rids.isEmpty()) { return 0; }// w w w. j a v a 2 s . c o m String sql = "delete from a1_starmark where uid=? and tid=? and rid in("; StringBuilder sb = new StringBuilder(); for (long rid : rids) { sb.append(rid + ","); } sb.replace(sb.lastIndexOf(","), sb.length(), ")"); sql += sb.toString(); return this.getJdbcTemplate().update(sql, new Object[] { uid, tid }); }
From source file:org.springframework.yarn.support.console.UiUtils.java
/** * Renders a textual representation of the provided {@link Table} * * @param table Table data {@link Table} * @param withHeader with header// w w w .jav a 2s . co m * @return The rendered table representation as String */ public static String renderTextTable(Table table, boolean withHeader) { table.calculateColumnWidths(); final String padding = " "; final String headerBorder = getHeaderBorder(table.getHeaders()); final StringBuilder textTable = new StringBuilder(); if (withHeader) { final StringBuilder headerline = new StringBuilder(); for (TableHeader header : table.getHeaders().values()) { if (header.getName().length() > header.getWidth()) { Iterable<String> chunks = Splitter.fixedLength(header.getWidth()).split(header.getName()); int length = headerline.length(); boolean first = true; for (String chunk : chunks) { final String lineToAppend; if (first) { lineToAppend = padding + CommonUtils.padRight(chunk, header.getWidth()); } else { lineToAppend = StringUtils.leftPad("", length) + padding + CommonUtils.padRight(chunk, header.getWidth()); } first = false; headerline.append(lineToAppend); headerline.append("\n"); } headerline.deleteCharAt(headerline.lastIndexOf("\n")); } else { String lineToAppend = padding + CommonUtils.padRight(header.getName(), header.getWidth()); headerline.append(lineToAppend); } } textTable.append(org.springframework.util.StringUtils.trimTrailingWhitespace(headerline.toString())); textTable.append("\n"); } textTable.append(headerBorder); for (TableRow row : table.getRows()) { StringBuilder rowLine = new StringBuilder(); for (Entry<Integer, TableHeader> entry : table.getHeaders().entrySet()) { String value = row.getValue(entry.getKey()); if (value.length() > entry.getValue().getWidth()) { Iterable<String> chunks = Splitter.fixedLength(entry.getValue().getWidth()).split(value); int length = rowLine.length(); boolean first = true; for (String chunk : chunks) { final String lineToAppend; if (first) { lineToAppend = padding + CommonUtils.padRight(chunk, entry.getValue().getWidth()); } else { lineToAppend = StringUtils.leftPad("", length) + padding + CommonUtils.padRight(chunk, entry.getValue().getWidth()); } first = false; rowLine.append(lineToAppend); rowLine.append("\n"); } rowLine.deleteCharAt(rowLine.lastIndexOf("\n")); } else { String lineToAppend = padding + CommonUtils.padRight(value, entry.getValue().getWidth()); rowLine.append(lineToAppend); } } textTable.append(org.springframework.util.StringUtils.trimTrailingWhitespace(rowLine.toString())); textTable.append("\n"); } if (!withHeader) { textTable.append(headerBorder); } return textTable.toString(); }