1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-24 02:12:15 -05:00

Cleanup Utility.combine()

Fix spelling mistakes, simplify adding separators, use unsynchronized
StringBuilder, and fix Javadoc.
This commit is contained in:
Andrew Gaul 2011-05-31 15:11:36 +02:00 committed by cketti
parent c5342472f2
commit 2fd9bd5a03

View File

@ -57,24 +57,25 @@ public class Utility {
} }
/** /**
* Combines the given array of Objects into a single string using the * Combines the given array of Objects into a single String using
* seperator character and each Object's toString() method. between each * each Object's toString() method and the separator character
* part. * between each part.
* *
* @param parts * @param parts
* @param seperator * @param separator
* @return * @return new String
*/ */
public static String combine(Object[] parts, char seperator) { public static String combine(Object[] parts, char separator) {
if (parts == null) { if (parts == null) {
return null; return null;
} else if (parts.length == 0) {
return "";
} }
StringBuffer sb = new StringBuffer(); StringBuilder sb = new StringBuilder();
for (int i = 0; i < parts.length; i++) { sb.append(parts[0]);
sb.append(parts[i].toString()); for (int i = 1; i < parts.length; ++i) {
if (i < parts.length - 1) { sb.append(separator);
sb.append(seperator); sb.append(parts[i]);
}
} }
return sb.toString(); return sb.toString();
} }