1 16 package org.apache.commons.collections.functors; 17 18 import java.io.Serializable ; 19 20 import org.apache.commons.collections.Closure; 21 22 30 public class ForClosure implements Closure, Serializable { 31 32 33 static final long serialVersionUID = -1190120533393621674L; 34 35 36 private final int iCount; 37 38 private final Closure iClosure; 39 40 50 public static Closure getInstance(int count, Closure closure) { 51 if (count <= 0 || closure == null) { 52 return NOPClosure.INSTANCE; 53 } 54 if (count == 1) { 55 return closure; 56 } 57 return new ForClosure(count, closure); 58 } 59 60 67 public ForClosure(int count, Closure closure) { 68 super(); 69 iCount = count; 70 iClosure = closure; 71 } 72 73 78 public void execute(Object input) { 79 for (int i = 0; i < iCount; i++) { 80 iClosure.execute(input); 81 } 82 } 83 84 90 public Closure getClosure() { 91 return iClosure; 92 } 93 94 100 public int getCount() { 101 return iCount; 102 } 103 104 } 105 | Popular Tags |