List of usage examples for org.apache.commons.lang.text StrBuilder isEmpty
public boolean isEmpty()
From source file:me.taylorkelly.mywarp.bukkit.util.FormattingUtils.java
/** * Creates a not numbered list from the given strings. Each string represents an independent entry on the list. * Strings that are longer than the given width will be split above several lines. *// w ww . j a v a 2 s.c o m * @param listChar the character that will be displayed as bullet point before each entry * @param maxWidth the maximal width of each entry * @param entries the list's entries * @return the list */ public static String toList(char listChar, int maxWidth, List<String> entries) { StrBuilder ret = new StrBuilder(); String listPrefix = listChar + " "; Splitter splitter = Splitter.on(' ').trimResults().omitEmptyStrings(); for (String entry : entries) { if (!ret.isEmpty()) { ret.appendNewLine(); // reset colors from the previous entry ret.append(ChatColor.RESET); } List<String> entryParts = new LinkedList<String>(); entryParts.add(listPrefix); Iterables.addAll(entryParts, splitter.split(entry)); ret.append(wrappedJoin(entryParts, " ", maxWidth)); } return ret.toString(); }
From source file:com.collective.celos.ci.testing.fixtures.compare.RecursiveFsObjectComparer.java
private void appendMessages(Collection<String> messages, StrBuilder strBuilder, String header) { if (messages.size() == 0) { return;/*w w w.j a v a 2 s .c o m*/ } if (!strBuilder.isEmpty()) { strBuilder.appendNewLine(); } strBuilder.append(header); List<String> sortedMessages = Lists.newArrayList(messages); Collections.sort(sortedMessages); strBuilder.appendWithSeparators(sortedMessages, ", "); }
From source file:me.taylorkelly.mywarp.bukkit.util.FormattingUtils.java
/** * Joins the given parts, separated by blanks. The resulting string will be wrapped into multiple lines so that each * line is at most as wide as the given width. Each new line will start with the given prefix. *//from ww w. j av a2 s . c o m * @param parts the parts * @param newLinePrefix the prefix for created new lines * @param wrappedWidth the width of each line * @return the wrapped string */ private static String wrappedJoin(Iterable<String> parts, String newLinePrefix, int wrappedWidth) { StrBuilder ret = new StrBuilder(); StrBuilder line = new StrBuilder(); for (String part : parts) { // if the word is longer than the maximum length, add chars as long // as possible than make a new line if (getWidth(part) > wrappedWidth) { for (char c : part.toCharArray()) { // if the maximum width is reached, make a new line if (getWidth(line.toString()) + getWidth(c) > wrappedWidth) { ret.appendln(line.toString()); line.clear(); line.append(newLinePrefix); } line.append(c); } // if the world AND the needed black is longer than the maximum // width make a new line and insert the word there } else { // if the maximum width is reached, make a new line if (getWidth(line.toString()) + getWidth(part) + getWidth(' ') > wrappedWidth) { ret.appendln(line.toString()); line.clear(); line.append(newLinePrefix); } // a blank is only needed if the line is not empty AND the last // char is not a a blank (e.g. from prefix) if (!line.isEmpty() && !line.rightString(1).equals(" ")) { line.append(' '); } line.append(part); } } // commit the line if (!line.isEmpty()) { ret.append(line); } return ret.toString(); }
From source file:org.eclipse.gyrex.http.jetty.internal.admin.CertificateDefinition.java
@Override public String getInfo() { try {/*from w ww. j ava 2s . co m*/ final StrBuilder certInfo = new StrBuilder(); final KeyStore ks = getKeyStore(); final Enumeration aliases = ks.aliases(); while (aliases.hasMoreElements()) { final String alias = (String) aliases.nextElement(); if (!certInfo.isEmpty()) { certInfo.append(", "); } // certInfo.append(alias).append(": "); if (ks.isKeyEntry(alias)) { Certificate[] chain = ks.getCertificateChain(alias); if (null == chain) { final Certificate certificate = ks.getCertificate(alias); chain = new Certificate[] { certificate }; } for (int i = 0; i < chain.length; i++) { if (i > 0) { certInfo.append(" "); } final Certificate certificate = chain[i]; if (certificate instanceof X509Certificate) { final X509Certificate x509 = (X509Certificate) certificate; final X500PrincipalHelper helper = new X500PrincipalHelper( x509.getSubjectX500Principal()); certInfo.append(helper.getCN()); certInfo.append(", valid till ").append(TO_STRING_FORMAT.format(x509.getNotAfter())); } else { certInfo.append("INVALID"); } } } else { certInfo.append("IGNORED"); } } return StringUtils.trim(certInfo.toString()); } catch (final Exception e) { return ExceptionUtils.getRootCauseMessage(e); } }
From source file:org.kuali.kfs.module.endow.report.service.impl.EndowmentReportServiceImpl.java
/** * Concatenate strings with a separator//from w w w. j av a2 s. c om * * @param stringList * @param defaultEmptyValue * @return */ protected String getListWithSeparator(List<String> stringList, String defaultEmptyValue) { final String SEPARATOR = " "; StrBuilder builder = new StrBuilder(); builder = builder.appendWithSeparators(stringList, SEPARATOR); return builder.isEmpty() ? defaultEmptyValue : builder.toString(); }