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

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

Introduction

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

Prototype

public static String rightPad(String str, int size) 

Source Link

Document

Right pad a String with spaces (' ').

Usage

From source file:com.cloudbees.plugins.credentials.cli.ListCredentialsCommand.java

/**
 * {@inheritDoc}/*from   ww w.  j ava  2s . co m*/
 */
@Override
protected int run() throws Exception {
    store.checkPermission(CredentialsProvider.VIEW);
    List<Domain> domains = store.getDomains();
    for (Domain domain : domains) {
        List<Credentials> credentials = store.getCredentials(domain);
        Map<String, String> nameById = new LinkedHashMap<String, String>(credentials.size());
        int maxIdLen = "# of Credentials".length(), maxNameLen = 0;
        int index = 0;
        for (Credentials c : credentials) {
            String id;
            if (c instanceof IdCredentials) {
                id = ((IdCredentials) c).getId();
            } else {
                while (nameById.containsKey("index-" + index)) {
                    index++;
                }
                id = "index-" + index;
                index++;
            }
            String name = CredentialsNameProvider.name(c);
            nameById.put(id, name);
            maxIdLen = Math.max(maxIdLen, id.length());
            maxNameLen = Math.max(maxNameLen, name.length());
        }
        stdout.println(StringUtils.repeat("=", maxIdLen + maxNameLen + 1));
        stdout.println(StringUtils.rightPad("Domain", maxIdLen) + " "
                + (domain.isGlobal() ? "(global)" : domain.getName()));
        stdout.println(StringUtils.rightPad("Description", maxIdLen) + " "
                + StringUtils.defaultString(domain.getDescription()));
        stdout.println(StringUtils.rightPad("# of Credentials", maxIdLen) + " " + credentials.size());
        stdout.println(StringUtils.repeat("=", maxIdLen + maxNameLen + 1));
        stdout.println(StringUtils.rightPad("Id", maxIdLen) + " Name");
        stdout.println(StringUtils.repeat("=", maxIdLen) + " " + StringUtils.repeat("=", maxNameLen));
        for (Map.Entry<String, String> entry : nameById.entrySet()) {
            stdout.println(StringUtils.rightPad(entry.getKey(), maxIdLen) + " " + entry.getValue());
        }
        stdout.println(StringUtils.repeat("=", maxIdLen + maxNameLen + 1));
        stdout.println();
    }
    return 0;
}

From source file:com.jgui.ttscrape.Show.java

/**
 * Format the show with the start time, title, channel name, number, category and rating.
 * @return string representing this show.
 *//*from  ww w  .j  a v a 2  s .co  m*/
public String format() {
    StringBuffer sb = new StringBuffer();

    DateFormat df = new SimpleDateFormat("MM/dd/yyyy HH:mm");
    sb.append(StringUtils.rightPad(df.format(startTime), 20));
    sb.append(StringUtils.rightPad(title, 30));
    sb.append("\t");
    sb.append(channelName + " " + channelNumber);
    sb.append("\t");
    sb.append(category);
    sb.append("\t");
    sb.append(stars);

    return sb.toString();
}

From source file:com.opengamma.integration.viewer.status.impl.ViewStatusCalculationWorker.java

public ViewStatusCalculationWorker(final ToolContext toolContext, UniqueId portfolioId,
        final ViewStatusOption option, final ExecutorService executorService) {
    ArgumentChecker.notNull(toolContext, "toolContex");
    ArgumentChecker.notNull(portfolioId, "portfolioId");
    ArgumentChecker.notNull(option, "option");
    ArgumentChecker.notNull(option.getUser(), "option.user");
    ArgumentChecker.notNull(option.getMarketDataSpecification(), "option.marketDataSpecification");
    ArgumentChecker.notNull(executorService, "executorService");

    validateComponentsInToolContext(toolContext);
    _portfolioId = portfolioId;//from   w ww.  ja v  a  2  s . co  m
    _user = option.getUser();
    _marketDataSpecification = option.getMarketDataSpecification();
    Map<String, Collection<String>> valueRequirementBySecType = scanValueRequirementBySecType(portfolioId,
            toolContext);
    if (s_logger.isDebugEnabled()) {
        StringBuilder strBuf = new StringBuilder();
        for (String securityType : Sets.newTreeSet(valueRequirementBySecType.keySet())) {
            Set<String> valueNames = Sets.newTreeSet(valueRequirementBySecType.get(securityType));
            strBuf.append(
                    String.format("%s\t%s\n", StringUtils.rightPad(securityType, 40), valueNames.toString()));
        }
        s_logger.debug("\n{}\n", strBuf.toString());
    }
    _toolContext = toolContext;
    _executor = executorService;
    _valueRequirementBySecType = valueRequirementBySecType;
}

From source file:com.ning.maven.plugins.dependencyversionscheck.DependencyVersionsListMojo.java

protected void doExecute() throws Exception {
    checkScope();/* w w  w.jav a 2s  .co m*/

    final Map resolutionMap = buildResolutionMap(scope);

    LOG.info("{} dependencies for scope '{}':", (directOnly ? "Direct" : "Transitive"), scope);

    for (final Iterator it = resolutionMap.entrySet().iterator(); it.hasNext();) {
        final Map.Entry entry = (Map.Entry) it.next();
        final String artifactName = (String) entry.getKey();
        final List resolutions = (List) entry.getValue();

        if (CollectionUtils.isEmpty(resolutions)) {
            LOG.warn("No resolutions for '{}', this should never happen!", artifactName);
            continue; // for
        }

        final VersionResolution resolution = (VersionResolution) resolutions.get(0);

        // Map from version to VersionInformation
        final Map versionMap = new TreeMap();

        boolean foundConflict = false;
        boolean foundDirectDependency = false;

        for (Iterator resolutionIt = resolutions.iterator(); resolutionIt.hasNext();) {
            final VersionResolution versionResolution = (VersionResolution) resolutionIt.next();
            final String expectedVersion = versionResolution.getExpectedVersion().getSelectedVersion();

            VersionInformation versionInformation = (VersionInformation) versionMap.get(expectedVersion);
            if (versionInformation == null) {
                versionInformation = new VersionInformation(expectedVersion);
                versionMap.put(expectedVersion, versionInformation);
            }

            if (versionResolution.isConflict()) {
                versionInformation.setConflict(true);
                foundConflict = true;
            }

            if (versionResolution.isDirectDependency()) {
                versionInformation.setDirectDependency(true);
                foundDirectDependency = true;
            }
        }

        if (conflictsOnly && !foundConflict) {
            continue; // for;
        }

        if (directOnly && !foundDirectDependency) {
            continue; // for;
        }

        final StringBuilder result = new StringBuilder(StringUtils.rightPad(artifactName + ": ", maxLen + 2));
        result.append(resolution.getDependencyName()).append("-")
                .append(resolution.getActualVersion().getSelectedVersion());
        result.append(" (");

        for (Iterator versionIt = versionMap.values().iterator(); versionIt.hasNext();) {
            VersionInformation versionInformation = (VersionInformation) versionIt.next();

            result.append(versionInformation);

            if (versionIt.hasNext()) {
                result.append(", ");
            }
        }

        result.append(")");

        LOG.info(result.toString());
    }
}

From source file:io.pcp.parfait.benchmark.CPUThreadTest.java

private String formatCpuLookupMethod(CPUThreadTestRunner.CpuLookupMethod cpuLookupMethod) {
    return StringUtils.rightPad(cpuLookupMethod.name(),
            CPUThreadTestRunner.CpuLookupMethod.USE_CURRENT_THREAD_CPU_TIME.name().length());
}

From source file:com.mosso.client.cloudfiles.sample.FilesList.java

private static void printContainersAll(boolean humanReadable)
        throws IOException, HttpException, FilesException {
    FilesClient client = new FilesClient();
    if (client.login()) {
        List<FilesContainer> containers = client.listContainers();
        System.out.println(client.getAccount() + " containers: ");
        for (FilesContainer value : containers) {
            FilesContainerInfo info = value.getInfo();
            System.out.println("\t" + value.getName() + " - " + info.getObjectCount() + " objects:");

            List<FilesObject> objects = value.getObjects();
            for (FilesObject obj : objects) {
                if (humanReadable)
                    System.out.println("\t\t" + StringUtils.rightPad(obj.getName(), 35) + obj.getSizeString());
                else
                    System.out.println(
                            "\t\t" + StringUtils.rightPad(obj.getName(), 35) + obj.getSize() + "Bytes");
            }/* ww  w  .  j ava 2 s.  c om*/

            if (humanReadable) {
                System.out.println("\tTotal Size: " + info.getTotalSize() / 1024 + "KB\n");
            } else
                System.out.println("\tTotal Size: " + info.getTotalSize() + "Bytes\n");
        }
    }
}

From source file:com.srikanthps.HbaseBenchmarking.java

private static void runTest(Class rowCreatorClass, long startingRowKey, int numRecordsToInsert,
        long numThreadsToUse, String data)
        throws InterruptedException, InstantiationException, IllegalAccessException {

    timingStats.clear();/*from  w  w  w . ja  v  a 2s.  c om*/

    int numRecordsPerThread = (int) Math.ceil(((double) numRecordsToInsert) / numThreadsToUse);

    List<Thread> threads = new ArrayList<Thread>();
    for (int i = 0; i < numThreadsToUse; i++) {
        RowCreator c = (RowCreator) rowCreatorClass.newInstance();
        c.setData(data);
        c.setNextRowkey(startingRowKey);
        c.setNumRecordsToInsert(numRecordsPerThread);

        Thread t = new Thread(c);
        threads.add(t);
        t.start();
    }

    for (int i = 0; i < numThreadsToUse; i++) {
        threads.get(i).join();
    }

    System.out.println(StringUtils.rightPad(rowCreatorClass.newInstance().toString(), 50) + ","
            + format(numThreadsToUse, VALUE_LEFT_PAD) + "," + format(timingStats.getN(), VALUE_LEFT_PAD) + ","
            + format(timingStats.getMean(), VALUE_LEFT_PAD) + ","
            + format(timingStats.getStandardDeviation(), VALUE_LEFT_PAD) + ","
            + format(timingStats.getMax(), VALUE_LEFT_PAD) + "," + format(timingStats.getMin(), VALUE_LEFT_PAD)
            + "," + format(timingStats.getPercentile(80.0), VALUE_LEFT_PAD) + ","
            + format(timingStats.getPercentile(90.0), VALUE_LEFT_PAD));
}

From source file:ca.on.gov.jus.icon.common.iconcodetables.IconCodeTablesManager.java

private Object populateIconCodeTable(String iconCodeTableKey) throws Exception {
    logger.info("IN populateIconCodeTable");
    boolean transactionRejected = false;
    IconCodeTable iconCodeTable = null;/*w  w  w  .  ja v a  2 s .c  om*/

    if ("ICON_CodeTablesList".equalsIgnoreCase(iconCodeTableKey)) {
        iconCodeTable = getICONCodesTableList();
        iconCodeTables.put(iconCodeTableKey, iconCodeTable);
        return iconCodeTable;
    }

    //This will go to ICON Main menu first then to table Man main menu
    //Simply call this
    this.goToTableManagementMainScreen();

    //Create an instance of the main Macro
    TableManagementSystemMain2_Access tableManagementSystemMain2_Access = new TableManagementSystemMain2_Access();

    //Set the required values on it
    tableManagementSystemMain2_Access.setTableId(StringUtils.rightPad(iconCodeTableKey.trim(), 8));
    tableManagementSystemMain2_Access
            .setTablePass(StringUtils.rightPad(getTablePassword(iconCodeTableKey).trim(), 8));
    //Execute the action/Macro
    PageCodeBase.executeEJB(tableManagementSystemMain2_Access, getSessionScope());

    //Get the returned data
    String returnMessage = tableManagementSystemMain2_Access.getReturnMessage().trim();

    try {
        //Error or bad password - display msg
        if (!returnMessage.equals("")) {
            logger.log(Level.SEVERE, "ERROR: " + returnMessage);
            //found TRANSACTION REJECTED
            if (returnMessage.indexOf("TRANSACTION REJECTED") != -1) {
                transactionRejected = true;
                TableManagementSystemUnlock_Access tableManagementSystemUnlock_Access = new TableManagementSystemUnlock_Access();
                PageCodeBase.executeEJB(tableManagementSystemUnlock_Access, getSessionScope());
            } else {
                //Go back to the main menu after error
                TableManagementSystemGoMain_Access tableManagementSystemGoMain_Access = new TableManagementSystemGoMain_Access();
                PageCodeBase.executeEJB(tableManagementSystemGoMain_Access, getSessionScope());
            }
            throw new Exception(returnMessage);
        }

        String iconCodeTableName = ((IconCodeTable) getIconCodeTable("ICON_CodeTablesList").getCodeTableValues()
                .get(iconCodeTableKey)).getCodeTableName();

        iconCodeTable = new IconCodeTable(iconCodeTableKey, iconCodeTableName);
        String hasMore = "";
        do {
            //NO Error, we can go ahead then get the data  
            TableManagementSystemGetData_Access tableManagementSystemGetData_Access = new TableManagementSystemGetData_Access();

            //Execute the action/Macro
            PageCodeBase.executeEJB(tableManagementSystemGetData_Access, getSessionScope());

            hasMore = tableManagementSystemGetData_Access.getMore().trim();
            //Must declare a local variable to get the number
            //better for performance vs. calling EJB all the time
            int numberOfEntries = tableManagementSystemGetData_Access.getTableEntryListEntryCode().length;

            for (int i = 0; i < numberOfEntries; i++) {
                if (tableManagementSystemGetData_Access.getTableEntryListEntryCode(i).trim().length() > 0) {

                    iconCodeTable.getCodeTableValues().put(
                            tableManagementSystemGetData_Access.getTableEntryListEntryCode(i).trim(),
                            tableManagementSystemGetData_Access.getTableEntryListEntryValue(i).trim());

                    /* Since the table "Disbursement GL Acct X-Ref" (ICDSXREF)  
                     * is an exception to all the other tables and has an  
                     * additional column then we need to do some additional  
                     * work to extract the third column. For easier solution  
                     * the choice was to extract the value in the Java app  
                     * vs. creating a new Macro or modifying the existing one.
                     */
                    //                        if("ICDSXREF".equalsIgnoreCase(this.getViewIconTablesManagedBean().getSelectedTableId())) {
                    //                           this.processCustomRecord(tableManagementSystemGetData_Access, singleRecord, i);
                    //                  }
                    //                  this.getViewIconTablesManagedBean().getIconTableDataRecordList().add(singleRecord);
                }
            } //end for

            //if there is more data then call Page Down Macro
            if (!hasMore.equals("")) {
                TableManagementSystemPageDown_Access tableManagementSystemPageDown_Access = new TableManagementSystemPageDown_Access();
                PageCodeBase.executeEJB(tableManagementSystemPageDown_Access, getSessionScope());
            }

        } while (!hasMore.equals("")); //end do

        iconCodeTables.put(iconCodeTableKey, iconCodeTable);

        //At end of the while (no more data) we go back to the main screen
        TableManagementSystemGoMain_Access tableManagementSystemGoMain_Access = new TableManagementSystemGoMain_Access();
        PageCodeBase.executeEJB(tableManagementSystemGoMain_Access, getSessionScope());

    } finally {
        //Finally go to ICON main menu so that it is ready for next request
        if (false == transactionRejected) {
            TableManagementSystemGoIconMain_Access tableManagementSystemGoIconMain_Access = new TableManagementSystemGoIconMain_Access();
            PageCodeBase.executeEJB(tableManagementSystemGoIconMain_Access, getSessionScope());
        }
    }
    return iconCodeTable;
}

From source file:com.alibaba.dubbo.util.KetamaNodeLocatorTest.java

@Test
public void testDistribution() {
    final int nodeSize = 10;
    final int keySize = 10000;
    final List<String> nodes = generateRandomStrings(nodeSize);

    final long start1 = System.currentTimeMillis();
    final KetamaNodeLocator locator = new KetamaNodeLocator(nodes);

    // Make sure the initialization doesn't take too long.
    assertTrue((System.currentTimeMillis() - start1) < 100);

    final int[] counts = new int[nodeSize];
    for (int ix = 0; ix < nodeSize; ix++) {
        counts[ix] = 0;/* ww w  .  j av a2s. c om*/
    }

    final List<String> keys = generateRandomStrings(keySize);

    for (final String key : keys) {
        final String primary = locator.getPrimary(key);
        counts[nodes.indexOf(primary)] += 1;
    }

    // Give about a 30% leeway each way...
    final int min = (keySize * 7) / (nodeSize * 10);
    final int max = (keySize * 13) / (nodeSize * 10);
    int total = 0;
    boolean error = false;
    final StringBuilder sb = new StringBuilder("Key distribution error - \n");

    for (int ix = 0; ix < nodeSize; ix++) {
        if (counts[ix] < min || counts[ix] > max) {
            error = true;
            sb.append("  !!  ");
        } else {
            sb.append("      ");
        }
        sb.append(StringUtils.rightPad(nodes.get(ix), 12)).append(": ").append(counts[ix]).append("\n");
        total += counts[ix];
    }
    // Make sure we didn't miss any keys returning values.
    assertEquals(keySize, total);

    //        System.out.println(sb.toString());
    if (error) {
        fail(sb.toString());
    }
}

From source file:de.codesourcery.eve.skills.ui.components.impl.ItemBrowserComponent.java

private String toString(AttributeCategory cat, List<ItemAttribute> attrs) {

    int maxNameLen = 0;
    for (ItemAttribute attr : attrs) {
        maxNameLen = Math.max(maxNameLen, getAttributeDisplayName(attr).length());
    }/*w w w .j a  v a 2 s.c o m*/
    String result = "\n============\n" + cat.getName() + "\n============";

    final List<ItemAttribute> sorted = new ArrayList<>(attrs);
    Collections.sort(sorted, new Comparator<ItemAttribute>() {

        @Override
        public int compare(ItemAttribute o1, ItemAttribute o2) {
            return getAttributeDisplayName(o1).compareTo(getAttributeDisplayName(o2));
        }
    });
    for (Iterator<ItemAttribute> it = sorted.iterator(); it.hasNext();) {
        ItemAttribute itemAttribute = it.next();
        result += "\n" + StringUtils.rightPad(getAttributeDisplayName(itemAttribute), maxNameLen) + " : "
                + getAttributeDisplayValue(itemAttribute);
    }
    return result;
}