List of usage examples for org.apache.commons.lang3 StringUtils leftPad
public static String leftPad(final String str, final int size)
Left pad a String with spaces (' ').
The String is padded to the size of size .
StringUtils.leftPad(null, *) = null StringUtils.leftPad("", 3) = " " StringUtils.leftPad("bat", 3) = "bat" StringUtils.leftPad("bat", 5) = " bat" StringUtils.leftPad("bat", 1) = "bat" StringUtils.leftPad("bat", -1) = "bat"
From source file:com.netflix.genie.web.controllers.JobRestControllerIntegrationTest.java
/** * Test to make sure command args are limitted to 10,000 characters. * * @throws Exception On error//from w w w .j a v a2s .co m */ @Test public void testForTooManyCommandArgs() throws Exception { final JobRequest tooManyCommandArguments = new JobRequest.Builder(JOB_NAME, JOB_USER, JOB_VERSION, Lists.newArrayList(new ClusterCriteria(Sets.newHashSet(LOCALHOST_CLUSTER_TAG))), Sets.newHashSet(BASH_COMMAND_TAG)).withCommandArgs(StringUtils.leftPad("bad", 10_001)).build(); RestAssured.given(this.getRequestSpecification()).contentType(MediaType.APPLICATION_JSON_VALUE) .body(GenieObjectMapper.getMapper().writeValueAsBytes(tooManyCommandArguments)).when() .port(this.port).post(JOBS_API).then() .statusCode(Matchers.is(HttpStatus.PRECONDITION_FAILED.value())); }
From source file:com.gargoylesoftware.htmlunit.javascript.DebugFrameImpl.java
/** * Returns the line number of the first line in this frame's function or script, or <tt>???</tt> * if it cannot be determined. This is necessary because the line numbers provided by Rhino are unordered. * * @return the line number of the first line in this frame's function or script, or <tt>???</tt> * if it cannot be determined//from w ww . j a v a 2s . com */ private String getFirstLine(final Context cx) { final Object line = cx.getThreadLocal(KEY_LAST_LINE); String result; if (line == null) { result = "??"; } else { result = String.valueOf(line); } return StringUtils.leftPad(result, 5); }
From source file:com.github.devnied.emvnfccard.utils.TlvUtil.java
public static String getSpaces(final int length) { return StringUtils.leftPad(StringUtils.EMPTY, length); }
From source file:info.financialecology.finance.utilities.datastruct.VersatileDataTable.java
/** * Prints a header row. The total width of the header row * depends on the column width parameter. * @return the header// w ww .ja v a 2 s.co m */ public String printHeaders() { String ts = " "; int nItems = getColumnCount(); ts += StringUtils.repeat(' ', 12); for (int i = 0; i < nItems; i++) { String columnKey = (String) getColumnKey(i); String label = extractVariableName(columnKey); label += mapIndices(columnKey); ts += " " + StringUtils.leftPad(label, internalParams.getColumnWidth() + 1); } return ts += " "; }
From source file:info.financialecology.finance.utilities.datastruct.VersatileTimeSeriesCollection.java
/** * Creates an dimension index string of a time series based * on the index map. /*from w w w . j av a 2 s . c o m*/ * <p> * <b>Example:</b> Consider the time series <code>order_2_65</code>. * If no index map is defined for this particular order series, then * the string returned by this method will be something like "2   * 65". If a map is defined for the first index, e.g. (...,"2", * "hedge",...), the string returned will be "hedge   65" * <p> * <b>Note:</b> This method produces index strings with padded values. * The size of the padding is not parameterised here. * @param ats the time series whose indices should be mapped, if * applicable * @return the string containing the mapped, partially mapped, or * original dimension indices */ private String mapIndices(VersatileTimeSeries ats) { String mappedIndex = ""; String key = (String) ats.getKey(); String mapKey = ""; String variableName = ats.extractVariableName(key); HashMap<String, String> map = indexMap.get(variableName); ArrayList<String> indices = ats.extractVariableIndices(key); // gets the list of dimension indices // TODO leave the padding to the printDecorated method and use getIndexSeparator for (int i = 1; i <= indices.size(); i++) { if (map == null) // if this time series has not mapped the index values, use the values themselves mappedIndex += StringUtils.leftPad(indices.get(i - 1), 5); else { mapKey = i + "-" + indices.get(i - 1); String entry = map.get(mapKey); if (entry == null) // if the mapping is not defined, use the original index values mappedIndex += StringUtils.leftPad(indices.get(i - 1), 5); else // if a map is provided for the index, use the new index label mappedIndex += StringUtils.leftPad(entry, 5); } if ((i < indices.size()) && (i != indices.size())) mappedIndex += internalParams.getIndexSeparator(); // chaining indices for multiple dimension indices } return mappedIndex; }
From source file:info.financialecology.finance.utilities.datastruct.VersatileTimeSeries.java
/** * Prints the time, date, or tick header of a time series or collection of time series. The output * is restricted to a maximum number of leading and trailing ticks, times, or dates, separated by * elipses '...'.//from w w w . j ava 2s .c o m * <p> * The format of the string of ticks, times, or dates depends on the following parameters * <ul> * <li><code>outputHead</code>: max number of leading time series values in the output string</li> * <li><code>outputTail</code>: max number of trailing time series values in the output string</li> * <li><code>columnWidth</code>: minimum width of the output column</li> * <li><code>timePeriodFormat</code>: either "tick" (for a tick representation) or "actual" * (for time or date representation, using parameter <code>dateFormat</code> * <li><code>dateFormat</code>: indicates the format of the times or dates if <code>timePeriodFormat</code> * is set to "actual"</li> * </ul> * <p> * <b>Examples</b> * <ul> * <li>      1       2       3   ...   998 *       999     1000</li> * <li>      1 March 2014       2 March 2014       * 3 March 2014   ...   13 September 2024       14 September 2024 *     15 September 2024</li> * </ul> * <p> * @return the formatted sequence of time series ticks, times, or dates * @see #printDecoratedTicks(int) */ public String printTicks() { String ts = " "; int nItems = getItemCount(); // Determine length of time series head and tail, given int headLength = nItems < internalParams.getOutputHead() ? nItems : internalParams.getOutputHead(); int tailLength = nItems < internalParams.getOutputHead() ? 0 : nItems - internalParams.getOutputHead(); tailLength = tailLength < internalParams.getOutputTail() ? tailLength : internalParams.getOutputTail(); // Construct the header in 'tick' format (= sequence of integers) if (internalParams.getTimePeriodFormat().equalsIgnoreCase("tick")) { for (int i = 0; i < headLength; i++) ts += String.format(" %" + internalParams.getColumnWidth() + "d", i); if (tailLength > 0) ts += " ... "; for (int i = nItems - tailLength; i < nItems; i++) ts += String.format(" %" + internalParams.getColumnWidth() + "d", i); } // Construct the header in desired time or date format (e.g. 12 March 2012). Set the format via parameter DATE_FORMAT else if (internalParams.getTimePeriodFormat().equalsIgnoreCase("actual")) { SimpleDateFormat dateFormat = new SimpleDateFormat(internalParams.getDateFormat()); // sets the desired format of the time or date for (int i = 0; i < headLength; i++) ts += " " + StringUtils.leftPad(dateFormat.format(getTimePeriod(i).getStart()), internalParams.getColumnWidth()); if (tailLength > 0) ts += " ... "; for (int i = nItems - tailLength; i < nItems; i++) ts += " " + StringUtils.leftPad(dateFormat.format(getTimePeriod(i).getStart()), internalParams.getColumnWidth()); } return ts + " "; }
From source file:net.sourceforge.pmd.benchmark.TextReport.java
@Override public void generate(Map<String, BenchmarkResult> benchmarksByName, PrintStream stream) { List<BenchmarkResult> results = new ArrayList<>(benchmarksByName.values()); long[] totalTime = new long[Benchmark.TotalPMD.index + 1]; long[] totalCount = new long[Benchmark.TotalPMD.index + 1]; for (BenchmarkResult benchmarkResult : results) { totalTime[benchmarkResult.type.index] += benchmarkResult.getTime(); totalCount[benchmarkResult.type.index] += benchmarkResult.getCount(); if (benchmarkResult.type.index < Benchmark.MeasuredTotal.index) { totalTime[Benchmark.MeasuredTotal.index] += benchmarkResult.getTime(); }/* w ww . j a v a 2s. c o m*/ } results.add(new BenchmarkResult(Benchmark.RuleTotal, totalTime[Benchmark.RuleTotal.index], 0)); results.add(new BenchmarkResult(Benchmark.RuleChainTotal, totalTime[Benchmark.RuleChainTotal.index], 0)); results.add(new BenchmarkResult(Benchmark.MeasuredTotal, totalTime[Benchmark.MeasuredTotal.index], 0)); results.add(new BenchmarkResult(Benchmark.NonMeasuredTotal, totalTime[Benchmark.TotalPMD.index] - totalTime[Benchmark.MeasuredTotal.index], 0)); Collections.sort(results); StringBuilderCR buf = new StringBuilderCR(PMD.EOL); boolean writeRuleHeader = true; boolean writeRuleChainRuleHeader = true; long ruleCount = 0; long ruleChainCount = 0; for (BenchmarkResult benchmarkResult : results) { StringBuilder buf2 = new StringBuilder(benchmarkResult.name); buf2.append(':'); while (buf2.length() <= NAME_COLUMN_WIDTH) { buf2.append(' '); } String result = MessageFormat.format("{0,number,0.000}", Double.valueOf(benchmarkResult.getTime() / 1000000000.0)); buf2.append(StringUtils.leftPad(result, VALUE_COLUMN_WIDTH)); if (benchmarkResult.type.index <= Benchmark.RuleChainRule.index) { buf2.append(StringUtils.leftPad( MessageFormat.format("{0,number,###,###,###,###,###}", benchmarkResult.getCount()), 20)); } switch (benchmarkResult.type) { case Rule: if (writeRuleHeader) { writeRuleHeader = false; buf.appendLn(); buf.appendLn("---------------------------------<<< Rules >>>---------------------------------"); buf.appendLn("Rule name Time (secs) # of Evaluations"); buf.appendLn(); } ruleCount++; break; case RuleChainRule: if (writeRuleChainRuleHeader) { writeRuleChainRuleHeader = false; buf.appendLn(); buf.appendLn("----------------------------<<< RuleChain Rules >>>----------------------------"); buf.appendLn("Rule name Time (secs) # of Visits"); buf.appendLn(); } ruleChainCount++; break; case CollectFiles: buf.appendLn(); buf.appendLn("--------------------------------<<< Summary >>>--------------------------------"); buf.appendLn("Segment Time (secs)"); buf.appendLn(); break; case MeasuredTotal: String s = MessageFormat.format("{0,number,###,###,###,###,###}", ruleCount); String t = MessageFormat.format("{0,number,0.000}", ruleCount == 0 ? 0 : total(totalTime, Benchmark.Rule, ruleCount)); buf.appendLn("Rule Average (", s, " rules):", StringUtils.leftPad(t, 37 - s.length())); s = MessageFormat.format("{0,number,###,###,###,###,###}", ruleChainCount); t = MessageFormat.format("{0,number,0.000}", ruleChainCount == 0 ? 0 : total(totalTime, Benchmark.RuleChainRule, ruleChainCount)); buf.appendLn("RuleChain Average (", s, " rules):", StringUtils.leftPad(t, 32 - s.length())); buf.appendLn(); buf.appendLn("-----------------------------<<< Final Summary >>>-----------------------------"); buf.appendLn("Total Time (secs)"); buf.appendLn(); break; default: // Do nothing break; } buf.appendLn(buf2.toString()); } stream.print(buf.toString()); }
From source file:net.sourceforge.pmd.benchmark.TextTimingReportRenderer.java
@Override public void render(final TimingReport report, final Writer writer) throws IOException { for (final TimedOperationCategory category : TimedOperationCategory.values()) { final Map<String, TimedResult> labeledMeasurements = report.getLabeledMeasurements(category); if (!labeledMeasurements.isEmpty()) { renderCategoryMeasurements(category, labeledMeasurements, writer); }//w w w. ja v a 2s.c o m } renderHeader("Summary", writer); for (final TimedOperationCategory category : TimedOperationCategory.values()) { final TimedResult timedResult = report.getUnlabeledMeasurements(category); if (timedResult != null) { renderMeasurement(category.displayName(), timedResult, writer); } } writer.write(PMD.EOL); renderHeader("Total", writer); writer.write(StringUtils.rightPad("Wall Clock Time", LABEL_COLUMN_WIDTH)); final String wallClockTime = MessageFormat.format(TIME_FORMAT, report.getWallClockMillis() / 1000.0); writer.write(StringUtils.leftPad(wallClockTime, TIME_COLUMN_WIDTH)); writer.write(PMD.EOL); writer.flush(); }
From source file:net.sourceforge.pmd.benchmark.TextTimingReportRenderer.java
private void renderMeasurement(final String label, final TimedResult timedResult, final Writer writer) throws IOException { writer.write(StringUtils.rightPad(label, LABEL_COLUMN_WIDTH)); final String time = MessageFormat.format(TIME_FORMAT, timedResult.totalTimeNanos.get() / 1000000000.0); writer.write(StringUtils.leftPad(time, TIME_COLUMN_WIDTH)); final String selfTime = MessageFormat.format(TIME_FORMAT, timedResult.selfTimeNanos.get() / 1000000000.0); writer.write(StringUtils.leftPad(selfTime, SELF_TIME_COLUMN_WIDTH)); if (timedResult.callCount.get() > 0) { final String callCount = MessageFormat.format(CUSTOM_COUNTER_FORMAT, timedResult.callCount.get()); writer.write(StringUtils.leftPad(callCount, CALL_COLUMN_WIDTH)); if (timedResult.extraDataCounter.get() > 0) { final String counter = MessageFormat.format(CUSTOM_COUNTER_FORMAT, timedResult.extraDataCounter.get()); writer.write(StringUtils.leftPad(counter, COUNTER_COLUMN_WIDTH)); }/*from www. j a v a 2 s .c om*/ } writer.write(PMD.EOL); }
From source file:net.sourceforge.pmd.benchmark.TextTimingReportRenderer.java
private void renderHeader(final String displayName, final Writer writer) throws IOException { final StringBuilder sb = new StringBuilder(COLUMNS).append(displayName); // Make sure we have an even-length string if (displayName.length() % 2 == 1) { sb.append(' '); }/*from w w w . j a v a 2 s . com*/ // Surround with <<< and >>> sb.insert(0, "<<< ").append(" >>>"); // Create the ruler while (sb.length() < COLUMNS) { sb.insert(0, '-').append('-'); } writer.write(sb.toString()); writer.write(PMD.EOL); // Write table titles writer.write(StringUtils.rightPad("Label", LABEL_COLUMN_WIDTH)); writer.write(StringUtils.leftPad("Time (secs)", TIME_COLUMN_WIDTH)); writer.write(StringUtils.leftPad("Self Time (secs)", SELF_TIME_COLUMN_WIDTH)); writer.write(StringUtils.leftPad("# Calls", CALL_COLUMN_WIDTH)); writer.write(StringUtils.leftPad("Counter", COUNTER_COLUMN_WIDTH)); writer.write(PMD.EOL); writer.write(PMD.EOL); }