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

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

Introduction

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

Prototype

public static String leftPad(String str, int size) 

Source Link

Document

Left pad a String with spaces (' ').

Usage

From source file:com.srikanthps.HbaseBenchmarking.java

private static String format(Double d, int pad) {
    return StringUtils.leftPad(String.format("%.2f", d), pad);
}

From source file:ch.algotrader.simulation.SimulationResultFormatter.java

public void formatLong(final Appendable buffer, final SimulationResultVO resultVO,
        final CommonConfig commonConfig) throws IOException {

    buffer.append("execution time (min): " + (new DecimalFormat("0.00")).format(resultVO.getMins()) + "\r\n");

    if (resultVO.getAllTrades().getCount() == 0) {
        buffer.append("no trades took place! \r\n");
        return;/*from   w  w w.  j  a  v a  2 s .co m*/
    }

    buffer.append("dataSet: " + commonConfig.getDataSet() + "\r\n");

    double netLiqValue = resultVO.getNetLiqValue();
    buffer.append("netLiqValue=" + twoDigitFormat.format(netLiqValue) + "\r\n");

    // monthlyPerformances
    Collection<PeriodPerformanceVO> monthlyPerformances = resultVO.getMonthlyPerformances();
    double maxDrawDownM = 0d;
    double bestMonthlyPerformance = Double.NEGATIVE_INFINITY;
    int positiveMonths = 0;
    int negativeMonths = 0;
    if ((monthlyPerformances != null)) {
        StringBuilder dateBuffer = new StringBuilder("month-year:         ");
        StringBuilder performanceBuffer = new StringBuilder("monthlyPerformance: ");
        for (PeriodPerformanceVO monthlyPerformance : monthlyPerformances) {
            maxDrawDownM = Math.min(maxDrawDownM, monthlyPerformance.getValue());
            bestMonthlyPerformance = Math.max(bestMonthlyPerformance, monthlyPerformance.getValue());
            monthFormat.formatTo(DateTimeLegacy.toLocalDate(monthlyPerformance.getDate()), dateBuffer);
            performanceBuffer.append(
                    StringUtils.leftPad(twoDigitFormat.format(monthlyPerformance.getValue() * 100), 6) + "% ");
            if (monthlyPerformance.getValue() > 0) {
                positiveMonths++;
            } else {
                negativeMonths++;
            }
        }
        buffer.append(dateBuffer.toString() + "\r\n");
        buffer.append(performanceBuffer.toString() + "\r\n");
    }

    // yearlyPerformances
    int positiveYears = 0;
    int negativeYears = 0;
    Collection<PeriodPerformanceVO> yearlyPerformances = resultVO.getYearlyPerformances();
    if ((yearlyPerformances != null)) {
        StringBuilder dateBuffer = new StringBuilder("year:               ");
        StringBuilder performanceBuffer = new StringBuilder("yearlyPerformance:  ");
        for (PeriodPerformanceVO yearlyPerformance : yearlyPerformances) {
            yearFormat.formatTo(DateTimeLegacy.toGMTDate(yearlyPerformance.getDate()), dateBuffer);
            performanceBuffer.append(
                    StringUtils.leftPad(twoDigitFormat.format(yearlyPerformance.getValue() * 100), 6) + "% ");
            if (yearlyPerformance.getValue() > 0) {
                positiveYears++;
            } else {
                negativeYears++;
            }
        }
        buffer.append(dateBuffer.toString() + "\r\n");
        buffer.append(performanceBuffer.toString() + "\r\n");
    }

    if ((monthlyPerformances != null)) {
        buffer.append("posMonths=" + positiveMonths + " negMonths=" + negativeMonths);
        if ((yearlyPerformances != null)) {
            buffer.append(" posYears=" + positiveYears + " negYears=" + negativeYears);
        }
        buffer.append("\r\n");
    }

    PerformanceKeysVO performanceKeys = resultVO.getPerformanceKeys();
    MaxDrawDownVO maxDrawDownVO = resultVO.getMaxDrawDown();
    if (performanceKeys != null && maxDrawDownVO != null) {
        buffer.append("avgM=" + twoDigitFormat.format(performanceKeys.getAvgM() * 100) + "%");
        buffer.append(" stdM=" + twoDigitFormat.format(performanceKeys.getStdM() * 100) + "%");
        buffer.append(" avgY=" + twoDigitFormat.format(performanceKeys.getAvgY() * 100) + "%");
        buffer.append(" stdY=" + twoDigitFormat.format(performanceKeys.getStdY() * 100) + "% ");
        buffer.append(" sharpeRatio=" + twoDigitFormat.format(performanceKeys.getSharpeRatio()) + "\r\n");

        buffer.append("maxMonthlyDrawDown=" + twoDigitFormat.format(-maxDrawDownM * 100) + "%");
        buffer.append(" bestMonthlyPerformance=" + twoDigitFormat.format(bestMonthlyPerformance * 100) + "%");
        buffer.append(" maxDrawDown=" + twoDigitFormat.format(maxDrawDownVO.getAmount() * 100) + "%");
        buffer.append(
                " maxDrawDownPeriod=" + twoDigitFormat.format(maxDrawDownVO.getPeriod() / 86400000) + "days");
        buffer.append(
                " colmarRatio=" + twoDigitFormat.format(performanceKeys.getAvgY() / maxDrawDownVO.getAmount()));

        buffer.append("\r\n");
    }

    buffer.append("WinningTrades:");
    convertTrades(buffer, resultVO.getWinningTrades(), resultVO.getAllTrades().getCount());

    buffer.append("LoosingTrades:");
    convertTrades(buffer, resultVO.getLoosingTrades(), resultVO.getAllTrades().getCount());

    buffer.append("AllTrades:");
    convertTrades(buffer, resultVO.getAllTrades(), resultVO.getAllTrades().getCount());

    for (Map.Entry<String, Object> entry : resultVO.getStrategyResults().entrySet()) {
        buffer.append(entry.getKey() + "=" + entry.getValue() + " ");
    }
}

From source file:de.codesourcery.springmass.math.Matrix.java

private static String format(double v) {
    final DecimalFormat df = new DecimalFormat("##0.0##");
    return StringUtils.leftPad(df.format(v), 6);
}

From source file:de.codesourcery.jasm16.utils.Matrix.java

private static String format(float v) {
    final DecimalFormat df = new DecimalFormat("##0.0##");
    return StringUtils.leftPad(df.format(v), 6);
}

From source file:com.algoTrader.service.SimulationServiceImpl.java

@SuppressWarnings("unchecked")
private static String convertStatisticsToLongString(SimulationResultVO resultVO) {

    StringBuffer buffer = new StringBuffer();
    buffer.append("execution time (min): " + (new DecimalFormat("0.00")).format(resultVO.getMins()) + LF);
    buffer.append("dataSet: " + dataSet + LF);

    double netLiqValue = resultVO.getNetLiqValue();
    buffer.append("netLiqValue=" + twoDigitFormat.format(netLiqValue) + LF);

    List<MonthlyPerformanceVO> monthlyPerformanceVOs = resultVO.getMonthlyPerformanceVOs();
    double maxDrawDownM = 0d;
    double bestMonthlyPerformance = Double.NEGATIVE_INFINITY;
    if (monthlyPerformanceVOs != null) {
        StringBuffer dateBuffer = new StringBuffer("month-year:         ");
        StringBuffer performanceBuffer = new StringBuffer("MonthlyPerformance: ");
        for (MonthlyPerformanceVO monthlyPerformanceVO : monthlyPerformanceVOs) {
            maxDrawDownM = Math.min(maxDrawDownM, monthlyPerformanceVO.getValue());
            bestMonthlyPerformance = Math.max(bestMonthlyPerformance, monthlyPerformanceVO.getValue());
            dateBuffer.append(dateFormat.format(monthlyPerformanceVO.getDate()));
            performanceBuffer/*from   w  w  w. jav  a 2 s  . co m*/
                    .append(StringUtils.leftPad(twoDigitFormat.format(monthlyPerformanceVO.getValue() * 100), 6)
                            + "% ");
        }
        buffer.append(dateBuffer.toString() + LF);
        buffer.append(performanceBuffer.toString() + LF);
    }

    PerformanceKeysVO performanceKeys = resultVO.getPerformanceKeysVO();
    MaxDrawDownVO maxDrawDownVO = resultVO.getMaxDrawDownVO();
    if (performanceKeys != null && maxDrawDownVO != null) {
        buffer.append("n=" + performanceKeys.getN());
        buffer.append(" avgM=" + twoDigitFormat.format(performanceKeys.getAvgM() * 100) + PCNT);
        buffer.append(" stdM=" + twoDigitFormat.format(performanceKeys.getStdM() * 100) + PCNT);
        buffer.append(" avgY=" + twoDigitFormat.format(performanceKeys.getAvgY() * 100) + PCNT);
        buffer.append(" stdY=" + twoDigitFormat.format(performanceKeys.getStdY() * 100) + PCNT);
        buffer.append(" sharpRatio=" + twoDigitFormat.format(performanceKeys.getSharpRatio()) + LF);

        buffer.append("maxDrawDownM=" + twoDigitFormat.format(-maxDrawDownM * 100) + PCNT);
        buffer.append(" bestMonthlyPerformance=" + twoDigitFormat.format(bestMonthlyPerformance * 100) + PCNT);
        buffer.append(" maxDrawDown=" + twoDigitFormat.format(maxDrawDownVO.getAmount() * 100) + PCNT);
        buffer.append(
                " maxDrawDownPeriod=" + twoDigitFormat.format(maxDrawDownVO.getPeriod() / 86400000) + "days");
        buffer.append(
                " colmarRatio=" + twoDigitFormat.format(performanceKeys.getAvgY() / maxDrawDownVO.getAmount()));
    }

    return buffer.toString();
}

From source file:de.codesourcery.planning.demo.SimulationDemo.java

private static void printResources(List<IFactory> factories, IResourceManager manager) {

    final Set<IProductionLocation> locations = new HashSet<IProductionLocation>();

    for (IFactory f : factories) {
        for (IFactorySlot slot : f.getSlots()) {
            locations.add(slot.getInputLocation());
            locations.add(slot.getOutputLocation());
        }//from  w w  w  .  j  ava  2 s  .  c o  m
    }

    for (IProductionLocation location : locations) {
        final List<IResource> r = new ArrayList<IResource>(manager.getResourcesAt(location));
        //         Collections.sort( r , new Comparator<IResource>() {
        //
        //            @Override
        //            public int compare(IResource o1, IResource o2)
        //            {
        //               return o1.getType().compareTo( o2.getType() );
        //            }
        //         } );
        System.out.println("\nResources at " + location + ":\n\n");
        for (IResource resource : r) {
            System.out.println(StringUtils.rightPad(resource.getType().toString(), 25) + " "
                    + StringUtils.leftPad("" + resource.getAmount(), 15));
        }
    }
}

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

protected void saveSummaryToClipboard() {

    final Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();

    final StringBuffer buffer = new StringBuffer();

    buffer.append("Current date: " + DateHelper.format(new Date()) + "\n");
    buffer.append("Region: " + getDefaultRegion().getName() + "\n");
    buffer.append("\n");

    for (int i = 0; i < mineralPriceTableModel.getRowCount(); i++) {
        final MineralPrice minPrice = mineralPriceTableModel.getRow(i);
        buffer.append(StringUtils.rightPad(minPrice.itemName(), 13)).append(" : ");
        buffer.append(StringUtils.leftPad(AmountHelper.formatISKAmount(minPrice.getSellPrice()), 10) + " ISK");
        buffer.append("\n");
    }//from  www. ja v  a  2  s . c o m

    buffer.append("\n");

    final List<CsvRow> data = new ArrayList<CsvRow>();

    for (int i = 0; i < tableModel.getRowCount(); i++) {

        final TableRow row = tableModel.getRow(i);
        final ISKAmount amount = tableModel.getISKperM3(row);

        data.add(new CsvRow(row.oreName, amount));
    }

    Collections.sort(data);

    for (CsvRow r : data) {
        buffer.append(StringUtils.rightPad(r.oreName, 13)).append(" : ");
        buffer.append(StringUtils.leftPad(AmountHelper.formatISKAmount(r.iskPerM3), 10) + " ISK / m3");
        buffer.append("\n");
    }

    clipboard.setContents(new PlainTextTransferable(buffer.toString()), null);
}

From source file:com.github.cereda.arara.langchecker.LanguageUtils.java

/**
 * Prints the report for every language report.
 * @param languages The list of language reports.
 *//*from   w ww.  j  a  v a 2  s  . co  m*/
public static void printReport(List<LanguageReport> languages) {

    // print header
    System.out.println(StringUtils.center(" Language coverage report ", 60, "-").concat("\n"));

    // let's sort our list of reports according to
    // each language coverage
    Collections.sort(languages, new Comparator<LanguageReport>() {

        @Override
        public int compare(LanguageReport t1, LanguageReport t2) {

            // get values of each language
            float a1 = t1.getCoverage();
            float a2 = t2.getCoverage();

            // they are equal, do nothing
            if (a1 == a2) {
                return 0;
            } else {

                // we want to sort in reverse order,
                // so return a negative value here
                if (a1 > a2) {
                    return -1;
                } else {

                    // return a positive value, since
                    // the first statement was false
                    return 1;
                }
            }
        }
    });

    // list of languages to be fixed
    List<LanguageReport> fix = new ArrayList<>();

    // for each report, print
    // the corresponding entry
    for (LanguageReport language : languages) {

        // if there are problematic lines,
        // add the current language report
        if (!language.getLines().isEmpty()) {
            fix.add(language);
        }

        // build the beginning of the line
        String line = String.format("- %s ", language.getReference().getName());

        // build the coverage information
        String coverage = String.format(" %2.2f%%", language.getCoverage());

        // generate the line by concatenating
        // the beginning and coverage
        line = line.concat(StringUtils.repeat(".", 60 - line.length() - coverage.length())).concat(coverage);

        // print the line
        System.out.println(line);
    }

    // we have some fixes to do
    if (!fix.isEmpty()) {

        // print header
        System.out.println();
        System.out.println(StringUtils.center(" Lines to fix ", 60, "-").concat("\n"));

        // print legend for a simple message
        System.out.println(StringUtils.center("S: Simple message, single quotes should not be doubled", 60));

        // print legend for a parametrized
        System.out.println(
                StringUtils.center("P: Parametrized message, single quotes must be doubled", 60).concat("\n"));

        // print a line separator
        System.out.println(StringUtils.repeat("-", 60));

        // print each language and its
        // corresponding lines
        for (LanguageReport report : fix) {

            // build the beginning of the line
            String line = String.format("- %s ", report.getReference().getName());

            // build the first batch
            String batch = pump(report.getLines(), 2);

            // generate the line by concatenating
            // the beginning and batch
            line = line.concat(StringUtils.repeat(" ", 60 - line.length() - batch.length())).concat(batch);

            // print the line
            System.out.println(line);

            // get the next batch, if any
            batch = pump(report.getLines(), 2);

            // repeat while there
            // are other batches
            while (!batch.isEmpty()) {

                // print current line
                System.out.println(StringUtils.leftPad(batch, 60));

                // get the next batch and let
                // the condition handle it
                batch = pump(report.getLines(), 2);
            }

            // print a line separator
            System.out.println(StringUtils.repeat("-", 60));
        }
    }

}

From source file:com.eyeq.pivot4j.export.poi.ExcelExporter.java

/**
 * @see com.eyeq.pivot4j.ui.AbstractPivotRenderer#getCellLabel(com.eyeq.pivot4j.ui.RenderContext)
 *//*from  www.  j  a  va  2 s. c om*/
@Override
protected String getCellLabel(RenderContext context) {
    String label = super.getCellLabel(context);

    if (!getShowParentMembers() && label != null && context.getAxis() == Axis.ROWS
            && context.getMember() != null && context.getCell() == null) {
        label = StringUtils.leftPad(label, context.getMember().getDepth() + label.length());
    }
    return label;
}

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

protected void putOnClipboard() {

    // create text
    final SpreadSheetTableModel model = (SpreadSheetTableModel) this.table.getModel();

    int maxColumnCount = 1;

    final Map<Integer, Integer> maxColumnWidth = new HashMap<Integer, Integer>();

    for (TableRow r : model.getRows()) {
        if (r.getCellCount() > maxColumnCount) {
            maxColumnCount = r.getCellCount();
        }// w ww . j av a 2 s  .  c om

        for (int i = 0; i < r.getCellCount(); i++) {

            Integer maxWidth = maxColumnWidth.get(i);
            if (maxWidth == null) {
                maxWidth = new Integer(0);
                maxColumnWidth.put(i, maxWidth);
            }
            final ITableCell cell = r.getCell(i);
            if (cell.getValue() != null) {
                final int len = toString(cell).length();

                if (len > maxWidth.intValue()) {
                    maxWidth = new Integer(len);
                    maxColumnWidth.put(i, maxWidth);
                }
            }
        }
    }

    final StringBuffer text = new StringBuffer();

    for (TableRow r : model.getRows()) {
        for (int i = 0; i < r.getCellCount(); i++) {
            final int width = maxColumnWidth.get(i);
            final ITableCell cell = r.getCell(i);
            if (i == 0) {
                text.append(StringUtils.rightPad(toString(cell), width)).append(" | ");
            } else {
                text.append(StringUtils.leftPad(toString(cell), width)).append(" | ");
            }
        }
        text.append("\n");
    }

    // put on clipboard
    final Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();

    clipboard.setContents(new PlainTextTransferable(text.toString()), null);
}