1 33 package net.sf.jga.fn.adaptor; 34 35 import net.sf.jga.fn.BinaryFunctor; 36 import net.sf.jga.fn.BinaryPredicate; 37 38 43 44 public class OrBinary<T1,T2> extends BinaryPredicate<T1,T2> { 45 46 static final long serialVersionUID = 9139956045465862762L; 47 48 private BinaryFunctor<T1,T2,Boolean > _first; 50 private BinaryFunctor<T1,T2,Boolean > _second; 51 52 56 public OrBinary(BinaryFunctor<T1,T2,Boolean > first, BinaryFunctor<T1,T2,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 BinaryFunctor<T1,T2,Boolean > getFirstFunctor() { return _first; } 67 68 public BinaryFunctor<T1,T2,Boolean > getSecondFunctor() { return _second; } 69 70 71 public Boolean fn(T1 arg1, T2 arg2) { 72 return _first.fn(arg1,arg2) || _second.fn(arg1,arg2); 73 } 74 75 79 public void accept(net.sf.jga.fn.Visitor v) { 80 if (v instanceof OrBinary.Visitor) 81 ((OrBinary.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(OrBinary host); 99 } 100 } 101 | Popular Tags |