net.sf.jga.fn.algorithm

Class MaxValue<T>

public class MaxValue<T> extends AbstractUnaryFunctor<Collection<? extends T>,T> implements Serializable

Identifies the largest value in a collection.

Copyright © 2003 David A. Hall

Author: David A. Hall

Nested Class Summary
interfaceMaxValue.Visitor
Interface for classes that may interpret an MaxValue functor.
Constructor Summary
MaxValue(Comparator<T> comp)
Builds a MaxValue functor that will use the given comparator to compare elements in the collection.
Method Summary
voidaccept(Visitor v)
Calls the Visitor's visit(MaxValue) method, if it implements the nested Visitor interface.
Tfn(Collection<? extends T> collection)
Returns the largest value in the collection
Comparator<T>getComparator()
Returns the comparator used to order values in the collection.
StringtoString()

Constructor Detail

MaxValue

public MaxValue(Comparator<T> comp)
Builds a MaxValue functor that will use the given comparator to compare elements in the collection. Typically, the functor would compare its two arguments and return the greater value.

Throws: IllegalArgumentException if the Comparator is null

Method Detail

accept

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

fn

public T fn(Collection<? extends T> collection)
Returns the largest value in the collection

Throws: NoSuchElementException if the collection is empty

getComparator

public Comparator<T> getComparator()
Returns the comparator used to order values in the collection.

toString

public String toString()