net.sf.molae.pipe.sorted
Class Max<T>

java.lang.Object
  extended by net.sf.molae.pipe.binop.AbstractBinaryFunction<S,S,T>
      extended by net.sf.molae.pipe.binop.SymmetricBinaryFunction<T,T>
          extended by net.sf.molae.pipe.sorted.Max<T>
All Implemented Interfaces:
BinaryFunction<T,T,T>

public final class Max<T>
extends SymmetricBinaryFunction<T,T>

The binary function returning the maximum of two objects.

Since:
1.1
See Also:
Min

Constructor Summary
Max(Comparator<? super T> comparator)
          Creates a new maximum function based on the specified comparator.
Max(Comparator<? super T> comparator, T negativeInfinity, T positiveInfinity)
          Creates a new maximum function with the specified properties.
 
Method Summary
 T compute(T arg1, T arg2)
          Compares the two specified objects and returns the greater one.
static
<T extends Comparable<T>>
Max<T>
getInstance()
          Returns the default instance of this class.
static
<T extends Comparable<T>>
T
max(Collection<T> c)
          Returns the greatest element from the specified collection.
static
<T> T
max(Collection<T> c, Comparator<T> comparator)
          Returns the greatest element from the specified collection using the specified comparator.
 
Methods inherited from class net.sf.molae.pipe.binop.SymmetricBinaryFunction
getIdentityElement, getSink, isAnIdentityElement, isASink
 
Methods inherited from class net.sf.molae.pipe.binop.AbstractBinaryFunction
getFirstInverse, getPermuted, isAssociative, isLeftSink, isRightIdentityElement, setFirstInverse, setPermuted, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Max

public Max(Comparator<? super T> comparator,
           T negativeInfinity,
           T positiveInfinity)
Creates a new maximum function with the specified properties.

Parameters:
comparator - comparator to use for comparison or null if natural ordering is used
negativeInfinity - the negative infinity of the comparator or null if such an element does not exist.
positiveInfinity - the positive infinity of the comparator or null if such an element does not exist.

Max

public Max(Comparator<? super T> comparator)
Creates a new maximum function based on the specified comparator.

Parameters:
comparator - comparator to use for comparison or null if natural ordering is used
Method Detail

getInstance

public static <T extends Comparable<T>> Max<T> getInstance()
Returns the default instance of this class.

Returns:
the default instance of this class.

compute

public T compute(T arg1,
                 T arg2)
Compares the two specified objects and returns the greater one.

Specified by:
compute in interface BinaryFunction<T,T,T>
Specified by:
compute in class AbstractBinaryFunction<T,T,T>
Parameters:
arg1 - first object to compare
arg2 - second object to compare
Returns:
The maximum of arg1 and arg2. If both are equal, arg1 is returned.
Throws:
ClassCastException - if arg1 and arg2 cannot be compared to one another using the underlying comparator (or, if it is null, using natural ordering).
NullPointerException - if o1 or o2 is null and natural order is used, or if the comparator does not tolerate null elements.

max

public static <T> T max(Collection<T> c,
                        Comparator<T> comparator)
Returns the greatest element from the specified collection using the specified comparator. If the collection is empty, null is returned.

Parameters:
c - collection to search
comparator - comparator to use for comparison or null if natural ordering is used
Returns:
the greatest element from the specified collection.

max

public static <T extends Comparable<T>> T max(Collection<T> c)
Returns the greatest element from the specified collection. If the collection is empty, null is returned.

Parameters:
c - collection to search
Returns:
the greatest element from the specified collection.