Here you can find the source of max(T c1, T c2)
Parameter | Description |
---|---|
c1 | the first comparable, may be null |
c2 | the second comparable, may be null |
public static <T extends Comparable<? super T>> T max(T c1, T c2)
//package com.java2s; /******************************************************************************* * Copyright (c) 2011 MadRobot./* ww w.ja v a2 s. c om*/ * All rights reserved. This program and the accompanying materials * are made available under the terms of the GNU Lesser Public License v2.1 * which accompanies this distribution, and is available at * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html * * Contributors: * Elton Kent - initial API and implementation ******************************************************************************/ public class Main { /** * Null safe comparison of Comparables. * * @param c1 * the first comparable, may be null * @param c2 * the second comparable, may be null * @return * <ul> * <li>If both objects are non-null and unequal, the greater object. * <li>If both objects are non-null and equal, c1. * <li>If one of the comparables is null, the non-null object. * <li>If both the comparables are null, null is returned. * </ul> */ public static <T extends Comparable<? super T>> T max(T c1, T c2) { if (c1 != null && c2 != null) { return c1.compareTo(c2) >= 0 ? c1 : c2; } else { return c1 != null ? c1 : c2; } } }