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, String padStr) 

Source Link

Document

Right pad a String with a specified String.

The String is padded to the size of size .

 StringUtils.rightPad(null, *, *)      = null StringUtils.rightPad("", 3, "z")      = "zzz" StringUtils.rightPad("bat", 3, "yz")  = "bat" StringUtils.rightPad("bat", 5, "yz")  = "batyz" StringUtils.rightPad("bat", 8, "yz")  = "batyzyzy" StringUtils.rightPad("bat", 1, "yz")  = "bat" StringUtils.rightPad("bat", -1, "yz") = "bat" StringUtils.rightPad("bat", 5, null)  = "bat  " StringUtils.rightPad("bat", 5, "")    = "bat  " 

Usage

From source file:com.kurtraschke.nyctrtproxy.model.NyctTripId.java

/**
 * Parse a trip ID (from static GTFS or realtime feed) into NyctTripId
 *
 * @param tripId the trip ID/*from w ww .j  a va  2 s . c om*/
 * @return parsed trip ID
 */
private static NyctTripId buildFromString(String tripId) {
    int originDepartureTime;
    String pathId, routeId, directionId, networkId;

    Matcher matcher = _rtTripPattern.matcher(tripId);

    if (matcher.find()) {
        originDepartureTime = Integer.parseInt(matcher.group("originDepartureTime"), 10);
        pathId = StringUtils.rightPad(matcher.group("route"), 3, '.') + matcher.group("direction");
        routeId = matcher.group("route");
        directionId = matcher.group("direction");
        networkId = matcher.group("network");
        if (networkId.length() == 0)
            networkId = null;
        return new NyctTripId(originDepartureTime, pathId, routeId, directionId, networkId);

    } else {
        return null;
    }

}

From source file:com.francetelecom.clara.cloud.services.dto.ConfigOverrideDTOTest.java

@Test(expected = TechnicalException.class)
public void javax_validation_should_reject_too_large_comment() {
    String comment = StringUtils.rightPad("comment", ConfigOverrideDTO.MAX_CONFIG_COMMENT_LENGTH + 2, 'X');
    ConfigOverrideDTO configOverrideDTO = new ConfigOverrideDTO("configSet", "key", "value", comment);
    ValidatorUtil.validate(configOverrideDTO);
}

From source file:info.magnolia.ui.form.field.upload.DefaultFileFactory.java

@Override
public File createFile(String fileName, String mimeType) {
    try {/*from w  w w.  j  av a 2 s  . c o m*/
        File tmpFile = File.createTempFile(StringUtils.rightPad(fileName, 5, "x"), null, directory);
        tmpFile.deleteOnExit();
        return tmpFile;
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.francetelecom.clara.cloud.services.dto.ConfigOverrideDTOTest.java

@Test(expected = TechnicalException.class)
public void javax_validation_should_reject_too_large_value() {
    String value = StringUtils.rightPad("value", ConfigOverrideDTO.MAX_CONFIG_VALUE_LENGTH + 2, 'X');
    ConfigOverrideDTO configOverrideDTO = new ConfigOverrideDTO("configSet", "key", value, "comment");
    ValidatorUtil.validate(configOverrideDTO);
}

From source file:com.isomorphic.maven.util.LoggingCountingOutputStream.java

@Override
protected void afterWrite(final int bytesWritten) throws IOException {
    super.afterWrite(bytesWritten);

    final long byteCount = getByteCount();
    final double progress = ((double) byteCount / (double) expectedByteCount) * 100.0;

    snapshotBytes += bytesWritten;//from  w w w  .  ja v  a 2s.c o  m

    // Lets grab the number of bytes written over the last second and use that as our
    // bytesPerSecond gauge giving the user an indication of speed.
    if (System.currentTimeMillis() - snapshotStart >= 1000) {
        snapshotStart = System.currentTimeMillis();
        bytesPerSecond = snapshotBytes;
        snapshotBytes = 0;
    }

    // Using \r in this print out will cause the console to render this line of text on the
    // same line in order to avoid console spam.
    System.out.print("\r" + StringUtils.rightPad(FileUtils.byteCountToDisplaySize(byteCount) + " / "
            + FileUtils.byteCountToDisplaySize(expectedByteCount) + " ("
            + FileUtils.byteCountToDisplaySize(bytesPerSecond) + "/second) "
            + String.format("%.1f%%", progress), 60, " "));

    if (progress >= 100.0) {
        System.out.println("Done!");
    }
}

From source file:com.blackducksoftware.integration.hub.detect.help.print.HelpTextWriter.java

private String formatColumns(final List<String> columns, final int... columnWidths) {
    final StringBuilder createColumns = new StringBuilder();
    final List<String> columnfirstRow = new ArrayList<>();
    final List<String> columnRemainingRows = new ArrayList<>();
    for (int i = 0; i < columns.size(); i++) {
        if (columns.get(i).length() < columnWidths[i]) {
            columnfirstRow.add(columns.get(i));
            columnRemainingRows.add("");
        } else {//  w w  w .ja va  2  s  . co  m
            final String firstRow = columns.get(i).substring(0, columnWidths[i]);
            int endOfWordIndex = firstRow.lastIndexOf(' ');
            if (endOfWordIndex == -1) {
                endOfWordIndex = columnWidths[i] - 1;
                columnfirstRow.add(firstRow.substring(0, endOfWordIndex) + " ");
            } else {
                columnfirstRow.add(firstRow.substring(0, endOfWordIndex));
            }

            columnRemainingRows.add(columns.get(i).substring(endOfWordIndex).trim());
        }
    }

    for (int i = 0; i < columnfirstRow.size(); i++) {
        createColumns.append(StringUtils.rightPad(columnfirstRow.get(i), columnWidths[i], " "));
    }

    if (!allColumnsEmpty(columnRemainingRows)) {
        createColumns.append(System.lineSeparator() + formatColumns(columnRemainingRows, columnWidths));
    }
    return createColumns.toString();
}

From source file:com.rvantwisk.gcodegenerator.dialects.RS274.java

public void commentLarge(final String comment) {
    out.append("(").append(StringUtils.rightPad("---", 50, "-")).append(")").append(separator);
    out.append("(").append(comment.trim()).append(")").append(separator);
    out.append("(").append(StringUtils.rightPad("---", 50, "-")).append(")").append(separator);
}

From source file:edu.kit.dama.util.update.types.LibraryDiffInformation.java

@Override
public String toString() {
    StringBuilder b = new StringBuilder();
    String caption = "Library Diff Information";
    int maxWidth = 72;
    b.append(StringUtils.center(caption, maxWidth)).append("\n");
    b.append(StringUtils.rightPad("", maxWidth, "-")).append("\n");
    for (JavaLibrary lib : added) {
        b.append(StringUtils.abbreviateMiddle("(+) " + lib, "[...]", maxWidth)).append("\n");
    }// w ww .j a v  a2  s . co  m
    if (!changed.isEmpty()) {
        b.append("\n");
    }
    for (JavaLibrary lib : changed) {
        b.append(StringUtils.abbreviateMiddle("(U) " + lib, "[...]", maxWidth)).append("\n");
    }
    if (!unknown.isEmpty()) {
        b.append("\n");
    }
    for (JavaLibrary lib : unknown) {
        b.append(StringUtils.abbreviateMiddle("(?) " + lib, "[...]", maxWidth)).append("\n");
    }
    if (!deprecated.isEmpty()) {
        b.append("\n");
    }
    for (JavaLibrary lib : deprecated) {
        b.append(StringUtils.abbreviateMiddle("(-) " + lib, "[...]", maxWidth)).append("\n");
    }
    if (!ignored.isEmpty()) {
        b.append("\n");
    }
    for (File file : ignored) {
        b.append(StringUtils.abbreviateMiddle("(X) " + file.getAbsolutePath(), "[...]", maxWidth)).append("\n");
    }
    b.append("\n");
    b.append(StringUtils.rightPad("", maxWidth, "-")).append("\n");
    b.append("Added     : ").append(StringUtils.leftPad(String.valueOf(added.size()), 6)).append("\n");
    b.append("Changed   : ").append(StringUtils.leftPad(String.valueOf(changed.size()), 6)).append("\n");
    b.append("Deprecated: ").append(StringUtils.leftPad(String.valueOf(deprecated.size()), 6)).append("\n");
    b.append("Unknown   : ").append(StringUtils.leftPad(String.valueOf(unknown.size()), 6)).append("\n");
    b.append("Snapshots : ").append(StringUtils.leftPad(String.valueOf(detectedSnapshots), 6)).append("\n");
    b.append("Ignored   : ").append(StringUtils.leftPad(String.valueOf(ignored.size()), 6)).append("\n");
    b.append("Unchanged : ").append(StringUtils.leftPad(String.valueOf(unchanged.size()), 6)).append("\n");
    b.append(StringUtils.rightPad("", maxWidth, "-")).append("\n");
    return b.toString();
}

From source file:com.rvantwisk.cnctools.data.TaskRunnable.java

public void generateGCode(final ToolDBManager toolDBManager, final CncToolsGCodegenerator gCodeGenerator) {
    if (enabled.get() == true) {
        gCodeGenerator.newSet(true, id, null);
        gCodeGenerator.comment(StringUtils.rightPad("--- Program: " + getName(), 50, "-"));
        milltaskModel.get().generateGCode(toolDBManager, gCodeGenerator, getId());
    } else {//w  w w  . j ava2 s  .com
        gCodeGenerator.newSet(true, id, null);
        gCodeGenerator.comment(StringUtils.rightPad("--- Program: " + getName() + " (disabled)", 50, "-"));
    }
}

From source file:com.cisco.dbds.utils.logging.LogHandler.java

/**
 * Prints the scenario name.// w  w  w  .  j a v a2  s .co  m
 *
 * @param scenarioTags the scenario tags
 * @param testCaseName the test case name
 * @param status the status
 */
public static void printScenarioName(String scenarioTags, String testCaseName, String status) {

    String formattedLine = "";

    String formattedScenarioTags = ">  Scenario tags   : " + scenarioTags;
    String formattedScenarioName = ">  Scenario Name   : " + testCaseName.toUpperCase();
    String formattedStatus = ">  Scenario Status : " + status;

    if (formattedScenarioTags.length() > formattedScenarioName.length()) {
        formattedLine = StringUtils.leftPad("", formattedScenarioTags.length() + 2, '=');

        formattedScenarioTags = StringUtils.rightPad(formattedScenarioTags,
                (formattedScenarioTags.length() + 1), " ") + "<";

        formattedScenarioName = StringUtils.rightPad(formattedScenarioName,
                (formattedScenarioTags.length() - 1), " ") + "<";

        formattedStatus = StringUtils.rightPad(formattedStatus, (formattedScenarioTags.length() - 1), " ")
                + "<";

    } else {
        formattedLine = StringUtils.leftPad("", formattedScenarioName.length() + 2, '=');

        formattedScenarioTags = StringUtils.rightPad(formattedScenarioTags,
                (formattedScenarioName.length() + 1), " ") + "<";

        formattedScenarioName = StringUtils.rightPad(formattedScenarioName,
                (formattedScenarioName.length() + 1), " ") + "<";

        formattedStatus = StringUtils.rightPad(formattedStatus, (formattedScenarioName.length() - 1), " ")
                + "<";
    }

    if (isLoggingEnabled) {
        log.info(formattedLine);
        log.info(formattedScenarioTags);
        log.info(formattedScenarioName);
        log.info(formattedStatus);
        log.info(formattedLine);
    }
    printToConsole(formattedLine + "\n" + formattedScenarioTags + "\n" + formattedScenarioName + "\n"
            + formattedStatus + "\n" + formattedLine);
}