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:org.codice.ddf.commands.catalog.CatalogCommands.java
private String getProgressBar(long currentCount, long totalPossible, long start, long end) { int notches = calculateNotches(currentCount, totalPossible); int progressPercentage = calculateProgressPercentage(currentCount, totalPossible); int rate = calculateRecordsPerSecond(currentCount, 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:org.deidentifier.arx.examples.Example47.java
/** * Helper that prints a table/*from w w w.j ava 2s . c o m*/ * @param quasiIdentifiers */ private static void printPrettyTable(RiskModelAttributes.QuasiIdentifierRisk[] quasiIdentifiers) { // get char count of longest quasi-identifier int charCountLongestQi = quasiIdentifiers[quasiIdentifiers.length - 1].getIdentifier().toString().length(); // make sure that there is enough space for the table header strings charCountLongestQi = Math.max(charCountLongestQi, 12); // calculate space needed String leftAlignFormat = "| %-" + charCountLongestQi + "s | %13.2f | %12.2f |%n"; // add 2 spaces that are in the string above on the left and right side of the first pattern charCountLongestQi += 2; // subtract the char count of the column header string to calculate // how many spaces we need for filling up to the right columnborder int spacesAfterColumHeader = charCountLongestQi - 12; System.out.format("+" + StringUtils.repeat("-", charCountLongestQi) + "+---------------+--------------+%n"); System.out.format("| Identifier " + StringUtils.repeat(" ", spacesAfterColumHeader) + "| Distinction | Separation |%n"); System.out.format("+" + StringUtils.repeat("-", charCountLongestQi) + "+---------------+--------------+%n"); for (RiskModelAttributes.QuasiIdentifierRisk quasiIdentifier : quasiIdentifiers) { // print every Quasi-Identifier System.out.format(leftAlignFormat, quasiIdentifier.getIdentifier(), quasiIdentifier.getDistinction() * 100, quasiIdentifier.getSeparation() * 100); } System.out.format("+" + StringUtils.repeat("-", charCountLongestQi) + "+---------------+--------------+%n"); }
From source file:org.dkpro.lab.reporting.FlexTable.java
public StreamWriter getTextWriter() { return new StreamWriter() { @Override/*from ww w . j a va2 s . c om*/ public void write(OutputStream aStream) throws Exception { String[] colIds = FlexTable.this.compact ? getCompactColumnIds(false) : getColumnIds(); // Obtain the width of the columns based on their content and headers // col 0 is reserved here for the rowId width int colWidths[] = new int[colIds.length + 1]; for (String rowId : getRowIds()) { colWidths[0] = Math.max(colWidths[0], rowId.length()); } for (int i = 1; i < colWidths.length; i++) { colWidths[i] = Math.max(colWidths[i], colIds[i - 1].length()); for (String rowId : getRowIds()) { colWidths[i] = Math.max(colWidths[i], getValueAsString(rowId, colIds[i - 1]).length()); } } StringBuilder separator = new StringBuilder(); for (int w : colWidths) { if (separator.length() > 0) { separator.append("-+-"); } separator.append(StringUtils.repeat("-", w)); } separator.insert(0, "+-"); separator.append("-+"); PrintWriter writer = new PrintWriter(new OutputStreamWriter(aStream, "UTF-8")); // Render header column writer.println(separator); writer.print("| "); writer.print(StringUtils.repeat(" ", colWidths[0])); for (int i = 0; i < colIds.length; i++) { writer.print(" | "); // Remember: colWidth[0] is the rowId width! writer.print(StringUtils.center(colIds[i], colWidths[i + 1])); } writer.println(" |"); writer.println(separator); // Render body for (String rowId : getRowIds()) { writer.print("| "); writer.print(StringUtils.rightPad(rowId, colWidths[0])); for (int i = 0; i < colIds.length; i++) { writer.print(" | "); // Remember: colWidth[0] is the rowId width! String val = getValueAsString(rowId, colIds[i]); if (isDouble(val)) { writer.print(StringUtils.leftPad(val, colWidths[i + 1])); } else { writer.print(StringUtils.rightPad(val, colWidths[i + 1])); } } writer.println(" |"); } // Closing separator writer.println(separator); writer.flush(); } private boolean isDouble(String val) { try { double d = Double.parseDouble(val); // TODO: A bit of a hack; use Regex instead? } catch (NumberFormatException ex) { return false; } return true; } }; }
From source file:org.dllearner.algorithms.probabilistic.structure.unife.leap.AbstractLEAP.java
protected void printTimings(long totalTimeMills, long celaTimeMills, TreeMap<String, Long> timeMap) { logger.info("Main: " + totalTimeMills + " ms"); logger.info("CELOE: " + celaTimeMills + " ms"); long timeOther = totalTimeMills - celaTimeMills; for (Entry<String, Long> time : timeMap.entrySet()) { String names[] = time.getKey().split("\\."); if (names.length == 1) { timeOther -= time.getValue(); // logger.info(timeMap.subMap(names[0], names[0] + Character.MAX_VALUE).toString()); }/*from www. ja v a 2 s . c o m*/ String output = StringUtils.repeat("\t", names.length - 1); output += names[names.length - 1] + ": " + time.getValue() + " ms"; logger.info(output); } // logger.info("EDGE: " + (timeMap.get("EM") + timeMap.get("Bundle")) + " ms"); // logger.info("\tBundle: " + timeMap.get("Bundle") + " ms"); // logger.info("\tEM: " + timeMap.get("EM") + " ms"); // long timeOther = totalTimeMills - celaTimeMills - (timeMap.get("EM") + timeMap.get("Bundle")); logger.info("Other: " + timeOther + " ms"); logger.info("Program client: execution successfully terminated"); }
From source file:org.drools.semantics.lang.dl.DL_9_CompilationTest.java
private String tab(int n) { return StringUtils.repeat("\t", n); }
From source file:org.drugis.mtc.NetworkBuilderTest.java
@Test public void testIdTransform() { NoneNetworkBuilder<Integer> builder = new NoneNetworkBuilder<Integer>(new Transformer<Integer, String>() { public String transform(Integer input) { return StringUtils.repeat("A", input.intValue()); }/*from w w w . j av a 2s .co m*/ }, new EmptyStringTransformer<Integer>()); builder.add("1", 5); HashMap<Integer, Treatment> expected = new HashMap<Integer, Treatment>(); expected.put(5, new Treatment("AAAAA")); assertEquals(expected, builder.getTreatmentMap()); }
From source file:org.drugis.mtc.NetworkBuilderTest.java
@Test public void testDescriptionTransform() { NoneNetworkBuilder<Integer> builder = new NoneNetworkBuilder<Integer>( new NetworkBuilder.ToStringTransformer<Integer>(), new Transformer<Integer, String>() { public String transform(Integer input) { return StringUtils.repeat("A", input.intValue()); }//from w ww.j av a2 s .c om }); builder.add("1", 5); HashMap<Integer, Treatment> expected = new HashMap<Integer, Treatment>(); expected.put(5, new Treatment("5", "AAAAA")); assertEquals(expected, builder.getTreatmentMap()); }
From source file:org.duracloud.duradmin.util.SpaceUtil.java
public static void streamToResponse(InputStream is, HttpServletResponse response, String mimetype, String contentLength) throws ContentStoreException, IOException { OutputStream outStream = response.getOutputStream(); try {// w ww . j a v a 2s .co m response.setContentType(mimetype); if (contentLength != null) { response.setContentLengthLong(Long.parseLong(contentLength)); } byte[] buf = new byte[1024]; int read = -1; while ((read = is.read(buf)) > 0) { outStream.write(buf, 0, read); } response.flushBuffer(); } catch (Exception ex) { if (ex.getCause() instanceof ContentStateException) { response.reset(); response.setStatus(HttpStatus.SC_CONFLICT); String message = "The requested content item is currently in long-term storage" + " with limited retrieval capability. Please contact " + "DuraCloud support (https://wiki.duraspace.org/x/6gPNAQ) " + "for assistance in retrieving this content item."; //It is necessary to pad the message in order to force Internet Explorer to //display the server sent text rather than display the browser default error message. //If the message is less than 512 bytes, the browser will ignore the message. //c.f. http://support.microsoft.com/kb/294807 message += StringUtils.repeat(" ", 512); outStream.write(message.getBytes()); } else { throw ex; } } finally { try { outStream.close(); } catch (Exception e) { log.warn("failed to close outputstream ( " + outStream + "): message=" + e.getMessage(), e); } } }
From source file:org.eclipse.amp.amf.acore.edit.commands.test.CommandTest.java
protected void setUp() throws Exception { List<AdapterFactory> factories = new ArrayList<AdapterFactory>(); factories.add(new ResourceItemProviderAdapterFactory()); factories.add(new MetaABMFunctionItemProviderAdapterFactory()); factories.add(new MetaABMItemProviderAdapterFactory()); factories.add(new MetaABMActItemProviderAdapterFactory()); factories.add(new ReflectiveItemProviderAdapterFactory()); adapterFactory = new ComposedAdapterFactory(factories); // Create the command stack that will notify this editor as commands are // executed./*from www . ja v a 2 s . c om*/ BasicCommandStack commandStack; if (trace) { commandStack = new BasicCommandStack() { int level = 0; public void execute(Command command) { System.out.println(StringUtils.repeat(" ", level) + "Executing: " + command); level++; super.execute(command); level--; System.out.println(StringUtils.repeat(" ", level) + "Executed : " + command); } }; commandStack.addCommandStackListener(new CommandStackListener() { public void commandStackChanged(EventObject event) { System.out.println(" Cmd Event: " + event); } }); } else { commandStack = new BasicCommandStack(); } domain = new AdapterFactoryEditingDomain(adapterFactory, commandStack, new HashMap<Resource, Boolean>()); MetaABMPersist libPersist = MetaABMPersist .createURI(URI.createURI("http://metaabm.org/core_library.metaabm")); lib = libPersist.load(); library = (FLibrary) lib.getLibrary().get(0); funcLog = library.findSub("operators").findSub("logicalOperators"); funcNum = library.findSub("operators").findSub("numericOperators"); funcAdd = funcNum.findFunction("add"); funcEq = funcLog.findFunction("equal"); funcNot = funcLog.findFunction("not"); super.setUp(); }
From source file:org.eclipse.mdht.uml.cda.core.util.CDACommonUtils.java
/** * @param umlClass/* w w w . ja v a 2 s . c o m*/ * used to determine the nesting level of the element - in most cases a Class - but can also be a Constraint as properties are nested * within a constraint and not its containing class within the PDF file * @param index * index of the conformance rule starting from zero in the level designated by the given class * @return */ public static String getCustomizedBulletItem(Element umlClass, int index) { int level = 0; EObject eObject = umlClass; while (eObject != null && !(eObject instanceof Package)) { if (eObject instanceof Class && getMainSection((Class) eObject) != -1) { break; } EObject constrainedProperty = cachePropertyForClass.get(eObject); eObject = getContainerReference(eObject); if (constrainedProperty instanceof Property && eObject instanceof Class) { Class class1 = (Class) eObject; for (Constraint constraint : class1.getOwnedRules()) { if (constraint.getConstrainedElements().contains(constrainedProperty) && CDAProfileUtil.getLogicalConstraint(constraint) != null) { level++; break; } } } level++; } level = level % 3; if (level == 1) { String[] romans = new String[] { "i", "ii", "iii", "iv", "v", "vi", "vii", "viii", "ix", "x" }; return StringUtils.repeat("x", index / 10) + romans[index % 10]; } if (level == 2) { return "" + (char) ('a' + index); } return "" + (index + 1); }