| 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.adaptor.Constant; 37 import net.sf.jga.fn.adaptor.Identity; 38 import net.sf.jga.fn.comparison.EqualTo; 39 import net.sf.jga.fn.comparison.Equality; 40 import net.sf.jga.fn.logical.UnaryNegate; 41 import net.sf.jga.util.FilterIterator; 42 import net.sf.jga.util.TransformIterator; 43 44 52 53 public class RemoveAll<T> 54 extends UnaryFunctor<Iterator <? extends T>, FilterIterator<T>> 55 { 56 static final long serialVersionUID = 8231936204853616237L; 57 58 private UnaryFunctor<T,Boolean > _fn; 59 private UnaryFunctor<T,Boolean > _notFn; 60 61 66 public RemoveAll(T value) { 67 this(new EqualTo<T>().bind2nd(value)); 68 } 69 70 75 public RemoveAll(Equality<T> eq, T value) { 76 this(eq.bind2nd(value)); 77 } 78 79 84 public RemoveAll(UnaryFunctor<T,Boolean > test) { 85 if (test == null) 86 throw new IllegalArgumentException (); 87 88 _fn = test; 89 _notFn = new UnaryNegate<T>(test); 90 } 91 92 95 public UnaryFunctor<T,Boolean > getFunction() { 96 return _fn; 97 } 98 99 105 public FilterIterator<T> fn(Iterator <? extends T> iterator) { 106 return new FilterIterator<T>(iterator, _notFn); 107 } 108 109 113 public void accept(net.sf.jga.fn.Visitor v) { 114 if (v instanceof RemoveAll.Visitor) 115 ((RemoveAll.Visitor)v).visit(this); 116 else 117 v.visit(this); 118 } 119 120 122 public String toString() { 123 return "RemoveAll["+_fn+"]"; 124 } 125 126 128 131 public interface Visitor extends net.sf.jga.fn.Visitor { 132 public void visit(RemoveAll host); 133 } 134 } 135 | Popular Tags |