1 25 26 package org.snipsnap.util.collection; 27 28 import java.util.*; 29 30 37 public class Collections { 38 39 46 public static List filter(List aList, Filterator aFilter) { 47 List filteredList = new ArrayList(); 48 filteredList.addAll(aList); 49 50 Iterator iterator = filteredList.iterator(); 51 while (iterator.hasNext()) { 52 if (aFilter.filter(iterator.next())) { 53 iterator.remove(); 55 } 56 } 57 return filteredList; 58 } 59 60 61 68 public static List transform(List aList, Transformer aTransformer) { 69 List transformedList = new ArrayList(); 70 transformedList.addAll(aList); 71 72 ListIterator iterator = transformedList.listIterator(); 73 while (iterator.hasNext()) { 74 iterator.set(aTransformer.transform(iterator.next())); 75 } 76 return transformedList; 77 } 78 79 80 89 public static String join(Collection aCollection, String delimiter) { 90 StringBuffer sb = new StringBuffer (); 91 92 Iterator iterator = aCollection.iterator(); 93 while (iterator.hasNext()) { 94 sb.append(iterator.next().toString()); 95 if (iterator.hasNext()) { 96 sb.append(delimiter); 97 } 98 } 99 return sb.toString(); 100 } 101 102 103 112 public static List split(String aString, String delimiter) { 113 List list = new ArrayList(); 114 115 StringTokenizer st = new StringTokenizer(aString, delimiter); 116 while (st.hasMoreTokens()) { 117 list.add(st.nextToken()); 118 } 119 return list; 120 } 121 } 122 | Popular Tags |