1 33 package net.sf.jga.fn.adaptor; 34 35 import net.sf.jga.fn.UnaryFunctor; 36 import net.sf.jga.fn.UnaryPredicate; 37 38 43 44 public class AndUnary<T> extends UnaryPredicate<T> { 45 46 static final long serialVersionUID = -4087333621367458086L; 47 48 private UnaryFunctor<T,Boolean > _first; 50 private UnaryFunctor<T,Boolean > _second; 51 52 56 public AndUnary(UnaryFunctor<T,Boolean > first, UnaryFunctor<T,Boolean > second) { 57 if (first == null || second == null) { 58 throw new IllegalArgumentException ("Two functors are required"); 59 } 60 61 _first = first; 62 _second = second; 63 } 64 65 66 public UnaryFunctor<T,Boolean > getFirstFunctor() { return _first; } 67 68 public UnaryFunctor<T,Boolean > getSecondFunctor() { return _second; } 69 70 71 public Boolean fn(T arg) { 72 return _first.fn(arg) && _second.fn(arg); 73 } 74 75 79 public void accept(net.sf.jga.fn.Visitor v) { 80 if (v instanceof AndUnary.Visitor) 81 ((AndUnary.Visitor)v).visit(this); 82 else 83 v.visit(this); 84 } 85 86 88 public String toString() { 89 return _first +" && " +_second; 90 } 91 92 94 97 public interface Visitor extends net.sf.jga.fn.Visitor { 98 public void visit(AndUnary host); 99 } 100 } 101 | Popular Tags |