| 1 33 package net.sf.jga.fn.adaptor; 34 35 import java.util.Iterator ; 36 import net.sf.jga.fn.BinaryFunctor; 37 import net.sf.jga.fn.Generator; 38 import net.sf.jga.fn.UnaryFunctor; 39 40 46 47 public final class AdaptorFunctors { 48 49 static private Identity _id = new Identity(); 51 static private Project1st _proj1 = new Project1st(); 52 static private Project2nd _proj2 = new Project2nd(); 53 54 57 static public Generator<Boolean > and(Generator<Boolean > g1, Generator<Boolean > g2) { 58 return new AndGenerator(g1, g2); 59 } 60 61 65 static public <T> UnaryFunctor<T,Boolean > 66 and(UnaryFunctor<T,Boolean > uf1, UnaryFunctor<T,Boolean > uf2) 67 { 68 return new AndUnary<T>(uf1, uf2); 69 } 70 71 75 static public <T1,T2> BinaryFunctor<T1,T2,Boolean > 76 and(BinaryFunctor<T1,T2,Boolean > uf1, BinaryFunctor<T1,T2,Boolean > uf2) 77 { 78 return new AndBinary<T1,T2>(uf1, uf2); 79 } 80 81 82 87 static public <R> Generator<R> conditional(Generator<Boolean > test, Generator<R> trueFn) { 88 return new ConditionalGenerator<R>(test, trueFn, new Constant<R>(null)); 89 } 90 91 96 static public <R> Generator<R> 97 conditional(Generator<Boolean > test, Generator<R> trueFn, Generator<R> falseFn) 98 { 99 return new ConditionalGenerator<R>(test, trueFn, falseFn); 100 } 101 102 107 static public <T,R> UnaryFunctor<T,R> 108 conditional(UnaryFunctor<T,Boolean > test, UnaryFunctor<T,R> trueFn) 109 { 110 return new ConditionalUnary<T,R>(test, trueFn, new ConstantUnary<T,R>(null)); 111 } 112 113 119 static public <T,R> UnaryFunctor<T,R> 120 conditional(UnaryFunctor<T,Boolean > test, UnaryFunctor<T,R> trueFn, UnaryFunctor<T,R> falseFn) 121 { 122 return new ConditionalUnary<T,R>(test, trueFn, falseFn); 123 } 124 125 126 132 static public <T1,T2,R> BinaryFunctor<T1,T2,R> 133 conditional(BinaryFunctor<T1,T2,Boolean > test, BinaryFunctor<T1,T2,R> trueFn) 134 { 135 return new ConditionalBinary<T1,T2,R>(test, trueFn, new ConstantBinary<T1,T2,R>(null)); 136 } 137 138 144 static public <T1,T2,R> BinaryFunctor<T1,T2,R> 145 conditional(BinaryFunctor<T1,T2,Boolean > test, BinaryFunctor<T1,T2,R> trueFn, 146 BinaryFunctor<T1,T2,R> falseFn) 147 { 148 return new ConditionalBinary<T1,T2,R>(test, trueFn, falseFn); 149 } 150 151 152 154 static public <R> Generator<R> constant(R value) { 155 return new Constant<R>(value); 156 } 157 158 159 161 static public <T,R> UnaryFunctor<T,R> constantUnary(R value) { 162 return new ConstantUnary<T,R>(value); 163 } 164 165 166 168 static public <T1,T2,R> BinaryFunctor<T1,T2,R> constantBinary(R value) { 169 return new ConstantBinary<T1,T2,R>(value); 170 } 171 172 173 175 @SuppressWarnings ("unchecked") 176 static public <T> UnaryFunctor<T,T> identity() { 177 return (Identity<T>) _id; 178 } 179 180 181 184 static public Generator<Boolean > or(Generator<Boolean > g1, Generator<Boolean > g2) { 185 return new OrGenerator(g1, g2); 186 } 187 188 189 193 static public <T> UnaryFunctor<T,Boolean > 194 or(UnaryFunctor<T,Boolean > uf1, UnaryFunctor<T,Boolean > uf2) 195 { 196 return new OrUnary<T>(uf1, uf2); 197 } 198 199 200 204 static public <T1,T2> BinaryFunctor<T1,T2,Boolean > 205 or(BinaryFunctor<T1,T2,Boolean > uf1, BinaryFunctor<T1,T2,Boolean > uf2) 206 { 207 return new OrBinary<T1,T2>(uf1, uf2); 208 } 209 210 211 213 @SuppressWarnings ("unchecked") 214 static public <T1,T2> BinaryFunctor<T1,T2,T1> project1st() { 215 return _proj1; 216 } 217 218 219 220 222 @SuppressWarnings ("unchecked") 223 static public <T1,T2> BinaryFunctor<T1,T2,T2> project2nd() { 224 return _proj2; 225 } 226 } 227 228 | Popular Tags |