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

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

Introduction

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

Prototype

@Override
public String toString() 

Source Link

Document

Gets a String version of the string builder, creating a new instance each time the method is called.

Usage

From source file:de.vandermeer.skb.commons.Predicates.java

/**
 * Returns a predicate that evaluates to true if the set contains strings starting with a given character sequence.
 * @param nodes set of strings as base/*  w w  w  . j a  va  2 s. co m*/
 * @return predicate that returns true if set contains strings starting with it, false otherwise
 */
final public static Predicate<StrBuilder> CONTAINS_STRINGS_STARTING_WITH(final Set<String> nodes) {
    return new Predicate<StrBuilder>() {
        @Override
        public boolean test(final StrBuilder fqpn) {
            if (fqpn == null) {
                return false;
            }
            String key = fqpn.toString();
            if (!nodes.contains(key)) {
                return false;
            }

            Set<String> tail = new TreeSet<String>(nodes).tailSet(key, false);
            if (tail.size() == 0) {
                return false;
            }

            String child = tail.iterator().next();
            if (child.startsWith(key)) {
                return true;
            }
            return false;
        }
    };
}

From source file:de.vandermeer.asciithemes.TA_ItemizeList.java

/**
 * Creates a new itemize list with unlimited levels for given character.
 * Incremental means that level 1 has 1 character, level 2 has 2 characters, level 3 has 3 characters and so forth.
 * @param label character as label/*from   w w  w  .  j a  v  a2s.  c om*/
 * @param description list description
 * @return new list
 */
public static TA_ItemizeList createIncremental(final Character label, final String description) {
    Validate.notNull(label);
    Validate.notBlank(description);

    return new TA_ItemizeList() {
        @Override
        public int getMaxLevel() {
            return -1;
        }

        @Override
        public String getLabel(int level) {
            StrBuilder ret = new StrBuilder();
            for (int i = 0; i < level; i++) {
                ret.append(label);
            }
            return ret.toString();
        }

        @Override
        public String getDescription() {
            return description;
        }
    };
}

From source file:com.relicum.ipsum.Utils.StringStyles.java

/**
 * Centered heading./*  ww w.  j  a va2 s  .c  o  m*/
 * <p>Centres the text to be exactly in the middle of the line with white space used for padding either side.
 * The max length of the heading string is 26 characters.
 *
 * @param color   the color
 * @param style   the style
 * @param heading the heading text
 * @return the centered heading string
 */
public static String centeredHeading(ChatColor color, ChatColor style, String heading) {

    Validate.notNull(color);
    Validate.notNull(style);
    Validate.isTrue(heading.length() < 27, "The maximum length of the heading is 26 Characters");

    int left = 26 - heading.length();
    int offSet = 0;
    int outSet = 0;

    if (!((Integer) left < 1)) {

        if (left == 1) {
            offSet = 1;
        } else if (left == 2) {
            offSet = 1;
            outSet = 1;
        } else if (left > 0 && left % 2 == 1) {
            offSet = (left / 2) + 1;
            outSet = left / 2;
        } else {
            offSet = left / 2;
            outSet = offSet;
        }
    }
    StrBuilder sb = new StrBuilder(58);

    sb.append(" ").appendPadding(19 + offSet, ' ').append(style).append("").append(color).append(heading)
            .appendPadding(8 + offSet, ' ');

    return sb.toString();
}

From source file:com.marand.thinkmed.api.demographics.PersonNameForm.java

private static String combineName(final String name1, final String name2, final String delimiter) {
    final StrBuilder builder = new StrBuilder();
    if (StringUtils.isNotBlank(name1)) {
        builder.append(name1);// w  ww  .  j  a va2s  .  c o m
    }
    if (StringUtils.isNotBlank(name2)) {
        if (!builder.isEmpty()) {
            builder.append(delimiter);
        }
        builder.append(name2);
    }

    return builder.toString();
}

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  va  2 s. c o  m
    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.commons.collections.Tree.java

/**
 * Removes a node and all its children from the map
 * @param fqpn node to be removed//from   w  w w.  j  a v a  2  s.c  o m
 * @param map map from which the node should be removed
 * @param separator path separator
 * @return true if successful, false otherwise
 */
public static boolean removeNode(StrBuilder fqpn, Map<String, ?> map, String separator) {
    if (fqpn == null || map == null || fqpn == null) {
        return false;
    }

    for (String s : IsPath.GET_SUB_PATHS(separator, fqpn, map.keySet())) {
        map.remove(s);
    }
    map.remove(fqpn.toString());
    return !map.containsKey(fqpn.toString());
}

From source file:de.vandermeer.asciithemes.TA_EnumerateList.java

/**
 * Creates a new enumerate list with levels provided by given numbering schemes.
 * @param description list description//from  w  w  w.j  a  v  a2  s . c  o m
 * @param numbering an array with numbering schemes
 * @return new list
 */
public static TA_EnumerateList create(final String description, final TA_Numbering... numbering) {
    Validate.notNull(numbering);
    Validate.noNullElements(numbering);
    Validate.notBlank(description);

    return new TA_EnumerateList() {
        @Override
        public int getMaxLevel() {
            return numbering.length;
        }

        @Override
        public String getLabel(int level) {
            return numbering[0].getNumber(level);
        }

        @Override
        public String getLabel(int[] levels, String separator, boolean useSepOnLast) {
            String simple = TA_EnumerateList.super.getLabel(levels, separator, useSepOnLast);
            if (simple != null) {
                return simple;
            }

            Validate.notNull(levels);
            Validate.validState(numbering.length >= levels.length,
                    "the required levels are going deeper than the provided numbering: levels <" + levels.length
                            + "> provided <" + numbering.length + ">");
            StrBuilder ret = new StrBuilder();
            for (int i = 0; i < levels.length; i++) {
                ret.appendSeparator(separator);
                ret.append(numbering[i].getNumber(levels[i]));
            }
            if (useSepOnLast) {
                ret.append(separator);
            }
            return ret.toString();
        }

        @Override
        public String getDescription() {
            return description;
        }
    };
}

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  .j av a 2  s  .c  om*/
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.relicum.ipsum.Utils.StringStyles.java

/**
 * Boxed announcement./*from   w  ww .  jav a 2s  . c  o m*/
 *
 * @param color     the color
 * @param color2    the color 2
 * @param style     the style
 * @param character the character
 * @param hColor    the h color
 * @param hStyle    the h style
 * @param heading   the heading
 * @param messages  the messages
 * @return the string
 */
public static String boxedAnnouncement(final ChatColor color, final ChatColor color2, final ChatColor style,
        char character, final ChatColor hColor, ChatColor hStyle, String heading, String... messages) {

    StrBuilder sb = new StrBuilder();
    sb.setNewLineText("\n");
    sb.append(" ").appendNewLine().append(" ").appendNewLine().append(" ").appendNewLine();
    sb.append(fullLine(color, color2, style, character)).appendNewLine();
    sb.append(" ").appendNewLine();
    sb.append(centeredHeading(hColor, hStyle, heading)).appendNewLine();
    sb.append(" ").appendNewLine();
    sb.append(ChatColor.translateAlternateColorCodes('&', messages[0])).appendNewLine();
    sb.append(" ").appendNewLine();
    sb.append(fullLine(color2, color, style, character)).appendNewLine();

    return sb.toString();

}

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

/**
 * Returns the specified message as text.
 * //w w  w .  j  a  v a 2 s  .  c  o  m
 * @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);
    }
}