Java Date Compare min(Calendar... dates)

Here you can find the source of min(Calendar... dates)

Description

Takes in a varargs of calendars and returns the one with the earliest date

License

Apache License

Parameter

Parameter Description
dates These values can be null

Return

Calendar with the least date or null if no valid dates found

Declaration

public static Calendar min(Calendar... dates) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.*;

public class Main {
    /**//from ww w. j  av a2s.c  o m
     * Takes in a varargs of calendars and returns the one with the earliest date
     *
     * @param dates These values can be null
     * @return Calendar with the least date or null if no valid dates found
     */
    public static Calendar min(Calendar... dates) {
        Calendar least = null;
        for (Calendar calendar : dates) {
            if (calendar != null) {
                if (least == null) {
                    least = calendar;
                } else {
                    if (calendar.before(least)) {
                        least = calendar;
                    }
                }
            }
        }
        return least;
    }

    /**
     * Date one comes before date two.
     *
     * @param dt  date one
     * @param dt2 date two
     * @return true if neither are null and the first is before the second
     */
    public static boolean before(Date dt, Date dt2) {
        return !(dt == null || dt2 == null) && dt.before(dt2);

    }
}

Related

  1. max(Collection datumok)
  2. max(Date a, Date b)
  3. max(final Date a, final Date b)
  4. max(Set dateSet)
  5. mergeNonDateKeys(List rowKeys, List columnKeys)
  6. min(Date datum1, Date datum2)
  7. sameTimeInOneMinute(Date date1, Date date2)