List of usage examples for org.apache.commons.lang3 StringUtils removeEnd
public static String removeEnd(final String str, final String remove)
Removes a substring only if it is at the end of a source string, otherwise returns the source string.
A null source string will return null .
From source file:jclparser.NewClass.java
public static File analyze(File f) { String procedure = StringUtils.substringBeforeLast(f.getName(), "."); if (f.exists()) { f.delete();/* ww w .ja v a2s . c o m*/ } System.out.println("gepeto args2 = " + procedure); String tmp; PROC proc = parse(PROC.class, "SYS1.VIDA.PROCLIB", procedure); List<STEP> steps = proc.getListSTEP(); List<String> nodes = new ArrayList<>(); List<String> fromsTos = new ArrayList<>(); String nodeTemplate = "{\"key\": \"%s\", \"category\": \"program\", \"color\": \"lightblue\", \"label\": \"%s\", \"num\": \"%s\", \"card\": \"%s\"},"; String dsnTemplate = "{\"key\": \"%s\", \"color\": \"magenta\", \"label\": \"%s\"},"; String fromToTemplate = "{\"from\": \"%s\", \"to\": \"%s\"},"; Map<String, Integer> programs = new HashMap<>(); Set<String> files = new HashSet<>(); for (STEP step : steps) { String pgm = step.getProgram().getName(); String xxx = ""; CARD card = step.getProgram().getCard(); if (card != null) { if (card instanceof CARD_IKJEFT01) { pgm = ((CARD_IKJEFT01) card).getProgram(); } xxx = step.getProgram().getCard().toString(); System.out.println("VVV " + step.getProgram().getCard().toString()); // if (card instanceof CARD_SORT) { // pgm = ((CARD_SORT) card).getProgram(); // } } Integer num = programs.get(pgm); num = num == null ? 1 : num + 1; programs.put(pgm, num); if (num > 1) { pgm = pgm + " (" + num + ")"; } String t = String.format(nodeTemplate, pgm, "XXX", "XXX", xxx); nodes.add(t); List<DSN> dsns = step.getListDSN(); for (DSN dsn : dsns) { if (dsn.getName().trim().isEmpty()) { continue; } if (files.add(dsn.getName())) { String u = String.format(dsnTemplate, dsn.getName(), dsn.getLabel()); files.add(nodeTemplate); nodes.add(u); } String from = dsn.getMode().equals("INPUT") ? dsn.getName() : pgm; String to = !dsn.getMode().equals("INPUT") ? dsn.getName() : pgm; tmp = String.format(fromToTemplate, from, to); if (!pgm.equalsIgnoreCase("COPIADOR")) { fromsTos.add(tmp); } System.out.println("Label: " + StringUtils.rightPad(dsn.getLabel(), 8) + " Dsn: " + dsn.getName() + " Type: " + dsn.getType() + " Mode: " + dsn.getMode()); } } String lastNode = nodes.remove(nodes.size() - 1); lastNode = StringUtils.removeEnd(lastNode, ","); nodes.add(lastNode); String lastFromsTos = fromsTos.remove(fromsTos.size() - 1); lastFromsTos = StringUtils.removeEnd(lastFromsTos, ","); fromsTos.add(lastFromsTos); try { FileUtils.writeStringToFile(f, "{\"class\": \"go.GraphLinksModel\",\"nodeDataArray\": [", true); FileUtils.writeLines(f, nodes, true); FileUtils.writeStringToFile(f, "],", true); FileUtils.writeStringToFile(f, "\"linkDataArray\": [", true); FileUtils.writeLines(f, fromsTos, true); FileUtils.writeStringToFile(f, "]}", true); } catch (IOException ex) { Logger.getLogger(NewClass.class.getName()).log(Level.SEVERE, null, ex); } System.out.println("directoru " + f.getAbsolutePath()); // for (String node : nodes) { // System.out.println(node + ","); // } // // for (String fromTo : fromsTos) { // System.out.println(fromTo + ","); // } return f; }
From source file:ca.on.oicr.pde.workflows.GATKGenotypeGVCFsWorkflow.java
@Override public Map<String, SqwFile> setupFiles() { List<String> inputFilesList = Arrays.asList(StringUtils.split(getProperty("input_files"), ",")); Set<String> inputFilesSet = new HashSet<>(inputFilesList); if (inputFilesList.size() != inputFilesSet.size()) { throw new RuntimeException("Duplicate files detected in input_files"); }/* ww w.java 2 s .co m*/ if ((inputFilesSet.size() % 2) != 0) { throw new RuntimeException("Each GVCF should have a corresponding index"); } Map<String, String> gvcfs = new HashMap<>(); Map<String, String> gvcfIndexes = new HashMap<>(); for (String f : inputFilesSet) { if (f == null || f.isEmpty()) { } else if (f.endsWith("g.vcf.gz")) { gvcfs.put(StringUtils.removeEnd(f, "g.vcf.gz"), f); } else if (f.endsWith("g.vcf.gz.tbi")) { gvcfIndexes.put(StringUtils.removeEnd(f, "g.vcf.gz.tbi"), f); } else { throw new RuntimeException("Unsupported input file: [" + f + "]"); } } int id = 0; for (Entry<String, String> e : gvcfs.entrySet()) { String key = e.getKey(); String gvcfFilePath = e.getValue(); String gvcfIndexFilePath = gvcfIndexes.get(key); if (gvcfIndexFilePath == null) { throw new RuntimeException("Missing index for " + FilenameUtils.getName(gvcfFilePath)); } SqwFile gvcf = this.createFile("file_in_" + id++); gvcf.setSourcePath(gvcfFilePath); gvcf.setType("application/g-vcf-gz"); gvcf.setIsInput(true); SqwFile gvcfIndex = this.createFile("file_in_" + id++); gvcfIndex.setSourcePath(gvcfIndexFilePath); gvcfIndex.setType("application/tbi"); gvcfIndex.setIsInput(true); //FIXME: this seems to work for now, it would be better to be able to set the provisionedPath as //bai.getProvisionedPath != bai.getOutputPath ... //at least with seqware 1.1.0, setting output path changes where the output file will be stored, //but the commonly used get provisioned path will return the incorrect path to the file gvcfIndex.setOutputPath(FilenameUtils.getPath(gvcf.getProvisionedPath())); inputFiles.add(gvcf.getProvisionedPath()); } return this.getFiles(); }
From source file:com.monarchapis.driver.jaxrs.common.Swagger12DocumentationResource.java
/** * Returns the base URI from the <code>UriInfo</code>. * //w ww . ja v a2 s .c o m * @param uriInfo * The URI info for determining the base URI * @return the base URI. */ private static String getBaseUri(UriInfo uriInfo) { return StringUtils.removeEnd(uriInfo.getBaseUri().toString(), "/"); }
From source file:com.github.ferstl.depgraph.graph.puml.PumlGraphFormatter.java
private String escape(String id) { return StringUtils.removeEnd(id.replaceAll("\\W", "_"), "_"); }
From source file:mbenson.annotationprocessing.CodeModelProcessorBase.java
@Override public final boolean process(final Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { JCodeModel codeModel = new JCodeModel(); boolean result = false; try {//from w ww .j av a 2 s.co m result = processTo(codeModel, annotations, roundEnv); } catch (Throwable t) { error(t, "Error creating code model"); } if (result) { try { final CodeWriter codeWriter = new CodeWriter() { @Override public OutputStream openBinary(JPackage pkg, String fileName) throws IOException { JavaFileObject sourceFile = processingEnv.getFiler().createSourceFile( StringUtils.join(pkg.name(), ".", StringUtils.removeEnd(fileName, JAVA_FILE_EXTENSION)), annotations.toArray(new TypeElement[annotations.size()])); return sourceFile.openOutputStream(); } @Override public void close() throws IOException { } }; codeModel.build( new PrologCodeWriter(codeWriter, String.format("generated by %s\n", getClass().getName()))); } catch (IOException e) { error(e, "Error generating code"); } } return result; }
From source file:in.mycp.workers.ImageWorker.java
@Async public void createImage(final Infra infra, final ImageDescriptionP image) { String threadName = Thread.currentThread().getName(); try {//from w w w . ja v a 2 s . co m logger.debug("threadName " + threadName + " started."); Jec2 ec2 = getNewJce2(infra); String imageId = ""; try { imageId = ec2.createImage(image.getInstanceIdForImgCreation(), image.getName(), image.getDescription(), false); } catch (Exception e) { logger.error(e.getMessage());//e.printStackTrace(); } ImageDescription imageFromEuca = ec2.describeImages(Collections.singletonList(imageId)).get(0); String imageState = imageFromEuca.getImageState(); int START_SLEEP_TIME = 10000; while (!"available".equals(imageState)) { imageFromEuca = ec2.describeImages(Collections.singletonList(imageId)).get(0); imageState = imageFromEuca.getImageState(); logger.info("Image " + imageFromEuca.getImageId() + " still getting created; sleeping " + START_SLEEP_TIME + "ms"); Thread.sleep(START_SLEEP_TIME); } if ("available".equals(imageState)) { image.setImageId(imageFromEuca.getImageId()); image.setImageLocation(imageFromEuca.getImageLocation()); image.setImageOwnerId(imageFromEuca.getImageOwnerId()); image.setImageState(imageFromEuca.getImageState()); image.setIsPublic(imageFromEuca.isPublic()); List<String> prodCodes = imageFromEuca.getProductCodes(); String prodCodes_str = ""; for (Iterator iterator = prodCodes.iterator(); iterator.hasNext();) { String prodCode = (String) iterator.next(); prodCodes_str = prodCodes_str + prodCode + ","; } prodCodes_str = StringUtils.removeEnd(prodCodes_str, ","); image.setProductCodes(prodCodes_str); image.setArchitecture(imageFromEuca.getArchitecture()); image.setImageType(imageFromEuca.getImageType()); image.setKernelId(imageFromEuca.getKernelId()); image.setRamdiskId(imageFromEuca.getRamdiskId()); image.setPlatform(imageFromEuca.getPlatform()); image.setReason(imageFromEuca.getReason()); image.setImageOwnerAlias(imageFromEuca.getImageOwnerAlias()); image.setName(imageFromEuca.getName()); image.setDescription(imageFromEuca.getDescription()); image.setRootDeviceType(imageFromEuca.getRootDeviceType()); image.setRootDeviceName(imageFromEuca.getRootDeviceName()); image.setVirtualizationType(imageFromEuca.getVirtualizationType()); image.merge(); } } catch (Exception e) { logger.error(e.getMessage());//e.printStackTrace(); } }
From source file:com.xpn.xwiki.internal.filter.output.PropertyClassOutputFilterStream.java
@Override public void beginWikiClassProperty(String name, String type, FilterEventParameters parameters) throws FilterException { if (this.enabled) { ComponentManager componentManager = this.componentManagerProvider.get(); this.currentClassPropertyMeta = null; PropertyClassProvider provider;/*from w ww . j a va2s.c o m*/ // First try to use the specified class type as hint. try { if (componentManager.hasComponent(PropertyClassProvider.class, type)) { provider = componentManager.getInstance(PropertyClassProvider.class, type); } else { // In previous versions the class type was the full Java class name of the property class // implementation. Extract the hint by removing the Java package prefix and the Class suffix. String classType = StringUtils.removeEnd(StringUtils.substringAfterLast(type, "."), "Class"); if (componentManager.hasComponent(PropertyClassProvider.class, classType)) { provider = componentManager.getInstance(PropertyClassProvider.class, classType); } else { this.logger.warn("Unknown property type [{}]", type); return; } } } catch (ComponentLookupException e) { throw new FilterException( String.format("Failed to get instance of the property class provider for type [%s]", type), e); } this.currentClassPropertyMeta = provider.getDefinition(); if (this.entity == null) { // We should use PropertyClassInterface (instead of PropertyClass, its default implementation) but it // doesn't have the set methods and adding them would breaks the backwards compatibility. We make the // assumption that all property classes extend PropertyClass. this.entity = (PropertyClass) provider.getInstance(); } this.entity.setName(name); this.entity.setObject(this.currentXClass); } }
From source file:com.netflix.genie.web.controllers.ControllerUtils.java
/** * Given a HTTP {@code request} and a {@code path} this method will return the root of the request minus the path. * Generally the path will be derived from {@link #getRemainingPath(HttpServletRequest)} and this method will be * called subsequently./*from w ww . j a v a 2s . c om*/ * <p> * If the request URL is {@code https://myhost/api/v3/jobs/12345/output/genie/run?myparam=4#BLAH} and the path is * {@code genie/run} this method should return {@code https://myhost/api/v3/jobs/12345/output/}. * <p> * All query parameters and references will be stripped off. * * @param request The HTTP request to get information from * @param path The path that should be removed from the end of the request URL * @return The base of the request * @throws MalformedURLException If we're unable to create a new valid URL after removing the path * @since 4.0.0 */ static URL getRequestRoot(final URL request, @Nullable final String path) throws MalformedURLException { final String currentPath = request.getPath(); final String newPath = StringUtils.removeEnd(currentPath, path); return new URL(request.getProtocol(), request.getHost(), request.getPort(), newPath); }
From source file:io.wcm.handler.link.Link.java
/** * @return Link markup (only the opening anchor tag) or null if resolving was not successful. *//*from ww w . j a va2s . c o m*/ public String getMarkup() { if (this.anchor != null) { return StringUtils.removeEnd(this.anchor.toString(), "</a>"); } else { return null; } }
From source file:io.wcm.wcm.ui.extjs.provider.impl.servlets.TemplateFilterPageTreeProvider.java
/** * Get paths for pages that use the given template * * @param templates//from w w w. j a v a 2 s . c o m * @param rootPath * @return a set of nodes that should be displayed in the tree */ private Set<String> getPagePathsForTemplate(String[] templates, String rootPath, SlingHttpServletRequest request) { Set<String> pagePaths = new HashSet<>(); if (templates != null && templates.length > 0) { try { NodeIterator nodes = searchNodesByTemplate(templates, rootPath, request); while (nodes.hasNext()) { Node node = nodes.nextNode(); String path = StringUtils.removeEnd(node.getPath(), "/jcr:content"); pagePaths.add(path); } } catch (RepositoryException ex) { log.warn("Seaching nodes by template failed.", ex); } } return pagePaths; }