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.aliyun.odps.tunnel.InstanceTunnelTest.java
@Test public void testPositive4() throws OdpsException, IOException { //big data table TableSchema schema = new TableSchema(); schema.addColumn(new Column("id", OdpsType.STRING)); odps.tables().delete("instance_tunnel_big", true); odps.tables().create("instance_tunnel_big", schema); TableTunnel tunnel = OdpsTestUtils.newTableTunnel(odps); TableTunnel.UploadSession uploadSession = tunnel.createUploadSession(odps.getDefaultProject(), "instance_tunnel_big"); RecordWriter writer = uploadSession.openRecordWriter(0); Record r = new ArrayRecord(schema); //2.6MB in string String magicString = StringUtils.repeat("ABCDEFGHIJKLMNOPQRSTUVWXYZ", 100000); r.setString(0, magicString);//from w ww.j a v a 2s.c o m for (int i = 0; i < 20; ++i) { writer.write(r); } writer.close(); uploadSession.commit(new Long[] { 0L }); Instance id = SQLTask.run(odps, "select lower(id) as str from instance_tunnel_big;"); System.err.println(id.getId()); id.waitForSuccess(); for (String st : id.getTaskResults().values()) { System.err.println(st); assertTrue(st.contains("Fetched data is larger than the rendering limitation")); } InstanceTunnel instanceTunnel = OdpsTestUtils.newInstanceTunnel(odps); InstanceTunnel.DownloadSession session = instanceTunnel.createDownloadSession(odps.getDefaultProject(), id.getId()); assertEquals(session.getRecordCount(), 20); assertEquals(session.getSchema().getColumns().size(), 1L); assertEquals(session.getSchema().getColumns().get(0).getName(), "str"); assertEquals(session.getSchema().getColumns().get(0).getType(), OdpsType.STRING); TunnelRecordReader reader = session.openRecordReader(0, session.getRecordCount()); for (int i = 0; i < session.getRecordCount(); ++i) { Record record = reader.read(); assertEquals(record.getString(0), magicString.toLowerCase()); } }
From source file:com.lmco.ddf.commands.catalog.IngestCommand.java
private String getProgressBar(int ingestCount, int totalPossible, long start, long end) { int notches = calculateNotches(ingestCount, totalPossible); int progressPercentage = calculateProgressPercentage(ingestCount, totalPossible); int rate = calculateRecordsPerSecond(ingestCount, start, end); String progressArrow = ">"; // /r is required, it allows for the update in place String progressBarFormat = "%1$4s%% [=%2$-50s] %3$5s records/sec\t\r"; return String.format(progressBarFormat, progressPercentage, StringUtils.repeat("=", notches) + progressArrow, rate); }
From source file:fitnesse.slim.SlimServiceTestBase.java
@Test public void callFunctionWithHugeParameter() throws Exception { addImportAndMake();/*from w w w . j av a 2 s. c o m*/ String hugeString = StringUtils.repeat("x", 999999 + 10); statements.add(new CallInstruction("id", "testSlim", "echoString", new Object[] { hugeString })); Map<String, Object> result = slimClient.invokeAndGetResponse(statements); assertEquals(hugeString, result.get("id")); }
From source file:msi.gama.util.GAML.java
public static String getDocumentationOn(final String query) { final String keyword = StringUtils.removeEnd(StringUtils.removeStart(query.trim(), "#"), ":"); final Multimap<GamlIdiomsProvider<?>, IGamlDescription> results = GamlIdiomsProvider.forName(keyword); if (results.isEmpty()) { return "No result found"; }/* w w w.j av a 2 s.c om*/ final StringBuilder sb = new StringBuilder(); final int max = results.keySet().stream().mapToInt(each -> each.name.length()).max().getAsInt(); final String separator = StringUtils.repeat("", max + 6).concat(Strings.LN); results.asMap().forEach((provider, list) -> { sb.append("").append(separator).append("|| "); sb.append(StringUtils.rightPad(provider.name, max)); sb.append(" ||").append(Strings.LN).append(separator); for (final IGamlDescription d : list) { sb.append("== ").append(toText(d.getTitle())).append(Strings.LN) .append(toText(provider.document(d))).append(Strings.LN); } }); return sb.toString(); // }
From source file:de.codesourcery.jasm16.ast.ASTUtils.java
public static final void printAST(ASTNode n, int depth, String source) { final String indent = StringUtils.repeat(" ", depth * 2); System.out.println(indent + n.toString() + " >" + n.getTextRegion().apply(source) + "<"); for (ASTNode child : n.getChildren()) { printAST(child, depth + 1, source); }/*from w ww.j av a2 s . com*/ }
From source file:com.github.cereda.arara.rulechecker.RuleUtils.java
/** * Prints the report for every rule report. * @param rules The list of rule report. */// w w w.j a va 2 s .com public static void printReport(List<RuleReport> rules) { // print header System.out.println(StringUtils.center(" Task coverage report ", 60, "-").concat("\n")); // let's sort our list of reports according to // each rule coverage Collections.sort(rules, new Comparator<RuleReport>() { @Override public int compare(RuleReport t1, RuleReport t2) { // get values of each rule float a1 = t1.getCoverage(); float a2 = t2.getCoverage(); // they are equal, do nothing if (a1 == a2) { return 0; } else { // we want to sort in reverse order, // so return a negative value here if (a1 > a2) { return -1; } else { // return a positive value, since // the first statement was false return 1; } } } }); // for each report, print // the corresponding entry for (RuleReport rule : rules) { // build the beginning of the line String line = String.format("- %s ", rule.getReference().getName()); // build the coverage information String coverage = String.format(" %2.2f%%", rule.getCoverage()); // generate the line by concatenating // the beginning and coverage line = line.concat(StringUtils.repeat(".", 60 - line.length() - coverage.length())).concat(coverage); // print the line System.out.println(line); } }
From source file:com.qcadoo.model.integration.FieldModuleIntegrationTest.java
License:asdf
@Test public void shouldCallAndFailDefaultMaxStringLenFieldValidators() throws Exception { // given/*from ww w. j a v a 2s .co m*/ final String stringWith300Characters = StringUtils.repeat("a", 300); // when & then Entity savedPart = performFieldValidationTestOnPart("name", stringWith300Characters, false); Assert.assertEquals("qcadooView.validate.field.error.invalidLength", savedPart.getError("name").getMessage()); }
From source file:musite.ui.cmd.CmdLineTools.java
private static String printResult(PredictionResult result) { if (result == null || result.getModels().isEmpty()) { return ""; }/*www .ja va 2 s. c o m*/ StringBuilder sb = new StringBuilder(); sb.append("Position\tAmino Acid\tSurr. Sequence\tScore\tSpecificity\tModel\n"); Iterator<Protein> it = result.proteinIterator(); while (it.hasNext()) { Protein protein = it.next(); String acc = protein.getAccession(); sb.append('>'); sb.append(protein.toString()); sb.append('\n'); for (PredictionModel model : result.getModels()) { Map<Integer, Double> preds = result.getPredictions(model, acc); if (preds == null || preds.isEmpty()) continue; String proteinSeq = protein.getSequence(); int len = proteinSeq.length(); for (Map.Entry<Integer, Double> entry : preds.entrySet()) { int site = entry.getKey(); sb.append(site + 1); sb.append('\t'); if (site < offset) { sb.append(StringUtils.repeat("*", offset - site)); sb.append(proteinSeq.substring(0, site)); } else { sb.append(proteinSeq.substring(site - offset, site)); } int end = site + offset + 1; if (end > len) { sb.append(proteinSeq.substring(site, len)); sb.append(StringUtils.repeat("*", end - len)); } else { sb.append(proteinSeq.substring(site, end)); } sb.append('\t'); sb.append(proteinSeq.charAt(site)); sb.append('\t'); sb.append(preds.get(site)); sb.append('\t'); SpecificityEstimator est = model.getSpecEstimator(); sb.append(est.specificity(preds.get(site))); sb.append('\t'); sb.append(model.getName()); sb.append('\n'); } } } return sb.toString(); }
From source file:me.taylorkelly.mywarp.bukkit.util.FormattingUtils.java
/** * Centralizes the given string relative to the given width by padding it with the given character. *//from w w w .j av a 2 s.co m * @param str the string to centralize * @param pad the padding char * @param paddedWidth the width of the padded string * @return the centered string */ public static String center(String str, char pad, int paddedWidth) { paddedWidth -= getWidth(str); String padding = StringUtils.repeat(Character.toString(pad), paddedWidth / getWidth(pad) / 2); return padding + str + padding; }
From source file:eu.annocultor.converters.time.OntologyToHtmlGenerator.java
void addToIndexFile(StringInStack url, String prefLabel) { // if (previous == null) { // // } else { // if (url.getLevel() > previous.getLevel()) { // urls.add("</div>"); // urls.add("<div class=\"div_" + url.getLevel() + "\">"); // } else { // urls.add("<div class=\"div_" + url.getLevel() + "\">"); // urls.add("<div class=\"div_" + url.getLevel() + "\">"); // } // }/*from w ww . j a va2s . c om*/ String prefix = StringUtils.repeat(" ", url.getLevel()); String prefLabelToDisplay = StringUtils.substringBefore(prefLabel, "<sub>"); String text = "<a href=\"" + url.getString() + "\">" + prefLabelToDisplay + "</a>"; if (url.getLevel() > lastLevel) { last = new Node(text, url.getString(), url.getLevel(), last); // urls.add(prefix + "<li><ul>"); } if (url.getLevel() < lastLevel) { for (int i = 0; i <= lastLevel - url.getLevel(); i++) { last = last.getParent(); } last = new Node(text, url.getString(), url.getLevel(), last); // urls.add(prefix + "</ul></li>"); } if (url.getLevel() == lastLevel) { last = new Node(text, url.getString(), url.getLevel(), last.getParent()); // urls.add("</li><li>"); } // urls.add("<li><p class=\"level_" + url.getLevel() + "\"><a href=\"" + url.getString() + "\">" // + StringUtils.substringBefore(prefLabel, "<sub>") + "</a></p>"); lastLevel = url.getLevel(); }