net.sf.jga.fn.algorithm
Class MaxValue<T>

java.lang.Object
  extended by net.sf.jga.fn.UnaryFunctor<java.util.Collection<? extends T>,T>
      extended by net.sf.jga.fn.algorithm.MaxValue<T>
All Implemented Interfaces:
java.io.Serializable, Visitable

public class MaxValue<T>
extends UnaryFunctor<java.util.Collection<? extends T>,T>

Identifies the largest value in a collection.

To serialize a MaxValue, the comparator passed at construction must be Serializable.

Copyright © 2003 David A. Hall

Author:
David A. Hall
See Also:
Serialized Form

Nested Class Summary
static interface MaxValue.Visitor
          Interface for classes that may interpret an MaxValue functor.
 
Constructor Summary
MaxValue(java.util.Comparator<T> comp)
          Builds a MaxValue functor that will use the given comparator to compare elements in the collection.
 
Method Summary
 void accept(Visitor v)
          Calls the Visitor's visit(MaxValue) method, if it implements the nested Visitor interface.
 T fn(java.util.Collection<? extends T> collection)
          Returns the largest value in the collection
 java.util.Comparator<T> getComparator()
          Returns the comparator used to order values in the collection.
 java.lang.String toString()
           
 
Methods inherited from class net.sf.jga.fn.UnaryFunctor
bind, compose, compose, generate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MaxValue

public MaxValue(java.util.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:
java.lang.IllegalArgumentException - if the Comparator is null
Method Detail

getComparator

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


fn

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

Specified by:
fn in class UnaryFunctor<java.util.Collection<? extends T>,T>
Throws:
NoSuchElementException - if the collection is empty

accept

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

Specified by:
accept in interface Visitable
Overrides:
accept in class UnaryFunctor<java.util.Collection<? extends T>,T>

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Copyright © 2002-2005 David A. Hall. All Rights Reserved.