List of usage examples for org.apache.commons.lang3.text StrBuilder append
public StrBuilder append(final double value)
String.valueOf. 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);/* www . j a v a 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: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 w w . j a v a 2 s . c o m*/ if (StringUtils.isNotBlank(name2)) { if (!builder.isEmpty()) { builder.append(delimiter); } builder.append(name2); } return builder.toString(); }
From source file:com.relicum.ipsum.Utils.StringStyles.java
/** * Centered heading./*from w w w . j a v a2 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.relicum.ipsum.Utils.StringStyles.java
/** * Boxed announcement./*from w w w .j a va2 s. c om*/ * * @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: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 ww . j ava 2 s .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.mgmtp.perfload.perfalyzer.util.StrBuilderUtils.java
public static void appendEscapedAndQuoted(final StrBuilder sb, final char delimiter, final String value) { boolean foundLineBreak = false; sb.appendSeparator(delimiter);// w ww . ja v a 2s . co m sb.append(CSV_QUOTE); if (value != null) { for (int i = 0, len = value.length(); i < len; ++i) { char c = value.charAt(i); switch (c) { case CSV_QUOTE: if (foundLineBreak) { foundLineBreak = false; sb.append(' '); } sb.append(c); // escape double quote, i. e. add quote character again break; case '\r': case '\n': foundLineBreak = true; continue; default: if (foundLineBreak) { sb.append(' '); foundLineBreak = false; } break; } sb.append(c); } } sb.append(CSV_QUOTE); }
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 .java2 s .c o m 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.asciithemes.TA_EnumerateList.java
/** * Creates a new enumerate list with levels provided by given numbering schemes. * @param description list description/*from ww w. j a v a 2 s.com*/ * @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: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 ww . j av a 2s . co 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 ww w . ja v a 2s.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); } }