List of usage examples for java.lang StringBuilder delete
@Override public StringBuilder delete(int start, int end)
From source file:org.apache.oozie.coord.input.dependency.CoordOldInputDependency.java
private boolean checkListOfPaths(CoordinatorActionBean coordAction, StringBuilder existList, StringBuilder nonExistList, Configuration conf) throws IOException { String[] uriList = nonExistList.toString().split(CoordELFunctions.INSTANCE_SEPARATOR); if (uriList[0] != null) { log.info("[" + coordAction.getId() + "]::ActionInputCheck:: In checkListOfPaths: " + uriList[0] + " is Missing."); }//from w w w . j a v a 2 s.com nonExistList.delete(0, nonExistList.length()); boolean allExists = true; String existSeparator = "", nonExistSeparator = ""; String user = ParamChecker.notEmpty(conf.get(OozieClient.USER_NAME), OozieClient.USER_NAME); for (int i = 0; i < uriList.length; i++) { if (allExists) { allExists = pathExists(coordAction, uriList[i], conf, user); log.info("[" + coordAction.getId() + "]::ActionInputCheck:: File:" + uriList[i] + ", Exists? :" + allExists); } if (allExists) { existList.append(existSeparator).append(uriList[i]); existSeparator = CoordELFunctions.INSTANCE_SEPARATOR; } else { nonExistList.append(nonExistSeparator).append(uriList[i]); nonExistSeparator = CoordELFunctions.INSTANCE_SEPARATOR; } } return allExists; }
From source file:com.jkoolcloud.tnt4j.streams.utils.Utils.java
/** * Clears string builder content.//w ww . j ava 2 s. com * * @param sb * string builder to clear content * @return empty string builder */ public static StringBuilder clear(StringBuilder sb) { return sb == null ? null : sb.delete(0, sb.length()); }
From source file:net.yacy.search.query.QueryParams.java
/** * Remove from the URL builder any query modifiers with the same name that the new modifier * @param sb/*from w ww . j a va2 s . c om*/ * a StringBuilder holding the search URL navigation being built. * Must not be null and contain the URL base and the query string * with its eventual modifiers * @param newModifier * a new modifier of form key:value. Must not be null. */ protected static void removeOldModifiersFromNavUrl(final StringBuilder sb, final String newModifier) { int nmpi = newModifier.indexOf(":"); if (nmpi > 0) { final String newModifierKey = newModifier.substring(0, nmpi) + ":"; int sameModifierIndex = sb.indexOf(newModifierKey); while (sameModifierIndex > 0) { final int spaceModifierIndex = sb.indexOf(" ", sameModifierIndex); if (spaceModifierIndex > sameModifierIndex) { /* There are other modifiers after the matching one : we only remove the old matching modifier */ sb.delete(sameModifierIndex, spaceModifierIndex + 1); } else { /* The matching modifier is the last : we truncate the builder */ sb.setLength(sameModifierIndex); } sameModifierIndex = sb.indexOf(newModifierKey); } if (sb.charAt(sb.length() - 1) == '+') { sb.setLength(sb.length() - 1); } if (sb.charAt(sb.length() - 1) == ' ') { sb.setLength(sb.length() - 1); } } }
From source file:de.itsvs.cwtrpc.controller.RemoteServiceControllerServlet.java
protected PreparedRemoteServiceConfig getServiceConfig(HttpServletRequest request) { final String contextPath; final StringBuilder uri; final PreparedRemoteServiceConfig serviceConfig; contextPath = request.getContextPath(); uri = new StringBuilder(request.getRequestURI()); if ((contextPath.length() > 0) && (uri.indexOf(contextPath) == 0)) { uri.delete(0, contextPath.length()); }/*from w ww. j a v a 2s . c o m*/ if ((uri.length() > 0) || (uri.charAt(0) == '/')) { uri.deleteCharAt(0); } if (log.isDebugEnabled()) { log.debug("Service URI is '" + uri + "'"); } serviceConfig = getServiceConfigsByUri().get(uri.toString()); return serviceConfig; }
From source file:net.sf.jabref.gui.autocompleter.AutoCompleteListener.java
private void cycle(JTextComponent comp, int increment) { assert (lastCompletions != null); assert (!lastCompletions.isEmpty()); lastShownCompletion += increment;/* w w w .j a v a 2s .co m*/ if (lastShownCompletion >= lastCompletions.size()) { lastShownCompletion = 0; } else if (lastShownCompletion < 0) { lastShownCompletion = lastCompletions.size() - 1; } String sno = lastCompletions.get(lastShownCompletion); toSetIn = sno.substring(lastBeginning.length() - 1); StringBuilder alltext = new StringBuilder(comp.getText()); int oldSelectionStart = comp.getSelectionStart(); int oldSelectionEnd = comp.getSelectionEnd(); // replace prefix with new prefix int startPos = comp.getSelectionStart() - lastBeginning.length(); alltext.delete(startPos, oldSelectionStart); alltext.insert(startPos, sno.subSequence(0, lastBeginning.length())); // replace suffix with new suffix alltext.delete(oldSelectionStart, oldSelectionEnd); //int cp = oldSelectionEnd - deletedChars; alltext.insert(oldSelectionStart, toSetIn.substring(1)); LOGGER.debug(alltext.toString()); comp.setText(alltext.toString()); //comp.setCaretPosition(cp+toSetIn.length()-1); comp.select(oldSelectionStart, (oldSelectionStart + toSetIn.length()) - 1); lastCaretPosition = comp.getCaretPosition(); LOGGER.debug("ToSetIn: '" + toSetIn + "'"); }
From source file:de.acosix.alfresco.mtsupport.repo.subsystems.TenantAwareSubsystemPlaceholderConfigurer.java
/** * {@inheritDoc}/*from www. java 2s . c o m*/ */ @Override protected String resolvePlaceholder(final String placeholder, final Properties props, final int systemPropertiesMode) { String resolved = null; if (TenantBeanUtils.TENANT_PLACEHOLDER.equals(placeholder)) { resolved = TENANT_CONTEXT.get(); } // placeholder contains the expected placeholder, perform resolution for tenant-specific and generic default variant of placeholder else if (TENANT_CONTEXT.get() != null && placeholder.contains(TenantBeanUtils.TENANT_PLACEHOLDER_IN_PLACEHOLDER)) { final String tenantDomain = TENANT_CONTEXT.get(); LOGGER.debug("[{}] Processing placeholder {} for tenant domain", this.beanName, placeholder, tenantDomain); final StringBuilder tenantReplacementBuilder = new StringBuilder(); tenantReplacementBuilder.append("."); tenantReplacementBuilder.append(tenantDomain); tenantReplacementBuilder.append("."); final String placeholderWithSpecificTenant = placeholder.replace( TenantBeanUtils.TENANT_PLACEHOLDER_IN_PLACEHOLDER, tenantReplacementBuilder.toString()); resolved = super.resolvePlaceholder(placeholderWithSpecificTenant, props, systemPropertiesMode); if (resolved == null) { tenantReplacementBuilder.delete(1, tenantReplacementBuilder.length()); final String placeholderForDefaultProperty = placeholder.replace( TenantBeanUtils.TENANT_PLACEHOLDER_IN_PLACEHOLDER, tenantReplacementBuilder.toString()); resolved = super.resolvePlaceholder(placeholderForDefaultProperty, props, systemPropertiesMode); if (resolved != null) { LOGGER.debug("[{}] Placeholder {} resolved to value {} from default configuration", this.beanName, placeholder, resolved); } else { LOGGER.debug( "[{}] Placeholder {} could not be resolved against tenant or default configuration", this.beanName, placeholder); } } else { LOGGER.debug("[{}] Placeholder {} resolved specific value {} from tenant configuration", this.beanName, placeholder, resolved); } } // fall back if (resolved == null) { resolved = super.resolvePlaceholder(placeholder, props, systemPropertiesMode); } return resolved; }
From source file:org.aludratest.testcase.data.impl.xml.XmlBasedTestDataProvider.java
private InputStream tryFindXml(String uri, Method testMethod) throws IOException, AutomationException, URISyntaxException { if (uri.matches("[a-z]+://.*")) { URI realUri = new URI(uri); URL url = realUri.toURL(); return url.openStream(); }/* w w w.ja v a 2s.c om*/ // first search try: full path, as used for Excels StringBuilder sbPath = new StringBuilder(); sbPath.append(aludraConfig.getXlsRootPath()); if (sbPath.toString().endsWith(File.separator)) { sbPath.delete(sbPath.length() - 1, sbPath.length()); } sbPath.append(File.separator); sbPath.append(testMethod.getDeclaringClass().getName().replace(".", File.separator)); sbPath.append(File.separator); sbPath.append(uri); File f = new File(sbPath.toString()); if (f.isFile()) { return new FileInputStream(f); } // second try: directly under root path sbPath = new StringBuilder(); sbPath.append(aludraConfig.getXlsRootPath()); if (sbPath.toString().endsWith(File.separator)) { sbPath.delete(sbPath.length() - 1, sbPath.length()); } sbPath.append(File.separator); sbPath.append(uri); f = new File(sbPath.toString()); if (f.isFile()) { return new FileInputStream(f); } throw new AutomationException("Could not find test data XML file " + uri); }
From source file:chat.viska.xmpp.NettyTcpSession.java
private Document preprocessInboundXml(final String xml) throws SAXException { final StringBuilder builder = new StringBuilder(xml); final String openingPrefixBlock = '<' + serverStreamPrefix + ':'; final String closingPrefixBlock = "</" + serverStreamPrefix + ':'; final int openingPrefixBlockIdx = builder.indexOf(openingPrefixBlock); final int firstXmlnsIdx = builder.indexOf(" xmlns=") + 1; if (openingPrefixBlockIdx == 0) { // Remove <stream: prefix and add namespace block builder.delete(1, 1 + serverStreamPrefix.length() + 1); final int closingPrefixBlockIdx = builder.indexOf(closingPrefixBlock); builder.delete(closingPrefixBlockIdx + 2, closingPrefixBlockIdx + 2 + serverStreamPrefix.length() + 1); builder.insert(builder.indexOf(">"), String.format(" xmlns=\"%1s\"", CommonXmlns.STREAM_HEADER)); } else if (firstXmlnsIdx < 0 || firstXmlnsIdx > builder.indexOf(">")) { // No xmlns for the root, which means a stanza builder.insert(builder.indexOf(">"), String.format(" xmlns=\"%1s\"", CommonXmlns.STANZA_CLIENT)); }/* w w w.j a v a 2 s . com*/ return DomUtils.readDocument(builder.toString()); }
From source file:it.crs4.seal.demux.Demux.java
private void createLaneContentFiles(Path outputPath, Path sampleSheetPath) throws IOException { StringBuilder builder = new StringBuilder(100); try {//www . ja v a 2s. c o m Path qualifiedPath = sampleSheetPath.makeQualified(sampleSheetPath.getFileSystem(getConf())); SampleSheet sheet = DemuxUtils.loadSampleSheet(qualifiedPath, getConf()); Collection<String> samples = sheet.getSamples(); // we have one output directory per sample, thus we need one LaneContent file per sample. for (String sample : samples) { Writer out = makeLaneContentWriter(outputPath, sample); try { for (int lane = 1; lane <= 8; ++lane) { builder.delete(0, builder.length()); builder.append(lane - 1).append(":"); if (sheet.getSamplesInLane(lane).contains(sample)) builder.append(sample); builder.append("\n"); out.write(builder.toString()); } } finally { out.close(); } } } catch (SampleSheet.FormatException e) { throw new RuntimeException("Error in sample sheet. " + e.getMessage()); } }
From source file:de.minestar.contao2.manager.PlayerManager.java
public void updateOnlineLists() { StringBuilder sBuilder = new StringBuilder(); Player player;/*from w ww. ja va 2s . c o m*/ for (Map.Entry<ContaoGroup, HashSet<String>> entry : this.groupMap.entrySet()) { sBuilder.setLength(0); for (String thisPlayer : entry.getValue()) { player = Bukkit.getPlayer(thisPlayer); if (player != null && player.isOnline()) { sBuilder.append(thisPlayer); sBuilder.append(", "); } } if (sBuilder.length() > 2) sBuilder.delete(sBuilder.length() - 2, sBuilder.length()); this.onlineList.put(entry.getKey(), sBuilder.toString()); } this.saveJSON(); }