List of usage examples for java.lang StringBuilder charAt
char charAt(int index);
From source file:com.funambol.foundation.items.dao.PIMNoteDAO.java
private static String truncateStringList(String categoriesField, String separatorsString, int truncationSize) { if (categoriesField == null) { return null; }/*from w w w. j a va 2s.c o m*/ StringTokenizer st = new StringTokenizer(categoriesField, separatorsString, true); StringBuilder sb = new StringBuilder(""); while (st.hasMoreTokens()) { String token = st.nextToken(); if (sb.length() + token.length() > truncationSize) { break; } sb.append(token); } if (sb.length() > 0) { char[] separators = separatorsString.toCharArray(); for (char separator : separators) { if (sb.charAt(sb.length() - 1) == separator) { sb.deleteCharAt(sb.length() - 1); break; } } } return sb.toString(); }
From source file:net.ymate.framework.commons.ParamUtils.java
public static String appendQueryParamValue(String url, Map<String, String> params, boolean encode, String charset) {//from w w w . j ava 2 s. c o m if (params != null && !params.isEmpty()) { StringBuilder _paramSB = new StringBuilder(url); if (!url.contains("?")) { _paramSB.append("?"); } else { _paramSB.append("&"); } for (Map.Entry<String, String> _param : params.entrySet()) { if (encode) { try { _paramSB.append(_param.getKey()).append("=").append( URLEncoder.encode(_param.getValue(), StringUtils.defaultIfBlank(charset, "UTF-8"))) .append("&"); } catch (UnsupportedEncodingException e) { _LOG.warn("", RuntimeUtils.unwrapThrow(e)); } } else { _paramSB.append(_param.getKey()).append("=").append(_param.getValue()).append("&"); } } if (_paramSB.length() > 0 && _paramSB.charAt(_paramSB.length() - 1) == '&') { _paramSB.setLength(_paramSB.length() - 1); } return _paramSB.toString(); } return url; }
From source file:net.sf.xfd.provider.ProviderBase.java
public static void stripSlashes(StringBuilder chars) { int length = chars.length(); int prevSlash = -1; for (int i = length - 1; i >= 0; --i) { if ('/' == chars.charAt(i)) { if (prevSlash == i + 1) { chars.deleteCharAt(i);// w w w .j a v a 2 s .c o m --prevSlash; } else { prevSlash = i; } } } }
From source file:com.aiblockchain.api.StringUtils.java
/** * Ensures that the given string builder has one newline characters at the end of its buffer. * * @param stringBuilder the given string builder *///from w w w. j ava 2s . co m public static void ensureOneNewLine(final StringBuilder stringBuilder) { //Preconditions assert stringBuilder != null : "stringBuilder must not be null"; final int length = stringBuilder.length(); if (length == 0) { stringBuilder.append('\n'); return; } final char ch1 = stringBuilder.charAt(length - 1); if (ch1 == '\n') { return; } else { stringBuilder.append('\n'); return; } }
From source file:at.porscheinformatik.common.spring.web.extended.http.DefaultLinkCreator.java
@Override public String createLink(String... parts) { if (parts == null) { return null; }//from w w w . j a v a2 s. co m StringBuilder url = new StringBuilder(); prefix(url); if (url.length() == 0 || url.charAt(url.length() - 1) != '/') { url.append("/"); } url.append(LocaleContextHolder.getLocale().toLanguageTag()); if (appConfig != null && appConfig.getVersion() != null) { url.append("/").append(appConfig.getVersion()); } for (String part : parts) { if (!part.startsWith("/")) { url.append("/"); } url.append(part); } suffix(url); return url.toString(); }
From source file:com.liferay.events.global.mobile.Utils.java
/** * Gets a set of matching characters between two strings. * <p/>/*from w ww. j av a 2s . c o m*/ * <p><Two characters from the first string and the second string are considered matching if the character's * respective positions are no farther than the limit value.</p> * * @param first The first string. * @param second The second string. * @param limit The maximum distance to consider. * @return A string contain the set of common characters. */ private static String getSetOfMatchingCharacterWithin(final CharSequence first, final CharSequence second, final int limit) { final StringBuilder common = new StringBuilder(); final StringBuilder copy = new StringBuilder(second); for (int i = 0; i < first.length(); i++) { final char ch = first.charAt(i); boolean found = false; // See if the character is within the limit positions away from the original position of that character. for (int j = Math.max(0, i - limit); !found && j < Math.min(i + limit, second.length()); j++) { if (copy.charAt(j) == ch) { found = true; common.append(ch); copy.setCharAt(j, '*'); } } } return common.toString(); }
From source file:com.microsoft.tfs.client.common.ui.teambuild.commands.CheckBuildFileExistsCommand.java
@Override protected IStatus doRun(final IProgressMonitor progressMonitor) { final String requiredPrefix = isGit ? GitProperties.GitPathBeginning : ServerPath.ROOT; if (!folderPath.startsWith(requiredPrefix)) { final String messageFormat = Messages .getString("CheckBuildFileExistsCommand.InvalidBuildFileServerPathFormat"); //$NON-NLS-1$ final String message = MessageFormat.format(messageFormat, folderPath, requiredPrefix); return new Status(IStatus.ERROR, TFSTeamBuildPlugin.PLUGIN_ID, Status.OK, message, new BuildException(message)); }//from w w w . j av a 2 s. c om final StringBuilder sb = new StringBuilder(folderPath); if (sb.charAt(sb.length() - 1) != ServerPath.PREFERRED_SEPARATOR_CHARACTER) { sb.append(ServerPath.PREFERRED_SEPARATOR_CHARACTER); } final String itemPath = sb.append(BuildConstants.PROJECT_FILE_NAME).toString(); return isGit ? checkGitVC(progressMonitor, itemPath) : checkTFVC(progressMonitor, itemPath); }
From source file:com.splicemachine.derby.utils.SpliceAdmin.java
public static void SYSCS_GET_LOGGERS(final ResultSet[] resultSet) throws SQLException { Set<String> loggers = EngineDriver.driver().dbAdministrator().getLoggers(); StringBuilder sb = new StringBuilder("select * from (values "); List<String> loggerNames = new ArrayList<>(loggers); Collections.sort(loggerNames); for (String logger : loggerNames) { sb.append(String.format("('%s')", logger)); sb.append(", "); }//from w w w . j a v a2 s. c o m if (sb.charAt(sb.length() - 2) == ',') { sb.setLength(sb.length() - 2); } sb.append(") foo (spliceLogger)"); resultSet[0] = executeStatement(sb); }
From source file:Main.java
/** * Parse the given name.//ww w . j a v a 2 s. c om * * @param sourceName * @param separator * @return some stuff parsed from the name */ private static List<String> parseName(String sourceName, char separator) { List<String> result = new ArrayList<String>(); if (sourceName != null) { StringBuilder currentWord = new StringBuilder(64); boolean lastIsLower = false; int index; int length; for (index = 0, length = sourceName.length(); index < length; ++index) { char curChar = sourceName.charAt(index); if (!Character.isJavaIdentifierPart(curChar)) { curChar = separator; } if (Character.isUpperCase(curChar) || (!lastIsLower && Character.isDigit(curChar)) || curChar == separator) { if (lastIsLower && currentWord.length() > 1 || curChar == separator && currentWord.length() > 0) { result.add(currentWord.toString()); currentWord = new StringBuilder(64); } lastIsLower = false; } else { if (!lastIsLower) { int currentWordLength = currentWord.length(); if (currentWordLength > 1) { char lastChar = currentWord.charAt(--currentWordLength); currentWord.setLength(currentWordLength); result.add(currentWord.toString()); currentWord = new StringBuilder(64); currentWord.append(lastChar); } } lastIsLower = true; } if (curChar != separator) { currentWord.append(curChar); } } result.add(currentWord.toString()); } return result; }
From source file:net.jofm.format.Format.java
private String trimLeftPad(String data) { if (data == null || data.length() == 0) { return data; }//from w w w.j av a 2s . c o m StringBuilder builder = new StringBuilder(data); while (builder.length() > 0 && builder.charAt(0) == padWith) { builder.deleteCharAt(0); } return builder.toString(); }