net.sf.jga.fn.comparison

Class ComparatorFn<T>

public class ComparatorFn<T> extends AbstractBinaryFunctor<T,T,Integer> implements Comparator<T>, Serializable

Functor wrapper around Comparator object. Allows Comparators to be used anywhere a Functor returning an Integer could have been used. Also implements Comparator as well, so an instance of this class could be used anywhere that the constructor argument could be used.

Copyright © 2002 David A. Hall

Author: David A. Hall

Nested Class Summary
interfaceComparatorFn.Visitor
Interface for classes that may interpret a ComparatorFn functor.
Constructor Summary
ComparatorFn(Comparator<T> comp)
Builds the ComparatorFn wrapped around the given Comparator.
Method Summary
voidaccept(Visitor v)
Calls the Visitor's visit(ComperatorFn) method, if it implements the nested Visitor interface.
intcompare(T x, T y)
Integerfn(T x, T y)
Given arguments x and y, return the result of the Comparator's compare(x,y) method, wrapped in an Integer.
Comparator<T>getComparator()
Returns the comparator in use by this functor
StringtoString()

Constructor Detail

ComparatorFn

public ComparatorFn(Comparator<T> comp)
Builds the ComparatorFn wrapped around the given Comparator.

Throws: NullPointerException if no Comparator is passed.

Method Detail

accept

public void accept(Visitor v)
Calls the Visitor's visit(ComperatorFn) method, if it implements the nested Visitor interface.

compare

public int compare(T x, T y)

fn

public Integer fn(T x, T y)
Given arguments x and y, return the result of the Comparator's compare(x,y) method, wrapped in an Integer. Whether or not a NullPointerException is thrown if either x or y are null is up to the Comparator

Returns: the result of the Comparator's compare(x,y) method

getComparator

public Comparator<T> getComparator()
Returns the comparator in use by this functor

toString

public String toString()