[Nice-commit] Nice/stdlib/nice/lang strings.nice,1.16,1.17
Brought to you by:
bonniot
From: Daniel B. <bo...@us...> - 2004-06-27 09:22:09
|
Update of /cvsroot/nice/Nice/stdlib/nice/lang In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11854/stdlib/nice/lang Modified Files: strings.nice Log Message: Replaced join by a generic version on Collection<T>. Contributed by Andy Glover. Index: strings.nice =================================================================== RCS file: /cvsroot/nice/Nice/stdlib/nice/lang/strings.nice,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** strings.nice 20 Mar 2004 11:26:13 -0000 1.16 --- strings.nice 27 Jun 2004 09:22:00 -0000 1.17 *************** *** 95,115 **** /** ! * Join a collection of strings together, interspersing <code>separator</code> * among them. * ! * @param strings the strings to join ! * @param separator the separator string to place between each * string and the one before it */ ! String join(Collection<String> strings, String separator) { StringBuffer buff = new StringBuffer(); ! Iterator<String> it = strings.iterator(); ! while(it.hasNext()) { ! buff.append(it.next()); ! if (it.hasNext()) ! buff.append(separator); } return buff.toString(); } --- 95,118 ---- /** ! * Represent the elements of a collection, interspersing <code>separator</code> * among them. * ! * @param collection the collection to join ! * @param separator the separator string to place between each * string and the one before it */ ! <T> String join (Collection<T> collection, String value = " ") { StringBuffer buff = new StringBuffer(); ! let size = collection.size(); ! var x = 0; ! ! for (T elem : collection) { ! buff.append(elem); ! if(++x < size) ! buff.append(value); } + return buff.toString(); } |