1 package net.sf.jga.fn.comparison; 33 34 import java.util.Comparator ; 35 import net.sf.jga.fn.BinaryFunctor; 36 import net.sf.jga.util.ComparableComparator; 37 38 56 57 public class Max<T> extends BinaryFunctor<T,T,T> { 58 59 static final long serialVersionUID = -8414037855280091672L; 60 61 private Comparator <? super T> _comp; 63 64 68 public Max(Comparator <? super T> comp) { 69 if (comp == null) { 70 throw new IllegalArgumentException ("Comparator may not be null"); 71 } 72 73 _comp = comp; 74 } 75 76 80 public Comparator <? super T> getComparator() { return _comp; } 81 82 84 88 public T fn(T x, T y) { 89 return _comp.compare(x,y) >= 0 ? x : y; 90 } 91 92 96 public void accept(net.sf.jga.fn.Visitor v) { 97 if (v instanceof Max.Visitor) 98 ((Max.Visitor)v).visit(this); 99 else 100 v.visit(this); 101 } 102 103 105 public String toString() { 106 return "Max"; 107 } 108 109 111 114 public interface Visitor extends net.sf.jga.fn.Visitor { 115 public void visit(Max host); 116 } 117 118 119 124 125 static public class Comparable<T extends java.lang.Comparable <? super T>> 126 extends Max<T> 127 { 128 static final long serialVersionUID = 2442624792379403532L; 129 public Comparable() { super(new ComparableComparator<T>()); } 130 } 131 } 132 | Popular Tags |