List of usage examples for org.apache.commons.lang StringUtils repeat
public static String repeat(String str, int repeat)
Repeat a String repeat
times to form a new String.
From source file:com.archivas.clienttools.arcmover.cli.ManagedCLIJob.java
/** * Entry point for generating a directory listing. *///from w ww. j ava2s . co m public void execute(PrintWriter out, PrintWriter err) throws Exception { // We have to at least have a job and a source profile if (managedJob == null || managedJob.getSourceProfile() == null) { throw new ParseException("Job not created during parsing of the commandline"); } // Let's make sure we can access the two profiles try { testConnection(managedJob.getSourceProfile()); testConnection(managedJob.getTargetProfile()); } catch (Exception e) { try { arcMover.removeManagedJob(managedJobImpl.getJobId(), managedJob.getJobType()); } catch (Exception ex) { LOG.log(Level.WARNING, "An error occurred removing job " + managedJobImpl.getJob().getJobName() + ": " + ex.getMessage(), ex); } finally { managedJobImpl = null; throw e; } } if (managedJob.getJobType() == ManagedJob.Type.COPY && managedJob.getSourceProfile().getType() .isLesserApiVersion(managedJob.getTargetProfile().getType())) { out.println(StringUtils.repeat("*", 80)); out.println("Copying objects to an earlier release of HCP results in loss of metadata that is"); out.println("not supported by the earlier release."); out.println(StringUtils.repeat("*", 80)); out.println(); } ManagedJobStats jobStats; arcMover.startManagedJob(managedJobImpl); // If we are rerunning the job there could be a small window where // arcMover.getStatus(managedJobImpl).isFinished() // is true. If that is the case sleep for a second and then continue if (managedJobImpl.getStatus().isFinished()) { try { Thread.sleep(1000); } catch (InterruptedException e) { /* Ignore it */ } } while (!managedJobImpl.getStatus().isFinished()) { jobStats = arcMover.getManagedJobStats(managedJobImpl); out.print(buildProgressString(jobStats)); out.flush(); LOG.fine("Job Stats : " + jobStats); try { Thread.sleep(1000); } catch (InterruptedException e) { // do nothing } } jobStats = arcMover.getManagedJobStats(managedJobImpl); out.print(buildProgressString(jobStats)); LOG.fine("Job Stats : " + jobStats); String details = generateDetails(arcMover.getManagedJobDetails(managedJobImpl, true)); String summary = generateSummary(arcMover.getManagedJobStats(managedJobImpl), managedJob.getJobType()); LOG.fine(details); LOG.info(summary); out.println(summary); // Export results synchronously if (exportResults.shouldExportResults()) { out.println("Exporting results"); exportResults.exportResults(); } // Set the error code if we have failures if (jobStats.areErrors()) { setExitCode(EXIT_CODE_DM_FAILED_FILES); } // Delete the job if it completed and we have no failed files if (jobStats.getStatus().equals(JobStatus.COMPLETED) && !jobStats.areErrors()) { try { arcMover.removeManagedJob(jobStats.getJobId(), managedJob.getJobType()); } catch (Exception e) { LOG.log(Level.WARNING, "An error occurred removing job " + managedJobImpl.getJob().getJobName() + ": " + e.getMessage(), e); } finally { managedJobImpl = null; } } // Flush the CLI out.flush(); err.flush(); }
From source file:com.qcadoo.model.integration.FieldModuleIntegrationTest.java
License:asdf
@Test public void shouldCallAndFailDefaultPasswordFieldValidators() throws Exception { // given// w ww . j ava2 s .c o m String textValue = StringUtils.repeat("a", 256); // when & then performFieldValidationTestOnPart("discountCode", textValue, false); }
From source file:com.qcadoo.model.integration.FieldModuleIntegrationTest.java
License:asdf
@Test public void shouldCallAndPassPasswordFieldMaxLenValidators() throws Exception { // given/*from w w w.jav a 2 s . c o m*/ String textValue = StringUtils.repeat("a", 512); // when & then performFieldValidationTestOnPart("longDiscountCode", textValue, true); }
From source file:com.livinglogic.ul4.FunctionFormat.java
private static String formatIntegerString(String string, boolean neg, IntegerFormat format) { if (format.align == '=') { int minimumwidth = format.minimumwidth; if (neg || format.sign != '-') --minimumwidth;//from w ww . ja va 2 s.co m if (format.alternate && (format.type == 'b' || format.type == 'o' || format.type == 'x' || format.type == 'X')) minimumwidth -= 2; if (string.length() < minimumwidth) string = StringUtils.repeat(Character.toString(format.fill), minimumwidth - string.length()) + string; if (format.alternate && (format.type == 'b' || format.type == 'o' || format.type == 'x' || format.type == 'X')) string = "0" + Character.toString(format.type) + string; if (neg) string = "-" + string; else { if (format.sign != '-') string = Character.toString(format.sign) + string; } return string; } else { if (format.alternate && (format.type == 'b' || format.type == 'o' || format.type == 'x' || format.type == 'X')) string = "0" + Character.toString(format.type) + string; if (neg) string = "-" + string; else { if (format.sign != '-') string = Character.toString(format.sign) + string; } if (string.length() < format.minimumwidth) { if (format.align == '<') string = string + StringUtils.repeat(Character.toString(format.fill), format.minimumwidth - string.length()); else if (format.align == '>') string = StringUtils.repeat(Character.toString(format.fill), format.minimumwidth - string.length()) + string; else // if (format.align == '^') { int pad = format.minimumwidth - string.length(); int padBefore = pad / 2; int padAfter = pad - padBefore; string = StringUtils.repeat(Character.toString(format.fill), padBefore) + string + StringUtils.repeat(Character.toString(format.fill), padAfter); } } return string; } }
From source file:com.qcadoo.model.integration.FieldModuleIntegrationTest.java
License:asdf
@Test public void shouldCallAndFailPasswordFieldMaxLenValidators() throws Exception { // given/*from w w w . j a v a 2 s .c o m*/ String textValue = StringUtils.repeat("a", 513); // when & then performFieldValidationTestOnPart("longDiscountCode", textValue, false); }
From source file:de.codesourcery.jasm16.utils.Misc.java
public static String toPrettyString(String errorMessage, int errorOffset, ITextRegion location, IScanner input) {//from ww w .j ava 2s . com int oldOffset = input.currentParseIndex(); try { input.setCurrentParseIndex(errorOffset); } catch (IllegalArgumentException e) { return "ERROR at offset " + errorOffset + ": " + errorMessage; } try { StringBuilder context = new StringBuilder(); while (!input.eof() && input.peek() != '\n') { context.append(input.read()); } final String loc; if (location instanceof SourceLocation) { final SourceLocation srcLoc = (SourceLocation) location; loc = "Line " + srcLoc.getLineNumber() + ",column " + srcLoc.getColumnNumber() + " (" + srcLoc.getOffset() + "): "; } else { loc = "index " + errorOffset + ": "; } final String line1 = loc + context.toString(); final String indent = StringUtils.repeat(" ", loc.length()); final String line2 = indent + "^ " + errorMessage; return line1 + "\n" + line2; } finally { try { input.setCurrentParseIndex(oldOffset); } catch (Exception e2) { /* swallow */ } } }
From source file:msi.gama.util.GAML.java
public static String getDocumentationOn2(final String query) { final String keyword = StringUtils.removeEnd(StringUtils.removeStart(query.trim(), "#"), ":"); final THashMap<String, String> results = new THashMap<>(); // Statements final SymbolProto p = DescriptionFactory.getStatementProto(keyword); if (p != null) { results.put("Statement", p.getDocumentation()); }/* w w w .ja v a 2 s .c o m*/ DescriptionFactory.visitStatementProtos((name, proto) -> { if (proto.getFacet(keyword) != null) { results.put("Facet of statement " + name, proto.getFacet(keyword).getDocumentation()); } }); final Set<String> types = new HashSet<>(); final String[] facetDoc = { "" }; DescriptionFactory.visitVarProtos((name, proto) -> { if (proto.getFacet(keyword) != null && types.size() < 4) { if (!Types.get(name).isAgentType() || name.equals(IKeyword.AGENT)) { types.add(name); } facetDoc[0] = proto.getFacet(keyword).getDocumentation(); } }); if (!types.isEmpty()) { results.put("Facet of attribute declarations with types " + types + (types.size() == 4 ? " ..." : ""), facetDoc[0]); } // Operators final THashMap<Signature, OperatorProto> ops = IExpressionCompiler.OPERATORS.get(keyword); if (ops != null) { ops.forEachEntry((sig, proto) -> { results.put("Operator on " + sig.toString(), proto.getDocumentation()); return true; }); } // Built-in skills final SkillDescription sd = GamaSkillRegistry.INSTANCE.get(keyword); if (sd != null) { results.put("Skill", sd.getDocumentation()); } GamaSkillRegistry.INSTANCE.visitSkills(desc -> { final SkillDescription sd1 = (SkillDescription) desc; final VariableDescription var = sd1.getAttribute(keyword); if (var != null) { results.put("Attribute of skill " + desc.getName(), var.getDocumentation()); } final ActionDescription action = sd1.getAction(keyword); if (action != null) { results.put("Primitive of skill " + desc.getName(), action.getDocumentation().isEmpty() ? "" : ":" + action.getDocumentation()); } return true; }); // Types final IType<?> t = Types.builtInTypes.containsType(keyword) ? Types.get(keyword) : null; if (t != null) { String tt = t.getDocumentation(); if (tt == null) { tt = "type " + keyword; } results.put("Type", tt); } // Built-in species for (final TypeDescription td : Types.getBuiltInSpecies()) { if (td.getName().equals(keyword)) { results.put("Built-in species", ((SpeciesDescription) td).getDocumentationWithoutMeta()); } final IDescription var = td.getOwnAttribute(keyword); if (var != null) { results.put("Attribute of built-in species " + td.getName(), var.getDocumentation()); } final ActionDescription action = td.getOwnAction(keyword); if (action != null) { results.put("Primitive of built-in species " + td.getName(), action.getDocumentation().isEmpty() ? "" : ":" + action.getDocumentation()); } } // Constants final UnitConstantExpression exp = IUnits.UNITS_EXPR.get(keyword); if (exp != null) { results.put("Constant", exp.getDocumentation()); } if (results.isEmpty()) { return "No result found"; } final StringBuilder sb = new StringBuilder(); final int max = results.keySet().stream().mapToInt(each -> each.length()).max().getAsInt(); final String separator = StringUtils.repeat("", max + 6).concat(Strings.LN); results.forEachEntry((sig, doc) -> { sb.append("").append(separator).append("|| "); sb.append(StringUtils.rightPad(sig, max)); sb.append(" ||").append(Strings.LN).append(separator); sb.append(toText(doc)).append(Strings.LN); return true; }); return sb.toString(); // }
From source file:eu.annocultor.converters.time.OntologyToHtmlGenerator.java
public void printBranch(Node node, List<String> os) { if (!StringUtils.isBlank(node.text)) { String prefix = StringUtils.repeat(" ", node.level); String classExpanded = expanded.contains(node.url) ? " class=\"expanded\"" : ""; os.add(prefix + "<li" + classExpanded + ">" + node.text); if (!node.children.isEmpty()) { if (node.children.size() > 1) { os.add(prefix + "<ul>"); }//from ww w.j a v a 2 s . co m for (Node child : node.children) { printBranch(child, os); } if (node.children.size() > 1) { os.add(prefix + "</ul>"); } } os.add(prefix + "</li>"); } }
From source file:ca.nengo.model.impl.ProjectionImpl.java
public String toScript(HashMap<String, Object> scriptData) throws ScriptGenException { StringBuilder py = new StringBuilder(); String pythonNetworkName = scriptData.get("prefix") + getNetwork().getName() .replaceAll("\\p{Blank}|\\p{Punct}", ((Character) scriptData.get("spaceDelim")).toString()); py.append(String.format("%1s.connect(", pythonNetworkName)); StringBuilder originNodeFullName = new StringBuilder(); Origin tempOrigin = myOrigin;//from www. ja v a2s .c o m while (tempOrigin instanceof OriginWrapper) { originNodeFullName.append(tempOrigin.getNode().getName() + "."); tempOrigin = ((OriginWrapper) tempOrigin).getWrappedOrigin(); } originNodeFullName.append(tempOrigin.getNode().getName()); py.append("\'" + originNodeFullName + "\'"); StringBuilder terminationNodeFullName = new StringBuilder(); Termination tempTermination = myTermination; while (tempTermination instanceof TerminationWrapper) { terminationNodeFullName.append(tempTermination.getNode().getName() + "."); tempTermination = ((TerminationWrapper) tempTermination).getWrappedTermination(); } terminationNodeFullName.append(tempTermination.getNode().getName()); py.append(", \'" + terminationNodeFullName + "\'"); DecodedTermination dTermination; StringBuilder transformString = new StringBuilder(); transformString.append('['); if (tempTermination instanceof DecodedTermination) { dTermination = (DecodedTermination) tempTermination; transformString.append(getTransformScript(dTermination, "transform = ".length())); } else if (tempTermination instanceof EnsembleTermination && tempTermination.getNode().getClass() .getCanonicalName() == "org.python.proxies.nef.array$NetworkArray$6") { boolean first = true; for (Node node : tempTermination.getNode().getChildren()) { if (first) { first = false; } else { transformString.append(",\n" + StringUtils.repeat(" ", "transform = ".length() + 1)); } // this relies on the decoded terminations in the child nodes having the // same name as the ensemble termination that contains them try { dTermination = (DecodedTermination) node.getTermination(tempTermination.getName()); } catch (Exception e) { dTermination = null; } transformString.append(getTransformScript(dTermination, "transform = ".length() + 1)); } } else { throw new ScriptGenException( "Trying to generate script of non decoded termination which is not supported."); } transformString.append("]\n"); py.insert(0, "transform = " + transformString.toString()); py.append(", transform=transform"); // Now handle origin function if there is one if (!(tempOrigin.getNode() instanceof FunctionInput)) { DecodedOrigin dOrigin; if (tempOrigin instanceof DecodedOrigin) { dOrigin = (DecodedOrigin) tempOrigin; } else if (tempOrigin.getClass().getCanonicalName() == "org.python.proxies.nef.array$ArrayOrigin$5" && tempOrigin.getNode().getClass() .getCanonicalName() == "org.python.proxies.nef.array$NetworkArray$6") { Node node = tempOrigin.getNode().getChildren()[0]; try { dOrigin = (DecodedOrigin) node.getOrigin(tempOrigin.getName()); } catch (StructuralException e) { dOrigin = null; } } else { throw new ScriptGenException( "Trying to generate script of non decoded origin which is not supported."); } String funcString = getFunctionScript(dOrigin); if (!funcString.isEmpty()) { py.insert(0, " return [" + funcString + "]\n\n"); py.insert(0, "def function(x):\n"); py.append(", func=function"); } } py.append(")\n\n"); return py.toString(); }
From source file:de.codesourcery.jasm16.ast.ASTUtils.java
public static void debugPrintTextRegions(ASTNode node, final String source, final ICompilationUnit unit) { ASTUtils.visitInOrder(node, new ISimpleASTNodeVisitor<ASTNode>() { @Override//w w w . j ava2 s . c o m public boolean visit(ASTNode node) { ITextRegion region = node.getTextRegion(); if (region != null) { int len = region.getEndOffset() - region.getStartingOffset() - 1; if (len < 0) { len = 0; } String regionString = StringUtils.repeat(" ", region.getStartingOffset()) + "^" + StringUtils.repeat(" ", len) + "^"; String bodyText = null; try { region.apply(source).replace("\n", "|").replace("\r", "|"); bodyText = source.replace("\n", "|").replace("\r", "|"); bodyText += "\n" + regionString; } catch (Exception e) { bodyText = "<Invalid region>"; } String loc = ""; if (unit != null) { SourceLocation sourceLocation = unit.getSourceLocation(region); if (sourceLocation != null) { loc = "[ " + sourceLocation.toString() + " ]"; } } System.out.print("\n-----\nAST Node " + node.getClass().getSimpleName() + " convers range " + region + " " + loc + "\n---\n" + bodyText); } else { System.err.print( "\n-----\nAST Node " + node.getClass().getSimpleName() + " has no text region set"); } return true; } }); }