List of usage examples for java.lang StringBuilder charAt
char charAt(int index);
From source file:io.gravitee.gateway.reactor.handler.impl.DefaultReactorHandlerResolver.java
@Override public ReactorHandler resolve(Request request) { StringBuilder path = new StringBuilder(request.path()); if (path.charAt(path.length() - 1) != '/') { path.append('/'); }/*from w w w. j av a 2 s .c om*/ Optional<ReactorHandler> handlers = handlerRegistry.getReactorHandlers().stream() .filter(handler -> path.toString().startsWith(handler.contextPath())).findFirst(); if (handlers.isPresent()) { ReactorHandler handler = handlers.get(); LOGGER.debug("Returning the first handler matching path {} : {}", path, handler); return handler; } return null; }
From source file:org.bonitasoft.web.designer.studio.workspace.RestClient.java
/** * Creates URL based on the URI passed in. *//*from w w w . j a v a 2 s .c o m*/ public String createURI(String uri) { StringBuilder sb = new StringBuilder(clientProperties.getUrl()); if (sb.charAt(sb.length() - 1) != '/') { sb.append("/"); } sb.append(uri); return sb.toString(); }
From source file:com.zimbra.cs.service.formatter.VCard.java
static boolean isAllWhitespace(StringBuilder line) { int length = line.length(); for (int ndx = 0; ndx < length; ndx++) { if (!Character.isWhitespace(line.charAt(ndx))) { return false; }/*from www. j a v a 2s . c o m*/ } return true; }
From source file:gov.nih.nci.cabig.ctms.lookandfeel.AssetServlet.java
private String resourcePath(String pathInfo) { StringBuilder res = new StringBuilder(getResourceBase()); if (res.charAt(res.length() - 1) != '/') res.append('/'); if (pathInfo.startsWith("/")) { res.append(pathInfo.substring(1)); } else {//from www. j ava 2s.com res.append(pathInfo); } return res.toString(); }
From source file:net.sf.xfd.provider.ProviderBase.java
public static void removeDotSegments(StringBuilder chars) { if (chars.charAt(0) != '/') return;/*ww w .ja v a2s .com*/ /** * / proc / self / .. / vmstat */ int seg1 = 0, seg2 = 0, seg3 = 0, seg4 = 0; int segCnt = 0; for (int i = 1; i < chars.length(); ++i) { if ('/' == chars.charAt(i)) { int segStart = 0; switch (segCnt) { case 0: // seg2 == 0 seg2 = i; segStart = seg1; ++segCnt; break; case 1: // seg3 = 0 seg3 = i; segStart = seg2; ++segCnt; break; case 2: // seg4 = 0 seg4 = i; segStart = seg3; ++segCnt; break; case 3: // seg4 > 0, carry seg1 = seg2; seg2 = seg3; seg3 = seg4; seg4 = i; segStart = seg3; } final int segLength = i - segStart; switch (segLength) { default: break; case 2: if (chars.charAt(segStart + 1) == '.') { chars.delete(segStart, i); --segCnt; i = segStart; } break; case 3: if (chars.charAt(segStart + 1) == '.' && chars.charAt(segStart + 2) == '.') { final int prevSegmentStart; if (segCnt == 3) { prevSegmentStart = seg2; segCnt = 1; } else { prevSegmentStart = seg1; segCnt = 0; } chars.delete(prevSegmentStart, i); i = prevSegmentStart; } } } } final int resultLength = chars.length(); if ('/' != chars.charAt(resultLength - 1)) { int lastSlash, prevSlash = 0; switch (segCnt) { case 3: lastSlash = seg4; prevSlash = seg3; break; case 2: lastSlash = seg3; prevSlash = seg2; break; case 1: lastSlash = seg2; prevSlash = seg1; break; default: lastSlash = 0; } switch (resultLength - lastSlash) { case 2: if (chars.charAt(lastSlash + 1) == '.') { chars.delete(lastSlash + 1, resultLength + 1); } break; case 3: if (chars.charAt(lastSlash + 1) == '.' && chars.charAt(lastSlash + 2) == '.') { chars.delete(prevSlash + 1, resultLength + 1); } break; } } }
From source file:com.zacwolf.commons.utils.PasswordUtils.java
public static String generateRandom(int minLength, int maxLength, int minLCaseCount, int minUCaseCount, int minNumCount, int minSpecialCount) { final Map<Integer, Integer> charGroupsUsed = new HashMap<Integer, Integer>(); charGroupsUsed.put(lcase, minLCaseCount); charGroupsUsed.put(ucase, minUCaseCount); charGroupsUsed.put(num, minNumCount); charGroupsUsed.put(special, minSpecialCount); final char[] randomString; if (minLength < maxLength) { randomString = new char[RandomUtils.nextInt(minLength, maxLength + 1)]; } else {/*from w ww . java 2s . co m*/ randomString = new char[minLength]; } int requiredCharactersLeft = minLCaseCount + minUCaseCount + minNumCount + minSpecialCount; for (int i = 0; i < randomString.length; i++) { final StringBuilder selectableChars = new StringBuilder(); if (requiredCharactersLeft < randomString.length - i) { selectableChars.append(LCaseChars).append(UCaseChars).append(NumericChars).append(SpecialChars); } else { for (Integer k : charGroupsUsed.keySet()) { if (charGroupsUsed.get(k) > 0) switch (k) { case lcase: selectableChars.append(LCaseChars); break; case ucase: selectableChars.append(UCaseChars); break; case num: selectableChars.append(NumericChars); break; case special: selectableChars.append(SpecialChars); break; } } } final char nextChar = selectableChars.charAt(RandomUtils.nextInt(0, selectableChars.length())); randomString[i] = nextChar; if (LCaseChars.contains(String.valueOf(nextChar))) { charGroupsUsed.put(lcase, charGroupsUsed.get(lcase) - 1); if (charGroupsUsed.get(lcase) >= 0) requiredCharactersLeft--; } else if (UCaseChars.contains(String.valueOf(nextChar))) { charGroupsUsed.put(ucase, charGroupsUsed.get(ucase) - 1); if (charGroupsUsed.get(ucase) >= 0) requiredCharactersLeft--; } else if (NumericChars.contains(String.valueOf(nextChar))) { charGroupsUsed.put(num, charGroupsUsed.get(num) - 1); if (charGroupsUsed.get(num) >= 0) requiredCharactersLeft--; } else if (SpecialChars.contains(String.valueOf(nextChar))) { charGroupsUsed.put(special, charGroupsUsed.get(special) - 1); if (charGroupsUsed.get(special) >= 0) requiredCharactersLeft--; } } return new String(randomString); }
From source file:com.zacwolf.commons.wbxcon.PasswordUtils.java
public static String generateRandom(final int minLength, final int maxLength, final int minLCaseCount, final int minUCaseCount, final int minNumCount, final int minSpecialCount) { final Map<Integer, Integer> charGroupsUsed = new HashMap<Integer, Integer>(); charGroupsUsed.put(lcase, minLCaseCount); charGroupsUsed.put(ucase, minUCaseCount); charGroupsUsed.put(num, minNumCount); charGroupsUsed.put(special, minSpecialCount); final char[] randomString; if (minLength < maxLength) { randomString = new char[RandomUtils.nextInt(minLength, maxLength + 1)]; } else {//from www . j ava2 s . co m randomString = new char[minLength]; } int requiredCharactersLeft = minLCaseCount + minUCaseCount + minNumCount + minSpecialCount; for (int i = 0; i < randomString.length; i++) { final StringBuilder selectableChars = new StringBuilder(); if (requiredCharactersLeft < randomString.length - i) { selectableChars.append(LCaseChars).append(UCaseChars).append(NumericChars).append(SpecialChars); } else { for (final Integer k : charGroupsUsed.keySet()) { if (charGroupsUsed.get(k) > 0) switch (k) { case lcase: selectableChars.append(LCaseChars); break; case ucase: selectableChars.append(UCaseChars); break; case num: selectableChars.append(NumericChars); break; case special: selectableChars.append(SpecialChars); break; } } } final char nextChar = selectableChars.charAt(RandomUtils.nextInt(0, selectableChars.length())); randomString[i] = nextChar; if (LCaseChars.contains(String.valueOf(nextChar))) { charGroupsUsed.put(lcase, charGroupsUsed.get(lcase) - 1); if (charGroupsUsed.get(lcase) >= 0) requiredCharactersLeft--; } else if (UCaseChars.contains(String.valueOf(nextChar))) { charGroupsUsed.put(ucase, charGroupsUsed.get(ucase) - 1); if (charGroupsUsed.get(ucase) >= 0) requiredCharactersLeft--; } else if (NumericChars.contains(String.valueOf(nextChar))) { charGroupsUsed.put(num, charGroupsUsed.get(num) - 1); if (charGroupsUsed.get(num) >= 0) requiredCharactersLeft--; } else if (SpecialChars.contains(String.valueOf(nextChar))) { charGroupsUsed.put(special, charGroupsUsed.get(special) - 1); if (charGroupsUsed.get(special) >= 0) requiredCharactersLeft--; } } return new String(randomString); }
From source file:de.micromata.genome.gwiki.page.impl.wiki.fragment.GWikiFragmentList.java
@Override public void getSource(StringBuilder sb) { if (sb.length() > 0 && sb.charAt(sb.length() - 1) != '\n') { sb.append("\n"); }// w ww . j a v a 2s. co m getChildSouce(sb); }
From source file:net.sourceforge.kalimbaradio.androidapp.util.Util.java
public static String getRestUrl(Context context, String method) { StringBuilder builder = new StringBuilder(); ServerSettingsManager serverMgr = new ServerSettingsManager(context); ServerSettingsManager.ServerSettings server = serverMgr.getActiveServer(); String serverUrl = server.getUrl(); String username = server.getUsername(); String password = server.getPassword(); // Slightly obfuscate password password = "enc:" + Util.utf8HexEncode(password); builder.append(serverUrl);//from w ww. ja v a 2 s . co m if (builder.charAt(builder.length() - 1) != '/') { builder.append("/"); } builder.append("rest/").append(method).append(".view"); builder.append("?u=").append(username); builder.append("&p=").append(password); builder.append("&v=").append(Constants.REST_PROTOCOL_VERSION); builder.append("&c=").append(Constants.REST_CLIENT_ID); return builder.toString(); }
From source file:com.springrts.springls.Client.java
private static void deleteLeadingWhiteSpace(StringBuilder str) { int wsPos = 0; while ((wsPos < str.length()) && isWhiteSpace(str.charAt(wsPos))) { wsPos++;//from ww w. j ava 2 s . c o m } str.delete(0, wsPos); }