mirror of
https://github.com/vanitasvitae/Smack.git
synced 2025-09-09 17:19:39 +02:00
Add checkstyle rule for StringBuilder.append(char)
And replace all instances where String.Builder.append() is called with a String of length one with append(char). Also adds StringUtils.toStringBuilder(Collection, String).
This commit is contained in:
parent
19ebcb814b
commit
e0e4fd9b12
46 changed files with 159 additions and 142 deletions
|
@ -160,7 +160,7 @@ public class MessageTest extends SmackTestCase {
|
|||
Message msg = new Message(getFullJID(1), Message.Type.chat);
|
||||
StringBuilder sb = new StringBuilder(5000);
|
||||
for (int i = 0; i <= 4000; i++) {
|
||||
sb.append("X");
|
||||
sb.append('X');
|
||||
}
|
||||
msg.setBody(sb.toString());
|
||||
|
||||
|
|
|
@ -19,10 +19,10 @@ package org.jivesoftware.smack.filter;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.jivesoftware.smack.util.Objects;
|
||||
import org.jivesoftware.smack.util.StringUtils;
|
||||
|
||||
public abstract class AbstractListFilter implements StanzaFilter {
|
||||
|
||||
|
@ -67,14 +67,8 @@ public abstract class AbstractListFilter implements StanzaFilter {
|
|||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(getClass().getSimpleName());
|
||||
sb.append(": (");
|
||||
for (Iterator<StanzaFilter> it = filters.iterator(); it.hasNext();) {
|
||||
StanzaFilter filter = it.next();
|
||||
sb.append(filter.toString());
|
||||
if (it.hasNext()) {
|
||||
sb.append(", ");
|
||||
}
|
||||
}
|
||||
sb.append(")");
|
||||
sb.append(StringUtils.toStringBuilder(filters, ", "));
|
||||
sb.append(')');
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -222,21 +222,32 @@ public class StringUtils {
|
|||
}
|
||||
|
||||
/**
|
||||
* Transform a collection of CharSequences to a whitespace delimited String.
|
||||
* Transform a collection of objects to a whitespace delimited String.
|
||||
*
|
||||
* @param collection the collection to transform.
|
||||
* @return a String with all the elements of the collection.
|
||||
*/
|
||||
public static String collectionToString(Collection<? extends CharSequence> collection) {
|
||||
public static String collectionToString(Collection<? extends Object> collection) {
|
||||
return toStringBuilder(collection, " ").toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform a collection of objects to a delimited String.
|
||||
*
|
||||
* @param collection the collection to transform.
|
||||
* @param delimiter the delimiter used to delimit the Strings.
|
||||
* @return a StringBuilder with all the elements of the collection.
|
||||
*/
|
||||
public static StringBuilder toStringBuilder(Collection<? extends Object> collection, String delimiter) {
|
||||
StringBuilder sb = new StringBuilder(collection.size() * 20);
|
||||
for (Iterator<? extends CharSequence> it = collection.iterator(); it.hasNext();) {
|
||||
CharSequence cs = it.next();
|
||||
for (Iterator<? extends Object> it = collection.iterator(); it.hasNext();) {
|
||||
Object cs = it.next();
|
||||
sb.append(cs);
|
||||
if (it.hasNext()) {
|
||||
sb.append(' ');
|
||||
sb.append(delimiter);
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
return sb;
|
||||
}
|
||||
|
||||
public static String returnIfNotEmptyTrimmed(String string) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue