1 package uk.co.jezuk.mango.algorithms; 2 3 import uk.co.jezuk.mango.UnaryFunction; 4 import java.util.Collection ; 5 import java.util.Iterator ; 6 7 15 public class Transform 16 { 17 public static Collection execute(Iterator iterator, UnaryFunction fn, Collection results) 18 { 19 if(iterator == null || fn == null || results == null) 20 return results; 21 22 while(iterator.hasNext()) 23 { 24 Object o = fn.fn(iterator.next()); 25 if(o != null) 26 { 27 if(o instanceof Collection ) 28 results.addAll((Collection )o); 29 else 30 results.add(o); 31 } } return results; 34 } 36 private Transform() {} 37 } | Popular Tags |