1 33 package net.sf.jga.fn.algorithm; 34 35 import java.util.Collection ; 36 import java.util.Collections ; 37 import java.util.Iterator ; 38 import java.util.Vector ; 39 import net.sf.jga.fn.BinaryFunctor; 40 import net.sf.jga.fn.UnaryFunctor; 41 import net.sf.jga.util.FindIterator; 42 43 53 54 public class FindElement<T> extends FindIteratorFunctor<T> { 55 56 static final long serialVersionUID = -1746637029942790280L; 57 58 private BinaryFunctor<T,T,Boolean > _bf; 60 61 private UnaryFunctor<T,Boolean > _uf; 63 64 private Collection <? extends T> _elements; 66 67 71 public FindElement(Collection <? extends T> elements) { 72 _elements = (elements == null) ? new Vector <T>() : elements; 73 _uf = new ElementOf<T>().bind2nd(elements); 74 } 75 76 81 public FindElement(Collection <? extends T> elements, 82 BinaryFunctor<T,T,Boolean > eq ) 83 { 84 _bf = eq; 85 _elements = (elements == null) ? new Vector <T>() : elements; 86 _uf = new ElementOf<T>(eq).bind2nd(elements); 87 } 88 89 92 public Collection <? extends T> getElementSet() { 93 return Collections.unmodifiableCollection(_elements); 94 } 95 96 100 public BinaryFunctor<T,T,Boolean > getComparisonFn() { 101 return _bf; 102 } 103 104 106 115 public FindIterator<T> fn(Iterator <? extends T> iterator) { 116 FindIterator<T> finder = wrap(iterator); 117 finder.findNext(_uf); 118 return finder; 119 } 120 121 125 public void accept(net.sf.jga.fn.Visitor v) { 126 if (v instanceof FindElement.Visitor) 127 ((FindElement.Visitor)v).visit(this); 128 else 129 v.visit(this); 130 } 131 132 134 public String toString() { 135 return "FindElement"; 136 } 137 138 140 144 public interface Visitor extends net.sf.jga.fn.Visitor { 145 public void visit(FindElement host); 146 } 147 148 } 149 | Popular Tags |