1 16 package org.apache.commons.collections.functors; 17 18 import java.util.Collection ; 19 import java.util.Iterator ; 20 21 import org.apache.commons.collections.Closure; 22 import org.apache.commons.collections.Predicate; 23 import org.apache.commons.collections.Transformer; 24 25 33 class FunctorUtils { 34 35 38 private FunctorUtils() { 39 super(); 40 } 41 42 48 static Predicate[] copy(Predicate[] predicates) { 49 if (predicates == null) { 50 return null; 51 } 52 return (Predicate[]) predicates.clone(); 53 } 54 55 60 static void validate(Predicate[] predicates) { 61 if (predicates == null) { 62 throw new IllegalArgumentException ("The predicate array must not be null"); 63 } 64 for (int i = 0; i < predicates.length; i++) { 65 if (predicates[i] == null) { 66 throw new IllegalArgumentException ("The predicate array must not contain a null predicate, index " + i + " was null"); 67 } 68 } 69 } 70 71 76 static void validateMin2(Predicate[] predicates) { 77 if (predicates == null) { 78 throw new IllegalArgumentException ("The predicate array must not be null"); 79 } 80 if (predicates.length < 2) { 81 throw new IllegalArgumentException ( 82 "At least 2 predicates must be specified in the predicate array, size was " + predicates.length); 83 } 84 for (int i = 0; i < predicates.length; i++) { 85 if (predicates[i] == null) { 86 throw new IllegalArgumentException ("The predicate array must not contain a null predicate, index " + i + " was null"); 87 } 88 } 89 } 90 91 97 static Predicate[] validate(Collection predicates) { 98 if (predicates == null) { 99 throw new IllegalArgumentException ("The predicate collection must not be null"); 100 } 101 if (predicates.size() < 2) { 102 throw new IllegalArgumentException ( 103 "At least 2 predicates must be specified in the predicate collection, size was " + predicates.size()); 104 } 105 Predicate[] preds = new Predicate[predicates.size()]; 107 int i = 0; 108 for (Iterator it = predicates.iterator(); it.hasNext();) { 109 preds[i] = (Predicate) it.next(); 110 if (preds[i] == null) { 111 throw new IllegalArgumentException ("The predicate collection must not contain a null predicate, index " + i + " was null"); 112 } 113 i++; 114 } 115 return preds; 116 } 117 118 124 static Closure[] copy(Closure[] closures) { 125 if (closures == null) { 126 return null; 127 } 128 return (Closure[]) closures.clone(); 129 } 130 131 136 static void validate(Closure[] closures) { 137 if (closures == null) { 138 throw new IllegalArgumentException ("The closure array must not be null"); 139 } 140 for (int i = 0; i < closures.length; i++) { 141 if (closures[i] == null) { 142 throw new IllegalArgumentException ("The closure array must not contain a null closure, index " + i + " was null"); 143 } 144 } 145 } 146 147 153 static Transformer[] copy(Transformer[] transformers) { 154 if (transformers == null) { 155 return null; 156 } 157 return (Transformer[]) transformers.clone(); 158 } 159 160 165 static void validate(Transformer[] transformers) { 166 if (transformers == null) { 167 throw new IllegalArgumentException ("The transformer array must not be null"); 168 } 169 for (int i = 0; i < transformers.length; i++) { 170 if (transformers[i] == null) { 171 throw new IllegalArgumentException ( 172 "The transformer array must not contain a null transformer, index " + i + " was null"); 173 } 174 } 175 } 176 177 } 178 | Popular Tags |