1 33 package net.sf.jga.fn.property; 34 35 import net.sf.jga.fn.BinaryFunctor; 36 import net.sf.jga.fn.UnaryPredicate; 37 import net.sf.jga.fn.comparison.EqualTo; 38 39 63 64 public class CompareProperty<T,V> extends UnaryPredicate<T> { 65 66 static final long serialVersionUID = 8734296101969960336L; 67 68 private BinaryFunctor<V,V,Boolean > _comp; 69 private GetProperty<T,V> _gpf; 70 private String _prop; 71 private V _value; 72 73 78 public CompareProperty(Class <T> argType, String propName, V val) { 79 this(argType, propName, new EqualTo<V>(), val); 80 } 81 82 88 public CompareProperty(Class <T> argType,String propName,BinaryFunctor<V,V,Boolean > pred,V val){ 89 _prop = propName; 90 _comp = pred; 91 _value = val; 92 _gpf = new GetProperty<T, V>(argType, propName); 93 } 94 95 98 102 public String getPropName() { return _prop; } 103 104 108 public V getValue() { return _value; } 109 110 114 public BinaryFunctor<V,V,Boolean > getPredicate() { 115 return _comp; 116 } 117 118 120 126 public Boolean fn(T arg) { 127 return _comp.fn(_gpf.fn(arg), _value); 128 } 129 130 134 public void accept(net.sf.jga.fn.Visitor v) { 135 if (v instanceof CompareProperty.Visitor) 136 ((CompareProperty.Visitor)v).visit(this); 137 else 138 v.visit(this); 139 } 140 141 143 public String toString() { 144 return "CompareProperty["+_prop+" "+_comp+" "+_value+"]"; 145 } 146 147 149 153 public interface Visitor extends net.sf.jga.fn.Visitor { 154 public void visit(CompareProperty host); 155 } 156 } 157 158 159 160 | Popular Tags |