Java Number Min Value min(T c1, T c2)

Here you can find the source of min(T c1, T c2)

Description

Gets minimal value between given two.

License

MIT License

Parameter

Parameter Description
c1 First value to be compared
c2 Second value to be compared

Return

First value will be returned if given c1 is less or equal to c2 . null value is considered as less than not null one.

Declaration

public static <T extends Comparable<T>> T min(T c1, T c2) 

Method Source Code

//package com.java2s;
/*//from w  w  w .j ava  2 s .co m
 * Copyright 2014 Maxim Dominichenko
 * 
 * Licensed under The MIT License (MIT) (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * https://github.com/domax/gwt-dynamic-plugins/blob/master/LICENSE
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

public class Main {
    /**
     * Gets minimal value between given two.
     * 
     * @param c1
     *          First value to be compared
     * @param c2
     *          Second value to be compared
     * @return First value will be returned if given {@code c1} is less or equal to {@code c2}. {@code null} value is
     *         considered as less than not {@code null} one.
     */
    public static <T extends Comparable<T>> T min(T c1, T c2) {
        if (c1 == c2)
            return c1;
        if (c1 == null)
            return c1;
        if (c2 == null)
            return c2;
        return c1.compareTo(c2) <= 0 ? c1 : c2;
    }
}

Related

  1. min(String in, int len)
  2. min(String name)
  3. min(String s)
  4. min(T a, T b)
  5. min(T a, T b)
  6. min(T v1, T v2)
  7. min(T v1, T v2, int nullSupport)
  8. min2(double a, double b)
  9. min2(int a, int b)