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

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

Introduction

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

Prototype

public StrBuilder(final String str) 

Source Link

Document

Constructor that creates a builder from the string, allocating 32 extra characters for growth.

Usage

From source file:com.mgmtp.perfload.agent.util.ClassNameUtils.java

public static String computeFullyQualifiedMethodName(final String className, final String methodName,
        final Type[] argumentTypes) {
    StrBuilder sb = new StrBuilder(50);
    sb.append(abbreviatePackageName(className));
    sb.append('.');
    sb.append(methodName);/*  w w  w  . j a v  a2  s  . c om*/
    sb.append('(');
    for (int i = 0; i < argumentTypes.length; ++i) {
        sb.appendSeparator(", ", i);
        sb.append(abbreviatePackageName(argumentTypes[i].getClassName()));
    }
    sb.append(')');
    return sb.toString();
}

From source file:de.vandermeer.skb.interfaces.categories.has.HasToLog.java

/**
 * Returns a builder using containment class, contained class, and values.
 * @param container the contain object class
 * @param contained contained object class
 * @param values values, printed comma separated
 * @return an `StrBuilder` combining the inputs
 *///  w ww. j  a v  a2s.  c o  m
static StrBuilder toLog(Class<?> container, Class<?> contained, Object... values) {
    StrBuilder ret = new StrBuilder(50).append(container.getSimpleName()).append('(')
            .append(contained.getSimpleName()).append(')').append(": ").appendWithSeparators(values, ", ");
    ;
    return ret;
}

From source file:de.vandermeer.asciitable.commons.ArrayTransformations.java

/**
 * Takes a 2 dimensional array and returns a string representation in table form.
 * @param <T> type of the input array
 * @param ar the array to be transformed
 * @return a string representation of the array
 *//*from   w  ww .  j  a  v  a2s .c  om*/
public static final <T> StrBuilder ARRAY_TO_STRING(T[][] ar) {
    StrBuilder ret = new StrBuilder(50);
    for (int row = 0; row < ar.length; row++) { //TODO not null save
        if (ar[row] == null) {
            ret.append("[").append(row).appendln("]: null");
        } else if (ar[row].length == 0) {
            ret.append("[").append(row).appendln("]: 0");
        } else {
            for (int col = 0; col < ar[row].length; col++) {
                ret.append("[").append(row).append("][").append(col).append("]: ");
                if (ar[row][col] == null) {
                    ret.appendln("null");
                } else if ("".equals(ar[row][col])) {
                    ret.appendln("0");
                } else {
                    ret.appendln(ar[row][col]);
                }
            }
        }
    }
    return ret;
}

From source file:de.vandermeer.skb.base.utils.Skb_TextUtils.java

/**
 * Returns a transformer that takes a 2 dimensional array and transforms it into a textual representation, for instance for debug output.
 * @param <T> type of the input array
 * @return transformer for textual representation of the 2 dimensional array
 *///from w  w w  .  j a va 2  s  .  c  o m
public static final <T> Skb_Transformer<T[][], StrBuilder> ARRAY_TO_TEXT() {
    return new Skb_Transformer<T[][], StrBuilder>() {
        @Override
        public StrBuilder transform(T[][] ar) {
            StrBuilder ret = new StrBuilder(50);
            for (int row = 0; row < ar.length; row++) { //TODO not null save
                if (ar[row] == null) {
                    ret.append("[").append(row).appendln("]: null");
                } else if (ar[row].length == 0) {
                    ret.append("[").append(row).appendln("]: 0");
                } else {
                    for (int col = 0; col < ar[row].length; col++) {
                        ret.append("[").append(row).append("][").append(col).append("]: ");
                        if (ar[row][col] == null) {
                            ret.appendln("null");
                        } else if ("".equals(ar[row][col])) {
                            ret.appendln("0");
                        } else {
                            ret.appendln(ar[row][col]);
                        }
                    }
                }
            }
            return ret;
        }
    };
}

From source file:com.mgmtp.jfunk.core.mail.MessageUtils.java

/**
 * Returns the specified message as text.
 * //from w  w w . j a v  a2 s  .c  om
 * @param message
 *            the message
 * @param includeHeaders
 *            specifies whether message headers are to be included in the returned text
 * @return the message text
 */
public static String messageAsText(final Message message, final boolean includeHeaders) {
    try {
        StrBuilder sb = new StrBuilder(300);

        if (includeHeaders) {
            @SuppressWarnings("unchecked")
            Enumeration<Header> headers = message.getAllHeaders();
            while (headers.hasMoreElements()) {
                Header header = headers.nextElement();
                sb.append(header.getName()).append('=').appendln(header.getValue());
            }

            sb.appendln("");
        }

        Object content = message.getContent();
        if (content instanceof String) {
            String body = (String) content;
            sb.appendln(body);
            sb.appendln("");
        } else if (content instanceof Multipart) {
            parseMultipart(sb, (Multipart) content);
        }
        return sb.toString();
    } catch (MessagingException ex) {
        throw new MailException("Error getting mail content.", ex);
    } catch (IOException ex) {
        throw new MailException("Error getting mail content.", ex);
    }
}

From source file:de.vandermeer.skb.interfaces.categories.has.HasToLog.java

/**
 * Returns a builder using containment class, default contained class, and values.
 * @param container the contain object class
 * @param values values, printed comma separated
 * @return an `StrBuilder` combining the inputs
 *///from ww w.j ava 2 s.  c om
static StrBuilder toLog(Class<?> container, Object... values) {
    StrBuilder ret = new StrBuilder(50).append(container.getSimpleName()).append('(').append("DefaultImpl")
            .append(')').append(": ").appendWithSeparators(values, ", ");
    ;
    return ret;
}

From source file:de.vandermeer.skb.interfaces.categories.has.HasPrompt.java

/**
 * Returns a prompt for an object.//  www . ja v a2  s.c om
 * @return the prompt, cannot be null
 */
default StrBuilder prompt() {
    StrBuilder ret = new StrBuilder(30);
    ret.append('[').append("default").append("]> ");
    return ret;
}

From source file:candr.yoclip.OptionUtils.java

/**
 * Combines an array of strings into a single string. Multiple strings are joined together separated by a space
 * character unless proceeded by an {@link Options#LINE_BREAK Options} line break.<p/>
 * As an example the string array <code>String[] example = { &quot;Hello&quot;, &quot;World!&quot; }</code> will result
 * in the string <code>&quot;Hello World!&quot</code>. The string array <code>String[] example = { &quot;Hello\n&quot;,
 * &quot;World!&quot; }</code> will result in the string <code>&quot;Hello${nl}World!&quot</code> (where ${nl} is the OS
 * dependent new line character string).
 *
 * @param descriptions The strings that will be combined.
 * @return a string created from the array of strings.
 *///ww  w  .  ja  v a2s  .c  o m
public static String combine(final String[] descriptions) {

    if (ArrayUtils.isEmpty(descriptions)) {
        return StringUtils.EMPTY;
    }

    if (descriptions.length == 1) {
        return descriptions[0];
    }

    final StrBuilder descriptionBuilder = new StrBuilder(descriptions[0]);

    for (int i = 1; i < descriptions.length; i++) {
        if (!descriptions[i].startsWith(Options.LINE_BREAK)) {
            final String prior = StringUtils.isEmpty(descriptions[i - 1]) ? StringUtils.EMPTY
                    : descriptions[i - 1];
            if (!prior.endsWith(Options.LINE_BREAK)) {
                descriptionBuilder.append(' ');
            }
        }
        descriptionBuilder.append(descriptions[i]);
    }

    return descriptionBuilder.toString();
}

From source file:com.mgmtp.jfunk.data.generator.util.LoremIpsumGenerator.java

public String generateLoremIpsum(final int length) {
    if (loremLength < length) {
        int multiplier = length / loremLength;
        int remainder = length % loremLength;

        StrBuilder sb = new StrBuilder(multiplier * length + remainder);
        for (int i = 0; i < multiplier; ++i) {
            sb.append(loremIpsum);//from  ww  w. java  2 s.c om
        }
        sb.append(loremIpsum.substring(0, remainder));
        return sb.toString();
    }

    return loremIpsum.substring(0, length);
}

From source file:de.vandermeer.asciitable.commons.Table_ToStringStyle.java

/**
 * Returns a builder using parent class, class and value.
 * @param parent parent class for the string
 * @param clazz current class for the string
 * @param values values for the string, printed comma separated
 * @return a StrBuilder combining the inputs
 *///from ww w  .j a  v a  2  s .c om
public static StrBuilder parentKV(Class<?> parent, Class<?> clazz, Object... values) {
    StrBuilder ret = new StrBuilder(50).append(parent.getSimpleName()).append('(').append(clazz.getSimpleName())
            .append(')').append(": ").appendWithSeparators(values, ", ");
    ;
    return ret;
}