You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by rw...@apache.org on 2020/12/30 23:25:49 UTC
svn commit: r1884971 - in /pivot/trunk/core/src/org/apache/pivot:
collections/ArrayList.java util/StringUtils.java
Author: rwhitcomb
Date: Wed Dec 30 23:25:48 2020
New Revision: 1884971
URL: http://svn.apache.org/viewvc?rev=1884971&view=rev
Log:
Enhance StringUtils.toString and use more places.
Modified:
pivot/trunk/core/src/org/apache/pivot/collections/ArrayList.java
pivot/trunk/core/src/org/apache/pivot/util/StringUtils.java
Modified: pivot/trunk/core/src/org/apache/pivot/collections/ArrayList.java
URL: http://svn.apache.org/viewvc/pivot/trunk/core/src/org/apache/pivot/collections/ArrayList.java?rev=1884971&r1=1884970&r2=1884971&view=diff
==============================================================================
--- pivot/trunk/core/src/org/apache/pivot/collections/ArrayList.java (original)
+++ pivot/trunk/core/src/org/apache/pivot/collections/ArrayList.java Wed Dec 30 23:25:48 2020
@@ -24,6 +24,7 @@ import java.util.Iterator;
import java.util.NoSuchElementException;
import org.apache.pivot.util.ListenerList;
+import org.apache.pivot.util.StringUtils;
import org.apache.pivot.util.Utils;
/**
@@ -609,19 +610,7 @@ public class ArrayList<T> implements Lis
StringBuilder sb = new StringBuilder();
sb.append(getClass().getSimpleName());
- sb.append(" [");
-
- int i = 0;
- for (T item : this) {
- if (i > 0) {
- sb.append(", ");
- }
-
- sb.append(item);
- i++;
- }
-
- sb.append("]");
+ StringUtils.append(sb, this);
return sb.toString();
}
Modified: pivot/trunk/core/src/org/apache/pivot/util/StringUtils.java
URL: http://svn.apache.org/viewvc/pivot/trunk/core/src/org/apache/pivot/util/StringUtils.java?rev=1884971&r1=1884970&r2=1884971&view=diff
==============================================================================
--- pivot/trunk/core/src/org/apache/pivot/util/StringUtils.java (original)
+++ pivot/trunk/core/src/org/apache/pivot/util/StringUtils.java Wed Dec 30 23:25:48 2020
@@ -25,6 +25,7 @@ import java.math.BigInteger;
* functions.
*/
public final class StringUtils {
+ /** Private constructor since this is a utility class. */
private StringUtils() {
}
@@ -190,6 +191,8 @@ public final class StringUtils {
* that looks like:
* <pre>[item1, item2, ...]</pre>
* appending the results to the given string builder for further use.
+ * <p> If the {@link StringBuilder} has any preceding text (that is, length > 0)
+ * then append a blank before the list representation.
*
* @param <T> The type of items in the list.
* @param sb The {@link StringBuilder} already in progress.
@@ -197,7 +200,11 @@ public final class StringUtils {
* @return The input {@code StringBuilder} for further use.
*/
public static <T> StringBuilder append(final StringBuilder sb, final Iterable<T> list) {
- sb.append("[");
+ // Separate this text from any preceding text
+ if (sb.length() > 0) {
+ sb.append(' ');
+ }
+ sb.append('[');
int i = 0;
for (T item : list) {
@@ -209,7 +216,7 @@ public final class StringUtils {
i++;
}
- sb.append("]");
+ sb.append(']');
return sb;
}