net.sf.molae.pipe.sorted
Class Min<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.Min<T>
All Implemented Interfaces:
BinaryFunction<T,T,T>

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

The binary function returning the minimum of two objects.

Since:
1.1
See Also:
Max

Constructor Summary
Min(Comparator<? super T> comparator)
          Creates a new minimum function based on the specified comparator.
Min(Comparator<? super T> comparator, T negativeInfinity, T positiveInfinity)
          Creates a new minimum function with the specified properties.
 
Method Summary
 T compute(T arg1, T arg2)
          Compares the two specified objects and returns the smaller one.
static
<T extends Comparable<T>>
Min<T>
getInstance()
          Returns the default instance of this class.
static
<T extends Comparable<T>>
T
min(Collection<T> c)
          Returns the smallest element from the specified collection.
static
<T> T
min(Collection<T> c, Comparator<? super T> comparator)
          Returns the smallest 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

Min

public Min(Comparator<? super T> comparator,
           T negativeInfinity,
           T positiveInfinity)
Creates a new minimum 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.

Min

public Min(Comparator<? super T> comparator)
Creates a new minimum 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>> Min<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 smaller 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 minimum 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.

min

public static <T> T min(Collection<T> c,
                        Comparator<? super T> comparator)
Returns the smallest 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 smallest element from the specified collection.

min

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

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