|
25 | 25 | import org.elasticsearch.common.io.FastStringReader; |
26 | 26 | import org.elasticsearch.common.util.CollectionUtils; |
27 | 27 | import org.elasticsearch.common.xcontent.ToXContent; |
28 | | -import org.elasticsearch.common.xcontent.ToXContentObject; |
29 | 28 | import org.elasticsearch.common.xcontent.XContentBuilder; |
30 | 29 | import org.elasticsearch.common.xcontent.json.JsonXContent; |
31 | 30 |
|
@@ -712,18 +711,19 @@ public static Set<String> commaDelimitedListToSet(String str) { |
712 | 711 | * @return the delimited String |
713 | 712 | */ |
714 | 713 | public static String collectionToDelimitedString(Iterable<?> coll, String delim, String prefix, String suffix) { |
715 | | - return collectionToDelimitedString(coll, delim, prefix, suffix, new StringBuilder()); |
| 714 | + StringBuilder sb = new StringBuilder(); |
| 715 | + collectionToDelimitedString(coll, delim, prefix, suffix, sb); |
| 716 | + return sb.toString(); |
716 | 717 | } |
717 | 718 |
|
718 | | - public static String collectionToDelimitedString(Iterable<?> coll, String delim, String prefix, String suffix, StringBuilder sb) { |
| 719 | + public static void collectionToDelimitedString(Iterable<?> coll, String delim, String prefix, String suffix, StringBuilder sb) { |
719 | 720 | Iterator<?> it = coll.iterator(); |
720 | 721 | while (it.hasNext()) { |
721 | 722 | sb.append(prefix).append(it.next()).append(suffix); |
722 | 723 | if (it.hasNext()) { |
723 | 724 | sb.append(delim); |
724 | 725 | } |
725 | 726 | } |
726 | | - return sb.toString(); |
727 | 727 | } |
728 | 728 |
|
729 | 729 | /** |
@@ -758,20 +758,21 @@ public static String collectionToCommaDelimitedString(Iterable<?> coll) { |
758 | 758 | * @return the delimited String |
759 | 759 | */ |
760 | 760 | public static String arrayToDelimitedString(Object[] arr, String delim) { |
761 | | - return arrayToDelimitedString(arr, delim, new StringBuilder()); |
| 761 | + StringBuilder sb = new StringBuilder(); |
| 762 | + arrayToDelimitedString(arr, delim, sb); |
| 763 | + return sb.toString(); |
762 | 764 | } |
763 | 765 |
|
764 | | - public static String arrayToDelimitedString(Object[] arr, String delim, StringBuilder sb) { |
| 766 | + public static void arrayToDelimitedString(Object[] arr, String delim, StringBuilder sb) { |
765 | 767 | if (isEmpty(arr)) { |
766 | | - return ""; |
| 768 | + return; |
767 | 769 | } |
768 | 770 | for (int i = 0; i < arr.length; i++) { |
769 | 771 | if (i > 0) { |
770 | 772 | sb.append(delim); |
771 | 773 | } |
772 | 774 | sb.append(arr[i]); |
773 | 775 | } |
774 | | - return sb.toString(); |
775 | 776 | } |
776 | 777 |
|
777 | 778 | /** |
|
0 commit comments