Java Collection Min minOr(Collection values, T defaultVal)

Here you can find the source of minOr(Collection values, T defaultVal)

Description

Like Collections#min(java.util.Collection) except with a default value returned in the case of an empty collection.

License

Open Source License

Declaration

public static <T extends Comparable<T>> T minOr(Collection<T> values,
        T defaultVal) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.Collection;
import java.util.Collections;

public class Main {
    /**// w  w  w  .  ja v  a2 s . c  om
     * Like {@link Collections#min(java.util.Collection)} except with a default value returned in the
     * case of an empty collection.
     */
    public static <T extends Comparable<T>> T minOr(Collection<T> values,
            T defaultVal) {
        if (values.isEmpty()) {
            return defaultVal;
        } else {
            return Collections.min(values);
        }
    }
}

Related

  1. min(Collection values)
  2. min(final Collection collection)
  3. minI(Collection col)
  4. minInt(Collection ints)
  5. minKmerLength(final Collection kmers)