| Summary: | Utility method to join a collection of strings | ||||||
|---|---|---|---|---|---|---|---|
| Product: | [RT] Riena | Reporter: | Stephan Mann <stephan.mann> | ||||
| Component: | Core | Assignee: | Project Inbox <riena.core-inbox> | ||||
| Status: | RESOLVED FIXED | QA Contact: | |||||
| Severity: | enhancement | ||||||
| Priority: | P3 | CC: | steffen.kriese | ||||
| Version: | unspecified | ||||||
| Target Milestone: | 3.0.0 | ||||||
| Hardware: | PC | ||||||
| OS: | Windows 7 | ||||||
| Whiteboard: | |||||||
| Attachments: |
|
||||||
|
Description
Stephan Mann
Created attachment 181377 [details]
Patch for StringUtils
I changed the implementation to
/**
* Joins the string representations of an {@link Iterable} collection of
* objects to one continues string while separating the entities with the
* provided separator.
* <p>
* The string representation will be retrieved by String.valueOf()
*
* @param iterable
* The {@link Iterable} number of objects
* @param separator
* @return The joined String separated by the given separator
*/
public static String join(final Iterable<? extends Object> iterable, final CharSequence separator) {
Iterator<? extends Object> oIt;
if (iterable == null || (!(oIt = iterable.iterator()).hasNext())) {
return ""; //$NON-NLS-1$
}
final StringBuilder sb = new StringBuilder(String.valueOf(oIt.next()));
while (oIt.hasNext()) {
sb.append(separator).append(oIt.next());
}
return sb.toString();
}
This way we habe null-handling and don´t create the StringBuilder if we don´t need to.
Added StringUtilsTest#testJoin()
commit |