Here you can find the source of min(Comparable c1, Comparable c2)
Parameter | Description |
---|---|
c1 | the first comparable, may be null |
c2 | the second comparable, may be null |
public static Object min(Comparable c1, Comparable c2)
//package com.java2s; public class Main { /**/* w w w .j a v a 2s . c o m*/ * 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 lesser 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 Object min(Comparable c1, Comparable c2) { if (c1 != null && c2 != null) { return c1.compareTo(c2) < 1 ? c1 : c2; } else { return c1 != null ? c1 : c2; } } }