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:org.apache.mahout.utils.clustering.AbstractClusterWriter.java

public static String getTopFeatures(Vector vector, String[] dictionary, int numTerms) {

    StringBuilder sb = new StringBuilder(100);

    for (Pair<String, Double> item : getTopPairs(vector, dictionary, numTerms)) {
        String term = item.getFirst();
        sb.append("\n\t\t");
        sb.append(StringUtils.rightPad(term, 40));
        sb.append("=>");
        sb.append(StringUtils.leftPad(item.getSecond().toString(), 20));
    }/*from  w  w  w .j  av a2s.  c o m*/
    return sb.toString();
}

From source file:org.apache.tinkerpop.gremlin.driver.util.ProfilingApplication.java

public long execute() throws Exception {
    final AtomicInteger tooSlow = new AtomicInteger(0);

    final Client client = cluster.connect();
    final String executionId = "[" + executionName + "]";
    try {// ww w .j  a  v  a  2  s .  c  om
        final CountDownLatch latch = new CountDownLatch(requests);
        client.init();

        final long start = System.nanoTime();
        IntStream.range(0, requests).forEach(i -> client.submitAsync(script).thenAcceptAsync(r -> {
            try {
                r.all().get(tooSlowThreshold, TimeUnit.MILLISECONDS);
            } catch (TimeoutException ex) {
                tooSlow.incrementAndGet();
            } catch (Exception ex) {
                ex.printStackTrace();
            } finally {
                latch.countDown();
            }
        }, executor));

        // finish once all requests are accounted for
        latch.await();

        final long end = System.nanoTime();
        final long total = end - start;
        final double totalSeconds = total / 1000000000d;
        final long requestCount = requests;
        final long reqSec = Math.round(requestCount / totalSeconds);
        System.out.println(String.format(
                StringUtils.rightPad(executionId, 10)
                        + " requests: %s | time(s): %s | req/sec: %s | too slow: %s",
                requestCount, StringUtils.rightPad(String.valueOf(totalSeconds), 14),
                StringUtils.rightPad(String.valueOf(reqSec), 7), tooSlow.get()));
        return reqSec;
    } catch (Exception ex) {
        ex.printStackTrace();
        throw new RuntimeException(ex);
    } finally {
        client.close();
    }
}

From source file:org.broadleafcommerce.common.util.TableCreator.java

public TableCreator addRow(Object[] data) {
    if (data.length != cols.length) {
        throw new IllegalArgumentException("Wrong number of data elements. Needed [" + cols.length + "] "
                + "but received [" + data.length + "]");
    }/*from   w  w w . ja v a 2  s.com*/

    sb.append('|');

    for (int i = 0; i < data.length; i++) {
        String trimmed = StringUtils.left(String.valueOf(data[i]), cols[i].width);
        sb.append(' ').append(StringUtils.rightPad(trimmed, cols[i].width)).append(" |");
    }

    sb.append("\r\n");
    return this;
}

From source file:org.broadleafcommerce.common.util.TableCreator.java

public TableCreator addRow(String rowHeader, Object rowData) {
    String trimmed = StringUtils.left(rowHeader, globalRowHeaderWidth);
    sb.append("| ").append(StringUtils.rightPad(trimmed, globalRowHeaderWidth))
            .append(StringUtils.rightPad(String.valueOf(rowData), rowWidth - globalRowHeaderWidth - 3))
            .append("|\r\n");
    return this;
}

From source file:org.dbgl.test.FilesTest.java

@Test
public void testListShortFiles() throws IOException {
    Set<ShortFile> files = FileUtils.listShortFiles(new File("."));
    assertTrue(files.size() > 0);//from  w w  w .j a  v a 2s. com

    for (ShortFile shortFile : files) {
        System.out.print(StringUtils.rightPad(shortFile.getFormattedName(), 15));
        System.out.print(shortFile.getFile().getName());
        System.out.println();
    }
}

From source file:org.evosuite.ga.stoppingconditions.StoppingConditionImpl.java

/** {@inheritDoc} */
@Override/*  w w  w  . ja v  a  2 s.c o m*/
public String toString() {
    StringBuilder r = new StringBuilder();
    String type = getType();
    type += " :";
    type = StringUtils.rightPad(type, 24);
    r.append(type);
    r.append(getValueString());
    if (isFinished())
        r.append(" Finished!");

    return r.toString();
}

From source file:org.evosuite.ga.stoppingconditions.StoppingConditionImpl.java

/**
 * <p>getValueString</p>/*  w ww  . j a  v a2  s. c  om*/
 *
 * @return a {@link java.lang.String} object.
 */
public String getValueString() {
    String value = NumberFormat.getIntegerInstance().format(getCurrentValue());
    value = StringUtils.leftPad(value, 12);
    String limit = NumberFormat.getIntegerInstance().format(getLimit());
    limit = StringUtils.rightPad(limit, 12);
    return value + " / " + limit;
}

From source file:org.jpos.qi.system.SQLQueryObject.java

@Override
public String toString() {
    try {//from   www .ja v a2  s . c  o  m
        Object res = DB.exec(db -> {
            StringBuilder sb = new StringBuilder("");
            for (int n = 0; n < queries.length; n++) {
                String query = queries[n];
                String title = titles[n];
                int mxrows = maxRows[n];
                sb.append(' ').append(title).append("\n\n");
                db.session().doWork(new Work() {
                    @Override
                    public void execute(Connection connection) throws SQLException {
                        PreparedStatement stmt = connection.prepareStatement(query);
                        ResultSet rs = stmt.executeQuery();
                        ResultSetMetaData md = rs.getMetaData();
                        int cols = md.getColumnCount();
                        String[] header = new String[cols];
                        int[] colsize = new int[cols];
                        for (int i = 1; i <= cols; i++) {
                            header[i - 1] = StringUtils.defaultIfEmpty(md.getColumnLabel(i),
                                    md.getColumnName(i));
                            colsize[i - 1] = header[i - 1].length();
                        }
                        int rows = 0;
                        String[][] out = new String[mxrows][cols];
                        while (rs.next() && rows < mxrows) {
                            for (int i = 1; i <= cols; i++) {
                                out[rows][i - 1] = rs.getString(i);
                                if (out[rows][i - 1] == null)
                                    out[rows][i - 1] = " ";
                                int l = out[rows][i - 1].length();
                                if (colsize[i - 1] < l)
                                    colsize[i - 1] = l;
                            }
                            rows++;
                        }
                        rs.close();
                        stmt.close();
                        StringBuilder sbSep = new StringBuilder(" ");
                        sb.append(' ');
                        for (int i = 1; i <= cols; i++) {
                            if (isNumericDataType(md.getColumnType(i)))
                                sb.append(StringUtils.leftPad(header[i - 1], colsize[i - 1]));
                            else
                                sb.append(StringUtils.rightPad(header[i - 1], colsize[i - 1]));
                            sbSep.append(StringUtils.repeat('-', colsize[i - 1]));
                            sb.append(' ');
                            sbSep.append(' ');
                        }
                        sb.append('\n');
                        sbSep.append('\n');
                        sb.append(sbSep);
                        for (int j = 0; j < rows; j++) {
                            sb.append(' ');
                            for (int i = 1; i <= cols; i++) {
                                if (isNumericDataType(md.getColumnType(i)))
                                    sb.append(StringUtils.leftPad(out[j][i - 1], colsize[i - 1]));
                                else
                                    sb.append(StringUtils.rightPad(out[j][i - 1], colsize[i - 1]));
                                sb.append(' ');
                            }
                            sb.append('\n');
                        }
                        sb.append(sbSep).append('\n');
                    }
                });
            }
            sb.append(" Last refreshed at ").append(new Date());
            return sb;
        });
        return res.toString();
    } catch (Exception e) {
        QI.getQI().getLog().error(e);
        return e.toString();
    }

}

From source file:org.kalypso.commons.eclipse.jface.viewers.TabViewer.java

private void updateItemLabel(final CTabItem item, final Object element) {
    final ITabControlProvider controlProvider = getLabelProvider();

    item.setToolTipText(null);/*from  w  w  w  . j a v a 2  s.c  om*/
    final String text = controlProvider.getText(element);
    if (text != null) {
        final String label = shortenLabel(text);
        item.setText(StringUtils.rightPad(label, m_minLabelLength));
        if (!label.equals(text))
            item.setToolTipText(text);
    }
}

From source file:org.kalypso.ogc.gml.featureview.control.FeatureTabItem.java

public void updateControl() {
    final Feature feature = getFeature();
    final String text = FeatureHelper.getAnnotationValue(feature, IAnnotation.ANNO_LABEL);

    /* Ensure minimum length */
    final int MIN_TITLE_LENGTH = 8;
    final int MAX_TITLE_LENGTH = 30;

    final String paddedText = StringUtils.rightPad(text, MIN_TITLE_LENGTH);

    /* Ensure maximum length */
    final String abreviatedText = StringUtils.abbreviate(paddedText, MAX_TITLE_LENGTH);

    m_item.setText(abreviatedText);/*from  w ww.  j a  v a 2 s  .  c  o  m*/
    m_item.setToolTipText(text);

    m_fc.updateControl();
}