1 package net.sf.jga.fn.algorithm; 33 34 import java.util.Iterator ; 35 import net.sf.jga.fn.UnaryFunctor; 36 import net.sf.jga.fn.comparison.EqualTo; 37 import net.sf.jga.fn.comparison.Equality; 38 import net.sf.jga.util.FindIterator; 39 40 48 49 public class Find<T> extends FindIteratorFunctor<T> { 50 51 static final long serialVersionUID = -556722539704270804L; 52 53 private UnaryFunctor<T,Boolean > _eq; 55 56 60 public Find (T value) { 61 this(new EqualTo<T>().bind2nd(value)); 62 } 63 64 68 public Find (Equality<T> eq, T value) { 69 this(eq.bind2nd(value)); 70 } 71 72 76 public Find (UnaryFunctor<T,Boolean > eq) { 77 _eq = eq; 78 } 79 80 84 public UnaryFunctor<T,Boolean > getComparisonFn() { 85 return _eq; 86 } 87 88 94 public FindIterator<T> fn (Iterator <? extends T> iterator) { 95 FindIterator<T> finder = wrap(iterator); 96 finder.findNext(_eq); 97 return finder; 98 } 99 100 104 public void accept(net.sf.jga.fn.Visitor v) { 105 if (v instanceof Find.Visitor) 106 ((Find.Visitor)v).visit(this); 107 else 108 v.visit(this); 109 } 110 111 113 public String toString() { 114 return "Find["+_eq+"]"; 115 } 116 117 119 122 public interface Visitor extends net.sf.jga.fn.Visitor { 123 public void visit(Find host); 124 } 125 } 126 | Popular Tags |