Example usage for java.util Date equals

List of usage examples for java.util Date equals

Introduction

In this page you can find the example usage for java.util Date equals.

Prototype

public boolean equals(Object obj) 

Source Link

Document

Compares two dates for equality.

Usage

From source file:org.squale.welcom.outils.DateUtil.java

/**
 * @param day = jour  tester au format Date
 * @return Retourne si la date passe en entre correspond  un jour feri
 *//*www.  j ava  2 s. com*/
public static boolean isPublicHolyday(final Date day) {
    if (day == null) {
        return false;
    }

    final GregorianCalendar gc = new GregorianCalendar();
    gc.setTime(day);

    final ArrayList ph = getPublicHolydays(gc.get(Calendar.YEAR));

    for (final Iterator iter = ph.iterator(); iter.hasNext();) {
        final Date d = (Date) iter.next();

        if (d.equals(day)) {
            return true;
        }
    }

    return false;
}

From source file:org.apache.falcon.entity.FeedHelper.java

private static void validateFeedInstance(Feed feed, Date instanceTime,
        org.apache.falcon.entity.v0.cluster.Cluster cluster) {

    // validate the cluster
    Cluster feedCluster = getCluster(feed, cluster.getName());
    if (feedCluster == null) {
        throw new IllegalArgumentException(
                "Cluster :" + cluster.getName() + " is not a valid cluster for feed:" + feed.getName());
    }//w w w .  j a va2  s  .c  o m

    // validate that instanceTime is in validity range
    if (feedCluster.getValidity().getStart().after(instanceTime)
            || !feedCluster.getValidity().getEnd().after(instanceTime)) {
        throw new IllegalArgumentException("instanceTime: " + instanceTime + " is not in validity range for"
                + " Feed: " + feed.getName() + " on cluster:" + cluster.getName());
    }

    // validate instanceTime on basis of startTime and frequency
    Date nextInstance = EntityUtil.getNextStartTime(feedCluster.getValidity().getStart(), feed.getFrequency(),
            feed.getTimezone(), instanceTime);
    if (!nextInstance.equals(instanceTime)) {
        throw new IllegalArgumentException("instanceTime: " + instanceTime + " is not a valid instance for the "
                + " feed: " + feed.getName() + " on cluster: " + cluster.getName()
                + " on the basis of startDate and frequency");
    }
}

From source file:com.discovery.darchrow.date.DateExtensionUtil.java

/**
 * ?(??),<br>/*from   w  ww.j  a v  a2  s  .  c o  m*/
 * ?? <code>00:00:00.000</code>
 * 
 * <pre>
 * getIntervalDayList("2011-03-5 23:31:25.456","2011-03-10 01:30:24.895", DatePattern.commonWithTime)
 * 
 * return
 * 2011-03-05 00:00:00
 * 2011-03-06 00:00:00
 * 2011-03-07 00:00:00
 * 2011-03-08 00:00:00
 * 2011-03-09 00:00:00
 * 2011-03-10 00:00:00
 * 
 * </pre>
 * 
 * @param fromDateString
 *            
 * @param toDateString
 *            ?
 * @param datePattern
 *            ? {@link DatePattern}
 * @return the interval day list
 * @see DateUtil#getIntervalDay(Date, Date)
 */
public static List<Date> getIntervalDayList(String fromDateString, String toDateString, String datePattern) {
    List<Date> dateList = new ArrayList<Date>();
    //***************************************************************/
    Date beginDate = DateUtil.string2Date(fromDateString, datePattern);
    Date endDate = DateUtil.string2Date(toDateString, datePattern);
    // ******?********
    Date beginDateReset = CalendarUtil.resetDateByDay(beginDate);
    Date endDateReset = CalendarUtil.resetDateByDay(endDate);
    //***************************************************************/
    // 
    int intervalDay = DateUtil.getIntervalDay(beginDateReset, endDateReset);
    //***************************************************************/
    Date minDate = beginDateReset;
    if (beginDateReset.equals(endDateReset)) {
        minDate = beginDateReset;
    } else if (beginDateReset.before(endDateReset)) {
        minDate = beginDateReset;
    } else {
        minDate = endDateReset;
    }
    //***************************************************************/
    dateList.add(minDate);
    //***************************************************************/
    if (intervalDay > 0) {
        for (int i = 0; i < intervalDay; ++i) {
            dateList.add(DateUtil.addDay(minDate, i + 1));
        }
    }
    return dateList;
}

From source file:com.saiton.ccs.validations.FormatAndValidate.java

private static boolean doesTheDateFallsBetween(Date from, Date to, Date date) {

    return (date.equals(from) || date.equals(to) || (date.after(from) && date.before(to)));

}

From source file:oscar.util.DateUtils.java

public static Integer nullSafeCompare(Date d1, Date d2) {
    if (d1 == null && d2 == null)
        return 0;
    if (d1 == null)
        return 1;
    if (d2 == null)
        return -1;

    if (d1.equals(d2))
        return 0;
    if (d1.before(d2))
        return 1;
    if (d2.after(d2))
        return -1;

    return null; //should never happen
}

From source file:org.apache.falcon.entity.EntityUtil.java

/**
 * Returns true if the given instanceTime is a valid instanceTime on the basis of startTime and frequency of an
 * entity./*from   w  w w. j  a va 2  s. c om*/
 *
 * It doesn't check the instanceTime being after the validity of entity.
 * @param startTime startTime of the entity
 * @param frequency frequency of the entity.
 * @param timezone timezone of the entity.
 * @param instanceTime instanceTime to be checked for validity
 * @return
 */
public static boolean isValidInstanceTime(Date startTime, Frequency frequency, TimeZone timezone,
        Date instanceTime) {
    Date next = getNextStartTime(startTime, frequency, timezone, instanceTime);
    return next.equals(instanceTime);
}

From source file:netflow.Main.java

private static long importFile(String fileName, StringTokenizerParser p, boolean processAllFile)
        throws IOException {
    BufferedReader reader = new BufferedReader(new FileReader(fileName));
    int lines = 0;
    int comments = 0;
    int goodLines = 0;
    int oldlines = 0;
    String line;/*w w w.j  av  a  2  s. co  m*/
    DateFormat df = new SimpleDateFormat("HH:mm:ss EEE dd MMM yyyy", Locale.ENGLISH);
    long now = System.currentTimeMillis();
    Date guard = new Date();
    log.info("Begin process " + guard);
    Date last = DatabaseProxy.getInstance().getMaxDate();
    if (last == null) {
        log.info("Date empty. Creating a new one");
        last = new Date();
        last.setTime(0L);
    }
    Date newDate = guard;
    log.info(last);

    HostCache cache = HostCache.getInstance();
    LineProcessor processor = new LineProcessor(cache);
    while ((line = reader.readLine()) != null) {
        if (!line.startsWith("#")) {
            if (last.before(newDate) || processAllFile) {
                String[] elements = p.parseLine(line);
                processor.parseLine(elements);
                goodLines++;
            } else {
                oldlines++;
            }
        } else {
            comments++;

            if (line.startsWith("#Time")) {
                newDate = LineProcessor.parseTime(line, df);
                log.info("Saving hosts " + newDate);
            }

            if (line.startsWith("#EndData") && !cache.isEmpty() && newDate != null && !newDate.equals(guard)) {
                log.info("Saving hosts (finish processing) " + newDate);
                cache.save(newDate);
            }
        }
        lines++;
    }
    log.info(lines + " Comments: " + comments + ", Effective lines: " + goodLines + ", Old lines:" + oldlines);
    return now;
}

From source file:com.example.app.profile.ui.user.ProfileMembershipManagement.java

private static boolean isOverlapped(List<Membership> list) {
    for (Membership m1 : list) {
        final Date startA = m1.getStartDate();
        final Date endA = m1.getEndDate();

        for (Membership m2 : list) {
            if (m1 == m2)
                continue;
            final Date startB = m2.getStartDate();
            final Date endB = m2.getEndDate();
            if ((startA == null || endB == null || startA.before(endB) || startA.equals(endB))
                    && (endA == null || startB == null || endA.after(startB) || endA.equals(startB)))
                return true;
        }/*from  w  w w  .  j  a v a 2s .  c o m*/
    }
    return false;
}

From source file:agileinterop.AgileInterop.java

private static JSONObject getPSRList(String body)
        throws ParseException, InterruptedException, java.text.ParseException, Exception {
    // Parse body as JSON
    JSONParser parser = new JSONParser();
    JSONObject jsonBody = (JSONObject) parser.parse(body);

    Date startDateOriginated = new SimpleDateFormat("MM/dd/yyyy")
            .parse(jsonBody.get("startDateOriginated").toString());
    Date endDateOriginated = new SimpleDateFormat("MM/dd/yyyy")
            .parse(jsonBody.get("endDateOriginated").toString());

    List<String> data = new ArrayList<>();

    class getPSRListForDate implements Runnable {
        private Date dateOriginated;
        private List<String> data;

        public getPSRListForDate(Date dateOriginated, List<String> data) {
            this.dateOriginated = dateOriginated;
            this.data = data;
        }/*from  w  w w  .j  a va2s.  c  o m*/

        public getPSRListForDate(List<String> data) {
            this.data = data;
        }

        @Override
        public void run() {
            try {
                String dateOriginatedString = new SimpleDateFormat("MM/dd/yyyy").format(dateOriginated);

                Long startTime = System.currentTimeMillis();

                IQuery query = (IQuery) Agile.session.createObject(IQuery.OBJECT_TYPE,
                        "Product Service Requests");

                String criteria = "[Cover Page.Date Originated] == '" + dateOriginatedString
                        + " 12:00:00 AM GMT' AND "
                        + "[Cover Page.Type] IN ('Customer Complaint', 'Customer Inquiry', 'Partner Complaint', "
                        + "'Reportable Malfunction / Adverse Event', 'Ancillary Devices & Applications', 'Distributors / Partners', "
                        + "'MDR Decision Tree', 'Investigation Report - No RGA', 'Investigation Report - RGA')";
                query.setCriteria(criteria);

                query.setResultAttributes(new Integer[] { 4856 }); // 4856 = Object ID of [Cover Page.PSR Number]

                ITable queryResults = query.execute();
                queryResults.setPageSize(5000);

                ITwoWayIterator tableIterator = queryResults.getTableIterator();
                while (tableIterator.hasNext()) {
                    IRow row = (IRow) tableIterator.next();
                    data.add(row.getCell(4856).toString()); // 4856 = Object ID of [Cover Page.PSR Number]
                }

                Long endTime = System.currentTimeMillis();

                String logMessage = String.format("getPSRList: Query for %s executed in %d milliseconds",
                        new SimpleDateFormat("yyyy-MM-dd").format(dateOriginated), endTime - startTime);
                System.out.println(logMessage);
            } catch (APIException ex) {
                Logger.getLogger(AgileInterop.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }

    if (startDateOriginated.after(endDateOriginated)) {
        throw new Exception("startDateOriginated is after endDateOriginated. This makes no sense, silly.");
    }

    synchronized (data) {
        Date currentDateOriginated = startDateOriginated;

        ExecutorService executor = Executors.newFixedThreadPool(6);
        do {
            executor.execute(new Thread(new getPSRListForDate(currentDateOriginated, data)));

            Calendar c = Calendar.getInstance();
            c.setTime(currentDateOriginated);
            c.add(Calendar.DATE, 1);

            currentDateOriginated = c.getTime();
        } while (currentDateOriginated.before(endDateOriginated)
                | currentDateOriginated.equals(endDateOriginated));

        executor.shutdown();
        while (!executor.isTerminated()) {
        }
    }

    JSONObject obj = new JSONObject();
    obj.put("data", data);
    return obj;
}

From source file:com.jdom.get.stuff.done.domain.DueWithinDatesFilterOption.java

public boolean accept(Task task) {
    Date date = task.getDueDate();

    return (date.equals(earliest) || date.equals(latest) || (date.after(earliest) && date.before(latest)));
}