Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 328330

Summary: Utility method to join a collection of strings
Product: [RT] Riena Reporter: Stephan Mann <stephan.mann>
Component: CoreAssignee: 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 Flags
Patch for StringUtils steffen.kriese: iplog+

Description Stephan Mann CLA 2010-10-21 05:53:18 EDT
I'm missing a vital method in the otherwise very handy StringUtils class. The attached patch adds a join method that joins the string representation of a collection of objects to one continues string which (for me at least) is often needed to represent collections in the UI.
Comment 1 Stephan Mann CLA 2010-10-21 05:54:04 EDT
Created attachment 181377 [details]
Patch for StringUtils
Comment 2 Nobody - feel free to take it CLA 2010-10-21 06:33:25 EDT
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()
Comment 3 Nobody - feel free to take it CLA 2010-10-21 06:33:50 EDT
commit