Example usage for org.apache.commons.lang3.text StrBuilder setNullText

List of usage examples for org.apache.commons.lang3.text StrBuilder setNullText

Introduction

In this page you can find the example usage for org.apache.commons.lang3.text StrBuilder setNullText.

Prototype

public StrBuilder setNullText(String nullText) 

Source Link

Document

Sets the text to be appended when null is added.

Usage

From source file:com.mgmtp.perfload.logging.DefaultResultLoggerTest.java

private String createExpectedResultString(final String errorMsg, final Object... extras) {
    String success = errorMsg != null ? "ERROR" : "SUCCESS";

    StrBuilder sb = new StrBuilder(250);
    sb.setNullText("");

    String result = String.format(EXP_RESULT_TEMPLATE, timestamp, success, trimToEmpty(errorMsg), localhost,
            executionId, requestId);//from  w  ww .  jav a 2  s. c o  m
    sb.append(result);
    if (extras != null) {
        for (Object extra : extras) {
            sb.append(";\"");
            sb.append(extra);
            sb.append("\"");
        }
    }
    return sb.toString();
}

From source file:de.vandermeer.asciitable.v1.V1_AsciiTable.java

/**
 * Renders rows of content with correct separators.
 * @param row array with all lines for all columns of a single row
 * @param padChar padding character//from   w  ww.ja  v  a  2 s . c o m
 * @param theme row theme
 * @return rendered lines for the row, empty if nothing was to be rendered
 */
protected final StrBuilder renderRow(String[][] row, char padChar, char[] theme) {
    StrBuilder ret = new StrBuilder(100);
    ret.setNullText("");
    for (int k = 0; k < row.length; k++) {
        String[] ar = row[k];
        ret.append(theme[V1_TableTheme.VERTICAL]);
        //if null is in array we need to render column spans
        if (ArrayUtils.contains(ar, null)) {
            int span = 0;
            for (int i = 0; i < ar.length; i++) {
                String content = ar[i];
                if (content == null) {
                    if (i == ar.length - 1) {
                        //a null in last column, so calculate the span)
                        int width = 0;
                        //add the span column width
                        for (k = 0; k < span; k++) {
                            width += this.columns[k + 1];
                        }
                        //add the separator characters (span) plus the one for this column
                        width += span;
                        //add the current column width
                        width += this.columns[i + 1];
                        //centre content in the new column
                        ret.appendFixedWidthPadRight("", width, padChar);
                    } else {
                        span += 1;
                        continue;
                    }
                } else if ("".equals(content)) {
                    //we have an empty column, so
                    //first finish the spans
                    for (k = 0; k < span; k++) {
                        ret.appendFixedWidthPadRight("", this.columns[k + 1], padChar);
                    }
                    ret.appendFixedWidthPadRight("", span, padChar);
                    ret.append(theme[V1_TableTheme.VERTICAL]);
                    span = 0;
                    //now add the empty column
                    ret.appendFixedWidthPadRight(content, this.columns[i + 1], padChar);
                    if (i < ar.length - 1) {
                        ret.append(theme[V1_TableTheme.VERTICAL]);
                    }
                } else {
                    int width = 0;
                    //add the span column width
                    for (k = 0; k < span; k++) {
                        width += this.columns[k + 1];
                    }
                    //add the separator characters (span) plus the one for this column
                    width += span;
                    //add the current column width
                    width += this.columns[i + 1];
                    //centre content in the new column
                    ret.append(StringUtils.center(content, width, padChar));
                    if (i < ar.length - 1) {
                        ret.append(theme[V1_TableTheme.VERTICAL]);
                    }
                    span = 0;
                }
            }
        } else {
            for (int i = 0; i < ar.length; i++) {
                String content = ar[i];
                ret.appendFixedWidthPadRight(content, this.columns[i + 1], padChar);
                if (i < ar.length - 1) {
                    ret.append(theme[V1_TableTheme.VERTICAL]);
                }
            }
        }
        ret.append(theme[V1_TableTheme.VERTICAL]);
        if (k < row.length - 1) {
            ret.append('\n');
        }
    }

    return ret;
}

From source file:de.vandermeer.asciitable.v1.AsciiTable.java

/**
 * Renders rows of content with correct separators.
 * @param row array with all lines for all columns of a single row
 * @param padChar padding character// w w w  .j av  a 2  s  .  co m
 * @param theme row theme
 * @return rendered lines for the row, empty if nothing was to be rendered
 */
protected final StrBuilder renderRow(String[][] row, char padChar, char[] theme) {
    StrBuilder ret = new StrBuilder(100);
    ret.setNullText("");
    for (int k = 0; k < row.length; k++) {
        String[] ar = row[k];
        ret.append(theme[TableTheme.VERTICAL]);
        //if null is in array we need to render column spans
        if (ArrayUtils.contains(ar, null)) {
            int span = 0;
            for (int i = 0; i < ar.length; i++) {
                String content = ar[i];
                if (content == null) {
                    if (i == ar.length - 1) {
                        //a null in last column, so calculate the span)
                        int width = 0;
                        //add the span column width
                        for (k = 0; k < span; k++) {
                            width += this.columns[k + 1];
                        }
                        //add the separator characters (span) plus the one for this column
                        width += span;
                        //add the current column width
                        width += this.columns[i + 1];
                        //centre content in the new column
                        ret.appendFixedWidthPadRight("", width, padChar);
                    } else {
                        span += 1;
                        continue;
                    }
                } else if ("".equals(content)) {
                    //we have an empty column, so
                    //first finish the spans
                    for (k = 0; k < span; k++) {
                        ret.appendFixedWidthPadRight("", this.columns[k + 1], padChar);
                    }
                    ret.appendFixedWidthPadRight("", span, padChar);
                    ret.append(theme[TableTheme.VERTICAL]);
                    span = 0;
                    //now add the empty column
                    ret.appendFixedWidthPadRight(content, this.columns[i + 1], padChar);
                    if (i < ar.length - 1) {
                        ret.append(theme[TableTheme.VERTICAL]);
                    }
                } else {
                    int width = 0;
                    //add the span column width
                    for (k = 0; k < span; k++) {
                        width += this.columns[k + 1];
                    }
                    //add the separator characters (span) plus the one for this column
                    width += span;
                    //add the current column width
                    width += this.columns[i + 1];
                    //centre content in the new column
                    ret.append(StringUtils.center(content, width, padChar));
                    if (i < ar.length - 1) {
                        ret.append(theme[TableTheme.VERTICAL]);
                    }
                    span = 0;
                }
            }
        } else {
            for (int i = 0; i < ar.length; i++) {
                String content = ar[i];
                ret.appendFixedWidthPadRight(content, this.columns[i + 1], padChar);
                if (i < ar.length - 1) {
                    ret.append(theme[TableTheme.VERTICAL]);
                }
            }
        }
        ret.append(theme[TableTheme.VERTICAL]);
        if (k < row.length - 1) {
            ret.append('\n');
        }
    }

    return ret;
}