Java Number Max Value max(T c1, T c2)

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

Description

Gets maximal 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 greater or equal to c2 . null value is considered as less than not null one.

Declaration

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

Method Source Code

//package com.java2s;
/*/*from w  ww. j a  va2s.c om*/
 * 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 maximal 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 greater or equal to {@code c2}. {@code null} value is
     *         considered as less than not {@code null} one.
     */
    public static <T extends Comparable<T>> T max(T c1, T c2) {
        if (c1 == c2)
            return c1;
        if (c1 == null)
            return c2;
        if (c2 == null)
            return c1;
        return c1.compareTo(c2) >= 0 ? c1 : c2;
    }
}

Related

  1. max(String name)
  2. max(String s)
  3. max(T a, T b)
  4. max(T a, T b)
  5. max(T c1, T c2)
  6. max(T v1, T v2)
  7. max(T v1, T v2, int nullSupport)
  8. max2(double a, double b)
  9. max2(int a, int b)