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:org.pepstock.jem.node.system.Ps.java

/**
  * Formats list of string, result of gathering process info.<br>
  * One list for one process.//from  ww  w.  ja v  a2  s  .  co m
  * 
  * @param info collection of info for process 
  * @return info string representation of list
  */
public static String join(List<String> info) {
    StringBuilder buf = new StringBuilder();
    // gets amount of headers
    for (int i = 0; i < Top.HEADER.length; i++) {
        // gets length of headers for padding
        int len = Top.HEADER[i].length();
        buf.append(StringUtils.rightPad(info.get(i), len, ' ')).append(' ');
    }
    return buf.toString();
}

From source file:org.syphr.mythtv.test.ConsoleFormatter.java

@Override
public String format(LogRecord record) {
    StringBuilder formattedRecord = new StringBuilder(
            StringUtils.rightPad(record.getSourceClassName(), 65, '.'));
    formattedRecord.append(" | ");

    String message = record.getMessage();
    formattedRecord.append(message != null ? message : " no message provided");
    formattedRecord.append(NEWLINE);/*from  ww  w. j  a  v  a 2 s .  co m*/

    Throwable thrown = record.getThrown();
    if (thrown != null) {
        StringWriter sw = new StringWriter();
        thrown.printStackTrace(new PrintWriter(sw));
        formattedRecord.append(sw);
    }

    return formattedRecord.toString();
}

From source file:PositionKeeper.procedures.Initialize.java

public long run(int maxAccounts, int maxProducts) {
    voltQueueSQL(checkStmt, EXPECT_SCALAR_LONG);
    long existingAccount = voltExecuteSQL()[0].asScalarLong();

    // if the data is initialized, return the account count
    if (existingAccount != 0)
        return existingAccount;

    // initialize the data
    String User = "TestAccount";
    String accountId = null;//from w w w . j  a  v  a  2 s . c o m
    String accountName = null;
    String accountAddress = null;
    String accountTin = null;
    for (int i = 1; i <= maxAccounts; i++) {
        accountId = "account" + i;
        accountName = "peter" + i;
        accountAddress = i + " Holland street";
        accountTin = String.valueOf(i);
        voltQueueSQL(insertAccountStmt, EXPECT_SCALAR_MATCH(1), accountId, accountName, accountAddress,
                accountTin, User, new TimestampType(new Date()), User, new TimestampType(new Date()));
    }
    voltExecuteSQL();

    String productCusip = null;
    String productName = null;
    String productIsin = null;
    String productTicker = null;
    String productRic = null;
    String productCcy = null;
    String productCoi = null;
    for (int i = 0; i < maxProducts; i++) {
        productCusip = "cusip" + i;
        productName = "product" + i;
        productIsin = StringUtils.rightPad(String.valueOf(i), 12, "0");
        productTicker = "MSFT";
        productRic = ".SPX";
        productCcy = "USD";
        productCoi = "XXX";
        voltQueueSQL(insertProductStmt, EXPECT_SCALAR_MATCH(1), productCusip, productName, productIsin,
                productTicker, productRic, productCcy, productCoi, User, new TimestampType(new Date()), User,
                new TimestampType(new Date()));
    }
    voltExecuteSQL();

    return maxAccounts;
}

From source file:rems.Program.java

private static String[] breakDownStr(String inStr, int maxWidth, int maxHeight, Graphics g, float mxTxtWdth) {
    String[] nwStr = new String[maxHeight];
    int hghtCntr = 0;
    if (maxWidth < 3 && maxWidth > 1) {
        maxWidth = 3;/*  w  ww . jav  a 2 s .  co  m*/
    } else if (maxWidth == 1) {
        maxWidth = 1;
        for (int c = 0; c < maxHeight; c++) {
            nwStr[c] += StringUtils.rightPad("", maxWidth, ' ');
        }
        return nwStr;
    }

    inStr = inStr.replace("\r\n", "");
    inStr = inStr.replace("\n", "");
    //String steps = "";
    for (int c = 0; c < maxHeight; c++) {
        nwStr[c] += StringUtils.rightPad("", maxWidth, ' ');
    }
    Font nwFont = new Font("Courier New", Font.PLAIN, 11);
    String[] mystr = Global.breakTxtDown(inStr, mxTxtWdth, nwFont, g);
    for (int c = 0; c < mystr.length; c++) {
        nwStr[c] = StringUtils.rightPad(mystr[c], maxWidth, ' ');
        if (c >= maxHeight - 1) {
            return nwStr;
        }
    }
    return nwStr;
}

From source file:rems.Program.java

public static String formatDtSt(ResultSet dtst, String rptTitle, String[] colsToGrp, String[] colsToCnt,
        String[] colsToSum, String[] colsToAvrg, String[] colsToFrmt) {
    try {//from  www. jav  a  2s.  co  m
        DecimalFormat myFormatter = new DecimalFormat("###,##0.00");
        DecimalFormat myFormatter2 = new DecimalFormat("###,##0");
        String finalStr = rptTitle.toUpperCase();
        finalStr += "\r\n\r\n";
        ResultSetMetaData dtstmd = dtst.getMetaData();
        dtst.last();
        int ttlRws = dtst.getRow();
        dtst.beforeFirst();
        int colCnt = dtstmd.getColumnCount();

        long[] colcntVals = new long[colCnt];
        double[] colsumVals = new double[colCnt];
        double[] colavrgVals = new double[colCnt];
        finalStr += "|";
        for (int f = 0; f < colCnt; f++) {
            int colLen = dtstmd.getColumnName(f + 1).length();
            if (colLen >= 3) {
                finalStr += StringUtils.rightPad("=", colLen, '=');
                finalStr += "|";
            }
        }
        finalStr += "\r\n";
        finalStr += "|";
        for (int e = 0; e < colCnt; e++) {
            int colLen = dtstmd.getColumnName(e + 1).length();
            if (colLen >= 3) {
                if (Program.mustColBeFrmtd(String.valueOf(e), colsToFrmt) == true) {
                    finalStr += StringUtils.leftPad(dtstmd.getColumnName(e + 1).substring(0, colLen - 2).trim(),
                            colLen, ' ');
                } else {
                    finalStr += StringUtils.leftPad(dtstmd.getColumnName(e + 1).substring(0, colLen - 2),
                            colLen, ' ');
                }
                finalStr += "|";
            }
        }
        finalStr += "\r\n";
        finalStr += "|";
        for (int f = 0; f < colCnt; f++) {
            int colLen = dtstmd.getColumnName(f + 1).length();
            if (colLen >= 3) {
                finalStr += StringUtils.rightPad("=", colLen, '=');
                finalStr += "|";
            }
        }
        finalStr += "\r\n";
        String[][] prevRowVal = new String[ttlRws][colCnt];
        for (int i = 0; i < ttlRws; i++) {
            String[][] lineFormat = new String[colCnt][];
            dtst.next();
            for (int a = 0; a < colCnt; a++) {
                double nwval = 0;
                prevRowVal[i][a] = dtst.getString(a + 1);

                boolean mstgrp = mustColBeGrpd(String.valueOf(a), colsToGrp);
                if (mustColBeCntd(String.valueOf(a), colsToCnt) == true) {
                    if ((i > 0) && (prevRowVal[i - 1][a].equals(dtst.getString(a + 1))) && (mstgrp == true)) {
                    } else {
                        colcntVals[a] += 1;
                    }
                } else if (mustColBeSumd(String.valueOf(a), colsToSum) == true) {
                    nwval = Double.parseDouble(dtst.getString(a + 1));
                    if ((i > 0) && (prevRowVal[i - 1][a].equals(dtst.getString(a + 1))) && (mstgrp == true)) {
                    } else {
                        colsumVals[a] += nwval;
                    }
                } else if (mustColBeAvrgd(String.valueOf(a), colsToAvrg) == true) {
                    nwval = Double.parseDouble(dtst.getString(a + 1));
                    if ((i > 0) && (prevRowVal[i - 1][a].equals(dtst.getString(a + 1))) && (mstgrp == true)) {
                    } else {
                        colcntVals[a] += 1;
                        colsumVals[a] += nwval;
                    }
                }

                int colLen = dtstmd.getColumnName(a + 1).length();
                String[] arry;
                BufferedImage bi;
                Graphics g; // stands for Buffered Image Graphics
                Toolkit toolkit;
                MediaTracker tracker;
                if (colLen >= 3) {
                    if ((i > 0) && (prevRowVal[i - 1][a].equals(dtst.getString(a + 1)))
                            && (mustColBeGrpd(String.valueOf(a), colsToGrp) == true)) {
                        toolkit = Toolkit.getDefaultToolkit();
                        Image img = toolkit.getImage(Global.appStatPath + "/staffs.png");
                        Font nwFont = new Font("Courier New", 11, Font.PLAIN);
                        bi = new BufferedImage(70, 70, BufferedImage.TYPE_INT_RGB);
                        g = bi.getGraphics();
                        float ght = (float) g.getFontMetrics(nwFont).stringWidth(
                                StringUtils.rightPad(dtstmd.getColumnName(a + 1).trim(), colLen, '='));
                        float ght1 = (float) g.getFontMetrics(nwFont).stringWidth("=");
                        arry = breakDownStr("    ", colLen, 25, g, ght - ght1);
                    } else {
                        toolkit = Toolkit.getDefaultToolkit();
                        Image img = toolkit.getImage(Global.appStatPath + "/staffs.png");
                        Font nwFont = new Font("Courier New", 11, Font.PLAIN);
                        bi = new BufferedImage(70, 70, BufferedImage.TYPE_INT_RGB);
                        g = bi.getGraphics();
                        float ght = (float) g.getFontMetrics(nwFont).stringWidth(
                                StringUtils.rightPad(dtstmd.getColumnName(a + 1).trim(), colLen, '='));
                        float ght1 = (float) g.getFontMetrics(nwFont).stringWidth("=");
                        arry = breakDownStr(dtst.getString(a + 1), colLen, 25, g, ght - ght1);
                    }
                    lineFormat[a] = arry;
                }
            }
            String frshLn = "";
            for (int c = 0; c < 25; c++) {
                String frsh = "|";
                for (int b = 0; b < colCnt; b++) {
                    int colLen = dtstmd.getColumnName(b + 1).length();
                    if (colLen >= 3) {
                        if (Program.mustColBeFrmtd(String.valueOf(b), colsToFrmt) == true) {
                            double num = Double.parseDouble(lineFormat[b][c].trim());
                            if (!lineFormat[b][c].trim().equals("")) {
                                frsh += StringUtils.leftPad(myFormatter.format(num), colLen, ' ').substring(0,
                                        colLen);//.trim().PadRight(60, ' ')
                            } else {
                                frsh += lineFormat[b][c].substring(0, colLen); //.trim().PadRight(60, ' ')
                            }
                        } else {
                            frsh += lineFormat[b][c].substring(0, colLen); //.trim().PadRight(60, ' ')
                        }
                        frsh += "|";
                    }
                }
                String nwtst = frsh;
                frsh += "\r\n";
                if (nwtst.replace("|", " ").trim().equals("")) {
                    c = 24;
                } else {
                    frshLn += frsh;
                }
            }
            finalStr += frshLn;
        }
        finalStr += "\r\n";
        finalStr += "|";
        for (int f = 0; f < colCnt; f++) {
            int colLen = dtstmd.getColumnName(f + 1).length();
            if (colLen >= 3) {
                finalStr += StringUtils.rightPad("=", colLen, '=');
                finalStr += "|";
            }
        }
        finalStr += "\r\n";
        finalStr += "|";
        //Populate Counts/Sums/Averages
        for (int f = 0; f < colCnt; f++) {
            int colLen = dtstmd.getColumnName(f + 1).length();
            if (colLen >= 3) {
                if (mustColBeCntd(String.valueOf(f), colsToCnt) == true) {
                    if (mustColBeFrmtd(String.valueOf(f), colsToFrmt) == true) {
                        finalStr += "Count = " + StringUtils
                                .leftPad(myFormatter2.format(colcntVals[f]), colLen, ' ').substring(0, colLen);
                    } else {
                        finalStr += "Count = " + StringUtils
                                .rightPad(String.valueOf(colcntVals[f]), colLen, ' ').substring(0, colLen);
                    }
                } else if (mustColBeSumd(String.valueOf(f), colsToSum) == true) {
                    if (mustColBeFrmtd(String.valueOf(f), colsToFrmt) == true) {
                        finalStr += "Sum = " + StringUtils
                                .leftPad(myFormatter.format(colsumVals[f]), colLen, ' ').substring(0, colLen);
                    } else {
                        finalStr += "Sum = " + StringUtils.rightPad(String.valueOf(colsumVals[f]), colLen, ' ')
                                .substring(0, colLen);
                    }
                } else if (mustColBeAvrgd(String.valueOf(f), colsToAvrg) == true) {
                    if (mustColBeFrmtd(String.valueOf(f), colsToFrmt) == true) {
                        finalStr += "Average = " + StringUtils
                                .leftPad((myFormatter.format(colsumVals[f] / colcntVals[f])), colLen, ' ')
                                .substring(0, colLen);
                    } else {
                        finalStr += "Average = " + StringUtils
                                .rightPad((String.valueOf(colsumVals[f] / colcntVals[f])), colLen, ' ')
                                .substring(0, colLen);
                    }
                } else {
                    finalStr += StringUtils.rightPad(" ", colLen, ' ').substring(0, colLen);
                }
                finalStr += "|";
            }
        }
        finalStr += "\r\n";
        finalStr += "|";
        for (int f = 0; f < colCnt; f++) {
            int colLen = dtstmd.getColumnName(f + 1).length();
            if (colLen >= 3) {
                finalStr += StringUtils.rightPad("-", colLen, '-').substring(0, colLen);
                finalStr += "|";
            }
        }
        finalStr += "\r\n";
        return finalStr;
    } catch (SQLException ex) {
        return "";
    } catch (NumberFormatException ex) {
        return "";
    }
}

From source file:ubic.basecode.graphics.MatrixDisplay.java

/**
 * Pads a string to the maxColumnLength. If it is over the maxColumnLength, it abbreviates it to the maxColumnLength
 * //from  w  w w  .j a v  a 2  s.  c  o m
 * @param str
 * @return
 */
private String padColumnString(String str) {
    String paddedstr = StringUtils.abbreviate(str, m_maxColumnLength);
    paddedstr = StringUtils.rightPad(str, m_maxColumnLength, " ");
    return paddedstr;
}