Example usage for org.apache.commons.lang3 StringUtils rightPad

List of usage examples for org.apache.commons.lang3 StringUtils rightPad

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils rightPad.

Prototype

public static String rightPad(final String str, final int size) 

Source Link

Document

Right pad a String with spaces (' ').

The String is padded to the size of size .

 StringUtils.rightPad(null, *)   = null StringUtils.rightPad("", 3)     = "   " StringUtils.rightPad("bat", 3)  = "bat" StringUtils.rightPad("bat", 5)  = "bat  " StringUtils.rightPad("bat", 1)  = "bat" StringUtils.rightPad("bat", -1) = "bat" 

Usage

From source file:de.lmu.ifi.dbs.jfeaturelib.utils.Extractor.java

/**
 * Prints the supports capabilities of the feature descriptors and prints the string to System.out.
 *//*from  www . j  a  v  a 2 s .c o m*/
private void listFeatureDescriptorCapabilities()
        throws InstantiationException, IllegalAccessException, IOException, URISyntaxException {
    Package fdPackage = FeatureDescriptor.class.getPackage();
    int offset = fdPackage.getName().length() + 1;

    // search for the descriptors
    PackageScanner<FeatureDescriptor> scanner = new PackageScanner<>();
    List<Class<FeatureDescriptor>> classes = scanner.scanForClass(fdPackage, FeatureDescriptor.class);

    // find the longest name to make a nice output
    int maxNameLength = 0;
    for (Class<FeatureDescriptor> fd : classes) {
        maxNameLength = Math.max(fd.getName().length() - offset, maxNameLength);
    }

    // sort the classes by class name
    Collections.sort(classes, new ClassNameComparator());

    // now we know the longest descriptor name - build the output string
    StringBuilder outString = new StringBuilder();
    for (Class<FeatureDescriptor> fd : classes) {
        String name = fd.getName().substring(offset);
        outString.append(StringUtils.rightPad(name, maxNameLength));
        outString.append(" : ");
        outString.append(fd.newInstance().supports().toString());
        outString.append("\n");
    }
    System.out.println(outString);
}

From source file:com.adobe.acs.commons.hc.impl.HealthCheckStatusEmailer.java

/**
 * Gererates the plain-text email sections for sets of Health Check Execution Results.
 *
 * @param title The section title/*from  w  w  w.j av a  2  s .  c  o  m*/
 * @param results the  Health Check Execution Results to render as plain text
 * @return the String for this section to be embedded in the e-mail
 */
protected String resultToPlainText(final String title, final List<HealthCheckExecutionResult> results) {
    final StringBuilder sb = new StringBuilder();

    sb.append(title);
    sb.append(System.lineSeparator());

    if (results.size() == 0) {
        sb.append("No " + StringUtils.lowerCase(title) + " could be found!");
        sb.append(System.lineSeparator());
    } else {
        sb.append(StringUtils.repeat("-", NUM_DASHES));
        sb.append(System.lineSeparator());

        for (final HealthCheckExecutionResult result : results) {
            sb.append(StringUtils.rightPad("[ " + result.getHealthCheckResult().getStatus().name() + " ]",
                    HEALTH_CHECK_STATUS_PADDING));
            sb.append("  ");
            sb.append(result.getHealthCheckMetadata().getTitle());
            sb.append(System.lineSeparator());
        }
    }

    return sb.toString();
}

From source file:de.hasait.clap.CLAP.java

public void printHelp(final PrintStream pPrintStream) {
    final Map<CLAPHelpCategoryImpl, Set<CLAPHelpNode>> nodes = new TreeMap<CLAPHelpCategoryImpl, Set<CLAPHelpNode>>();
    _root.collectHelpNodes(nodes, null);

    int maxLength = 0;
    for (final Entry<CLAPHelpCategoryImpl, Set<CLAPHelpNode>> entry : nodes.entrySet()) {
        for (final CLAPHelpNode node : entry.getValue()) {
            final int length = node.getHelpID().length();
            if (length > maxLength) {
                maxLength = length;/*from  w  w w .ja v  a 2s .co  m*/
            }
        }
    }
    maxLength += 6; // space to description

    for (final Entry<CLAPHelpCategoryImpl, Set<CLAPHelpNode>> entry : nodes.entrySet()) {
        pPrintStream.println();
        pPrintStream.println(nls(entry.getKey().getTitleNLSKey()));
        for (final CLAPHelpNode node : entry.getValue()) {
            pPrintStream.println();
            pPrintStream.print("  "); //$NON-NLS-1$
            pPrintStream.print(StringUtils.rightPad(node.getHelpID(), maxLength - 2));
            final String descriptionNLSKey = node.getDescriptionNLSKey();
            if (descriptionNLSKey != null) {
                pPrintStream.println(nls(descriptionNLSKey));
            } else {
                pPrintStream.println();
            }
        }
    }
}

From source file:com.liferay.blade.cli.command.CreateCommand.java

private void _printTemplates() throws Exception {
    BladeCLI bladeCLI = getBladeCLI();/*  w  w w  .  j a  va  2  s. c om*/

    Map<String, String> templates = BladeUtil.getTemplates(bladeCLI);

    List<String> templateNames = new ArrayList<>(BladeUtil.getTemplateNames(getBladeCLI()));

    Collections.sort(templateNames);

    Comparator<String> compareLength = Comparator.comparingInt(String::length);

    Stream<String> stream = templateNames.stream();

    String longestString = stream.max(compareLength).get();

    int padLength = longestString.length() + 2;

    for (String name : templateNames) {
        PrintStream out = bladeCLI.out();

        out.print(StringUtils.rightPad(name, padLength));

        bladeCLI.out(templates.get(name));
    }
}

From source file:com.mirth.connect.server.controllers.tests.TestUtils.java

public static String getPerformanceText(String testName, int testSize, long milliseconds) {
    double seconds = ((double) milliseconds) / 1000.0;
    return StringUtils.rightPad(testName, 50) + ((int) (testSize / seconds)) + " messages/second";
}

From source file:com.srotya.monitoring.kafka.util.KafkaConsumerOffsetUtil.java

public static String htmlOutput(List<KafkaOffsetMonitor> kafkaOffsetMonitors) {
    StringBuilder sb = new StringBuilder();
    sb.append("<html><body><pre>");
    sb.append(String.format("%s \t %s \t %s \t %s \t %s \t %s \n", StringUtils.rightPad("Consumer Group", 40),
            StringUtils.rightPad("Topic", 40), StringUtils.rightPad("Partition", 10),
            StringUtils.rightPad("Log Size", 10), StringUtils.rightPad("Consumer Offset", 15),
            StringUtils.rightPad("Lag", 10)));
    for (KafkaOffsetMonitor kafkaOffsetMonitor : kafkaOffsetMonitors) {
        sb.append(String.format("%s \t %s \t %s \t %s \t %s \t %s \n",
                StringUtils.rightPad(kafkaOffsetMonitor.getConsumerGroupName(), 40),
                StringUtils.rightPad(kafkaOffsetMonitor.getTopic(), 40),
                StringUtils.rightPad("" + kafkaOffsetMonitor.getPartition(), 10),
                StringUtils.rightPad("" + kafkaOffsetMonitor.getLogSize(), 10),
                StringUtils.rightPad("" + kafkaOffsetMonitor.getConsumerOffset(), 15),
                StringUtils.rightPad("" + kafkaOffsetMonitor.getLag(), 10)));
    }//from  w ww .j a v  a 2s .  c  o m
    sb.append("</pre></body></html>");
    return sb.toString();
}

From source file:candr.yoclip.Parser.java

protected String createHelp() {

    final ParserOptions<T> parserOptions = getParserOptions();
    final ParserHelpFactory<T> parserHelpFactory = getParserHelpFactory();

    final StrBuilder builder = new StrBuilder();

    // the usage synopsis is first
    builder.append("Usage: ").append(parserOptions.getName()).append(' ').appendln(getUsage());

    // followed by the header if one is available
    final String header = parserHelpFactory.getHeaderDescription(parserOptions);
    if (!StringUtils.isEmpty(header)) {

        if (isSpaceBeforeHeader()) {
            builder.appendNewLine();/*from  ww w  . j a v  a2 s  . c  om*/
        }

        builder.appendln(parserHelpFactory.wrap(header, getWidth()));
    }

    // followed by the option descriptions
    final String prefix = parserOptions.getPrefix();
    final String separator = parserOptions.getSeparator();

    // get all the options descriptions
    int hangingIndentSize = 0;
    final List<Pair<Boolean, Pair<String, String>>> optionDescriptionWrappers = new LinkedList<Pair<Boolean, Pair<String, String>>>();
    for (final ParserOption<T> parserOption : parserOptions.get()) {

        final Pair<String, String> optionDescription = parserHelpFactory.getOptionDescription(prefix, separator,
                parserOption);
        optionDescriptionWrappers.add(ImmutablePair.of(true, optionDescription));
        hangingIndentSize = Math.max(hangingIndentSize, optionDescription.getLeft().length());

        for (final Pair<String, String> optionPropertyDescription : parserHelpFactory
                .getOptionPropertyDescriptions(parserOption)) {
            optionDescriptionWrappers.add(ImmutablePair.of(false, optionPropertyDescription));
        }
    }

    // now add the help to the builder
    int maxIndentSize = getWidth() / 4;
    hangingIndentSize = Math.min(hangingIndentSize + 2, maxIndentSize);
    for (final Pair<Boolean, Pair<String, String>> optionDescriptionWrapper : optionDescriptionWrappers) {

        if (isSpaceBetweenOptionDescriptions()) {
            builder.appendNewLine();
        }

        // create the option description or option property description
        final StrBuilder descriptionBuilder = new StrBuilder();
        if (optionDescriptionWrapper.getLeft()) {

            final Pair<String, String> optionDescription = optionDescriptionWrapper.getRight();
            descriptionBuilder.append(StringUtils.rightPad(optionDescription.getLeft(), hangingIndentSize));
            if (descriptionBuilder.length() > hangingIndentSize) {
                descriptionBuilder.append(" ");
            }
            descriptionBuilder.append(optionDescription.getRight());

        } else {

            final Pair<String, String> optionPropertyDescription = optionDescriptionWrapper.getRight();
            descriptionBuilder.appendPadding(hangingIndentSize, ' ').append("'")
                    .append(optionPropertyDescription.getLeft()).append("' ")
                    .append(optionPropertyDescription.getRight());
        }
        builder.appendln(parserHelpFactory.hangingIndentWrap(descriptionBuilder.toString(), hangingIndentSize,
                getWidth()));
    }

    // followed by the trailer if one is available
    final String trailer = parserHelpFactory.getTrailerDescription(parserOptions);
    if (!StringUtils.isEmpty(trailer)) {

        if (isSpaceBeforeTrailer()) {
            builder.appendNewLine();
        }

        builder.appendln(parserHelpFactory.wrap(trailer, getWidth()));
    }

    return builder.toString();
}

From source file:info.financialecology.finance.utilities.datastruct.VersatileDataTable.java

/**
 * Prints all rows containing values.//from   www  . jav  a  2  s .co m
 * @return the header
 */
public String printValues() {
    String ts = "";
    String tsLast = "";
    List<String> rowKeys = getRowKeys();
    List<String> columnKeys = getColumnKeys();

    for (String rowKey : rowKeys) {
        if (StringUtils.startsWith(rowKey, "#")) {
            tsLast += "  " + StringUtils.rightPad(rowKey, 8) + " | "; // TODO leftmost column width should be a parameter
            for (String columnKey : columnKeys)
                tsLast += " " + String.format(" " + internalParams.getNumberFormat(),
                        getValue(rowKey, columnKey).doubleValue());
            tsLast += "\n";
        } else {
            ts += "  " + StringUtils.rightPad(rowKey, 8) + " | ";
            for (String columnKey : columnKeys)
                ts += " " + String.format(" " + internalParams.getNumberFormat(),
                        getValue(rowKey, columnKey).doubleValue());
            ts += "\n";
        }
    }

    //        for (int i = 0; i < getRowCount(); i++) {
    //            ts += "  " + StringUtils.rightPad((String) getRowKey(i), 4) + " | ";
    //            for (int j = 0; j < getColumnCount(); j++)
    //                ts += " " + String.format(" " + internalParams.getNumberFormat(), getValue(i, j).doubleValue());
    //            ts += "\n";
    //        }

    if (!tsLast.equalsIgnoreCase(""))
        ts += printRowSeparator(".") + "\n" + tsLast;

    return ts + " ";
}

From source file:info.financialecology.finance.utilities.datastruct.VersatileTimeSeries.java

/**
 * Prints the time, date, or tick of a time series or collection of time series, 
 * plus the row label 'TICK' (if the parameter <code>timePeriodFormat</code> is set 
 * to  or 'DATE'. See {@link #printTicks()} for more details and for parameter
 * dependencies.//  www .j  a v a 2  s  .  co  m
 * <p>
 * @param width the width of the right-hand row label
 * @return the sequence of ticks, times, or dates from the time series and the right-hand
 * label 'TICK' or 'DATE'
 * @see #printTicks()
 */
public String printDecoratedTicks(int width) {
    String timePeriodFormat = "";

    if (internalParams.getTimePeriodFormat().equalsIgnoreCase("tick"))
        timePeriodFormat = "TICK";
    else if (internalParams.getTimePeriodFormat().equalsIgnoreCase("actual"))
        timePeriodFormat = "DATE"; // TODO for time period units of second, minute and hour, add the label 'TIME'

    String ts = StringUtils.rightPad(timePeriodFormat, width - 2);
    ts += printTicks();
    return ts;
}

From source file:com.mirth.connect.donkey.test.util.TestUtils.java

public static String getPerformanceText(int numDestinations, long milliseconds, List<Long> times)
        throws IOException {
    double seconds = ((double) milliseconds) / 1000d;
    double speed = ((double) times.size()) / seconds;

    long sum = 0;
    Writer writer = null;/*from  w w  w . j  a v a 2 s  .  com*/

    if (PERFORMANCE_LOG_FILE != null) {
        writer = new BufferedWriter(new FileWriter(new File(PERFORMANCE_LOG_FILE)));
    }

    for (Long time : times) {
        sum += time;

        if (writer != null) {
            writer.append(time + "\n");
        }
    }

    if (writer != null) {
        writer.flush();
    }

    Collections.sort(times);

    StringBuilder stringBuilder = new StringBuilder();
    final int padding = 17;

    stringBuilder.append(StringUtils.rightPad("Messages Sent:", padding) + times.size() + "\n");
    stringBuilder.append(
            StringUtils.rightPad("Inbound:", padding) + Precision.round(speed, 2) + " messages/second\n");
    stringBuilder.append(StringUtils.rightPad("Outbound:", padding)
            + Precision.round(speed * numDestinations, 2) + " messages/second\n");

    if (times.size() > 0) {
        stringBuilder.append(StringUtils.rightPad("Lowest Time:", padding) + times.get(0) + "ms\n");
        stringBuilder
                .append(StringUtils.rightPad("Highest Time:", padding) + times.get(times.size() - 1) + "ms\n");
        stringBuilder
                .append(StringUtils.rightPad("Median Time:", padding) + times.get(times.size() / 2) + "ms\n");
        stringBuilder.append(StringUtils.rightPad("Average Time:", padding)
                + Precision.round((double) sum / (double) times.size(), 2) + "ms\n");
        stringBuilder.append(StringUtils.rightPad("Total Send Time:", padding) + sum + "ms\n");
        stringBuilder.append(StringUtils.rightPad("Total Test Time:", padding) + milliseconds + "ms\n");
    }

    return stringBuilder.toString();
}