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:playground.jbischoff.taxi.berlin.supply.TaxiStatusDataAnalyser.java

@SuppressWarnings("deprecation")
public static void dumpTaxisInSystem(Matrices statusMatrices, String start, String end, String averagesFile,
        String taxisOverTimeFile) {
    Map<String, Double> taxisInSystem = new TreeMap<String, Double>();
    Map<String, Double> averageTaxisPerHour = new TreeMap<String, Double>();

    SimpleDateFormat hrs = new SimpleDateFormat("yyyyMMddHH");

    try {/*from   w w  w . j a  va2s. c  o m*/
        Date currentTime = STATUS_DATE_FORMAT.parse(start);
        Date endTime = STATUS_DATE_FORMAT.parse(end);

        double hourTaxis = 0.;
        double filesPerhr = 12;

        while (!currentTime.equals(endTime)) {
            Matrix matrix = statusMatrices.getMatrix(STATUS_DATE_FORMAT.format(currentTime));
            if (matrix == null) {
                System.err.println("id: " + STATUS_DATE_FORMAT.format(currentTime) + " not found");
                currentTime = getNextTime(currentTime);
                filesPerhr--;
                continue;
            }

            Iterable<Entry> entryIter = MatrixUtils.createEntryIterable(matrix);
            double totalTaxis = 0.;
            for (Entry e : entryIter) {
                totalTaxis += e.getValue();
                hourTaxis += e.getValue();
            }

            taxisInSystem.put(STATUS_DATE_FORMAT.format(currentTime), totalTaxis);

            if (currentTime.getMinutes() == 55) {
                double average = hourTaxis / filesPerhr;
                String t = hrs.format(currentTime);
                averageTaxisPerHour.put(t, average);
                hourTaxis = 0.;
                filesPerhr = 12.;
            }
            currentTime = getNextTime(currentTime);

        }

        dumpMapToFile(averageTaxisPerHour, averagesFile);
        dumpMapToFile(taxisInSystem, taxisOverTimeFile);
    } catch (ParseException e) {
        e.printStackTrace();
    }
}

From source file:playground.jbischoff.taxi.berlin.supply.TaxiStatusDataAnalyser.java

private static void writeStatusByZone(Matrices statusMatrices, String zonalStatuses, String start, String end)
        throws ParseException {
    Date currentTime = STATUS_DATE_FORMAT.parse(start);
    Date endTime = STATUS_DATE_FORMAT.parse(end);
    Map<String, IdleStatusEntry> statuses = new TreeMap<String, IdleStatusEntry>();

    while (!currentTime.equals(endTime)) {
        Matrix m = statusMatrices.getMatrix(STATUS_DATE_FORMAT.format(currentTime));
        System.out.println(STATUS_DATE_FORMAT.format(currentTime));
        if (m == null) {
            System.err.println("time comes without status" + STATUS_DATE_FORMAT.format(currentTime));
            currentTime = getNextTime(currentTime);

            continue;
        }/*  w w w.jav  a 2  s . c  o m*/
        for (ArrayList<Entry> l : m.getFromLocations().values()) {

            for (Entry e : l) {
                if (!statuses.containsKey(e.getFromLocation())) {
                    statuses.put(e.getFromLocation(), new IdleStatusEntry(e.getFromLocation()));
                }
                IdleStatusEntry ent = statuses.get(e.getFromLocation());
                if (e.getToLocation().equals("65"))
                    ent.inc65(e.getValue());
                if (e.getToLocation().equals("66"))
                    ent.inc66(e.getValue());
                if (e.getToLocation().equals("70"))
                    ent.inc70(e.getValue());
                if (e.getToLocation().equals("75"))
                    ent.inc75(e.getValue());
                if (e.getToLocation().equals("79"))
                    ent.inc79(e.getValue());
                if (e.getToLocation().equals("80"))
                    ent.inc80(e.getValue());
                if (e.getToLocation().equals("83"))
                    ent.inc83(e.getValue());
                if (e.getToLocation().equals("85"))
                    ent.inc85(e.getValue());
                if (e.getToLocation().equals("87"))
                    ent.inc87(e.getValue());
                if (e.getToLocation().equals("90"))
                    ent.inc90(e.getValue());
            }
        }
        currentTime = getNextTime(currentTime);
    }
    BufferedWriter bw = IOUtils.getBufferedWriter(zonalStatuses);
    try {
        bw.append("zone\ts65\ts66\ts70\ts75\ts79\tss80\ts83\ts85\ts87\ts90\tsum (wait)");
        bw.newLine();
        for (IdleStatusEntry ise : statuses.values()) {
            bw.append(ise.toString());
            bw.newLine();
        }
        bw.flush();
        bw.close();

    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

From source file:org.openmrs.module.providermanagement.ProviderManagementUtils.java

/**
 * Returns true/false whether the relationship is active on the current date
 *
 * Note that if a relationship ends on a certain date, it is not considered active on that date
 *
 * @param relationship/*from w ww . j  ava  2 s . c o  m*/
 * @return
 */
public static boolean isRelationshipActive(Relationship relationship) {

    Date startDate = clearTimeComponent(relationship.getStartDate());
    Date endDate = relationship.getEndDate() != null ? clearTimeComponent(relationship.getEndDate()) : null;
    Date currentDate = clearTimeComponent(new Date());

    if (endDate != null && startDate.after(endDate)) {
        throw new APIException(
                "relationship start date cannot be after end date: relationship id " + relationship.getId());
    }

    return (startDate.before(currentDate) || startDate.equals(currentDate))
            && (endDate == null || endDate.after(currentDate));
}

From source file:nu.mine.kino.projects.utils.ViewUtils.java

public static PVACEVViewBean getPVACEVViewBean(TaskInformation todayTaskInfo, Date targetDate) {
    PVACEVViewBean bean = new PVACEVViewBean();

    Task task = todayTaskInfo.getTask();
    Task2PVACEVViewBean.convert(task, bean);

    PVBean pvBean = ProjectUtils.getPVBean(todayTaskInfo, targetDate);
    // ACBean acBean = ProjectUtils.getACBean(todayTaskInfo, baseTaskInfo);
    // EVBean evBean = ProjectUtils.getEVBean(todayTaskInfo, baseTaskInfo);

    PVBean2PVACEVViewBean.convert(pvBean, bean);
    // ACBean2PVACEVViewBean.convert(acBean, bean);
    // EVBean2PVACEVViewBean.convert(evBean, bean);
    bean.setProgressRate(Utils.round(todayTaskInfo.getEV().getProgressRate()));

    PVBean pvBean_p1 = ProjectUtils.getPVBean(todayTaskInfo, DateUtils.addDays(targetDate, 1));
    bean.setPlannedValue_p1(pvBean_p1.getPlannedValue());
    // RR`FbN?Av?^XN\L
    // //////////////
    // XPW?[??A100%
    Date scheduledEndDate = bean.getScheduledEndDate();
    Date baseDate = bean.getBaseDate();
    if (scheduledEndDate != null) {
        // \(scheEndDate)?A?(baseDate)O()??
        boolean isDelay = scheduledEndDate.before(baseDate) || scheduledEndDate.equals(baseDate);
        // x?A???B
        if (isDelay && bean.getProgressRate() != 1.0) {
            bean.setCheck(true);/*  w  w w . java  2  s. c om*/
        }
    }
    // //////////////
    return bean;
}

From source file:nu.mine.kino.projects.utils.ViewUtils.java

public static PVACEVViewBean getPVACEVViewBean(TaskInformation todayTaskInfo, TaskInformation baseTaskInfo,
        Date targetDate) {//from  w w w .ja  va  2 s .  co  m
    PVACEVViewBean bean = new PVACEVViewBean();

    Task task = todayTaskInfo.getTask();
    Task2PVACEVViewBean.convert(task, bean);

    // PVBean pvBean = ProjectUtils.getPVBean(todayTaskInfo, targetDate);
    PVBean pvBean = ProjectUtils.getPVBean(todayTaskInfo, baseTaskInfo);
    ACBean acBean = ProjectUtils.getACBean(todayTaskInfo, baseTaskInfo);
    EVBean evBean = ProjectUtils.getEVBean(todayTaskInfo, baseTaskInfo);

    PVBean2PVACEVViewBean.convert(pvBean, bean);
    ACBean2PVACEVViewBean.convert(acBean, bean);
    EVBean2PVACEVViewBean.convert(evBean, bean);
    bean.setProgressRate(Utils.round(todayTaskInfo.getEV().getProgressRate()));

    PVBean pvBean_p1 = ProjectUtils.getPVBean(todayTaskInfo, DateUtils.addDays(targetDate, 1));
    bean.setPlannedValue_p1(pvBean_p1.getPlannedValue());
    // RR`FbN?Av?^XN\L
    // //////////////
    // XPW?[??A100%
    Date scheduledEndDate = bean.getScheduledEndDate();
    Date baseDate = bean.getBaseDate();
    if (scheduledEndDate != null) {
        // \(scheEndDate)?A?(baseDate)O()??
        boolean isDelay = scheduledEndDate.before(baseDate) || scheduledEndDate.equals(baseDate);
        // x?A???B
        if (isDelay && bean.getProgressRate() != 1.0) {
            bean.setCheck(true);
        }
    }
    // //////////////
    return bean;
}

From source file:com.clustercontrol.accesscontrol.util.ClientSession.java

/**
 * Check/*from  w  ww.  ja v  a  2  s  .c o  m*/
 */
public static void doCheck() {
    m_log.trace("ClientSession.doCheck() start");

    // ?
    try {
        if (!LoginManager.isLogin()) {
            m_log.trace("ClientSession.doCheck() Not logged in yet. Skip.");
            return;
        }

        // ???
        for (EndpointUnit endpointUnit : EndpointManager.getAllManagerList()) {
            String managerName = endpointUnit.getManagerName();
            m_log.trace("ClientSession.doCheck() Get last updated time from Manager " + managerName);
            Date lastUpdateManager = null;
            if (endpointUnit.isActive()) {
                try {
                    RepositoryEndpointWrapper wrapper = RepositoryEndpointWrapper.getWrapper(managerName);
                    lastUpdateManager = new Date(wrapper.getLastUpdate());
                    m_log.trace("ClientSession.doCheck() lastUpdate(Manager) = " + lastUpdateManager);
                } catch (Exception e) {
                    // ???????
                    if (e instanceof ClientTransportException || e instanceof WebServiceException) {
                        m_log.warn("ClientSession.doCheck() Manager is dead ! , " + e.getClass().getName()
                                + ", " + e.getMessage());
                    } else {
                        // ?
                        m_log.warn("ClientSession.doCheck() Manager is dead !! , " + e.getClass().getName()
                                + ", " + e.getMessage(), e);
                    }
                    // ?
                    LoginManager.forceLogout(managerName);
                }
            }

            Date lastUpdateClient = FacilityTreeCache.getCacheDate(managerName);

            // ??????
            if (lastUpdateManager == lastUpdateClient)
                continue;

            boolean update = false;
            if (lastUpdateClient == null) {
                update = true;
            } else {
                update = !lastUpdateClient.equals(lastUpdateManager);
            }

            if (update) {
                m_log.debug("ClientSession.doCheck() lastUpdate(Manager)=" + lastUpdateManager
                        + ", lastUpdate(Client)=" + lastUpdateClient + ", " + managerName);
                // ????????
                FacilityTreeCache.refresh(managerName, lastUpdateManager);
            }
        }
    } catch (RuntimeException e) {
        m_log.warn("doCheck : " + e.getClass().getName() + ", message=" + e.getMessage(), e);
    }
}

From source file:org.craftercms.cstudio.alfresco.dm.util.DmUtils.java

public static boolean areEqual(Date oldDate, Date newDate) {
    if (oldDate == null && newDate == null) {
        return true;
    }//from w  w  w  . j av a2s  . com
    if (oldDate != null && newDate != null) {
        return oldDate.equals(newDate);
    }
    return false;
}

From source file:net.kamhon.ieagle.util.DateUtil.java

/**
 * Not Consider time. Just compare date.
 * /*from w  w w .j a  v  a2s  .  co  m*/
 * @param date
 * @param startDate
 * @param endDate
 * @return
 */
public static boolean isBetweenDate(Date date, Date startDate, Date endDate) {
    Date clonedDate = (Date) date.clone();
    clonedDate = formatDateByTime(clonedDate, 0, 0, 0, 0);

    Date clonedStartDate = (Date) startDate.clone();
    Date clonedEndDate = (Date) endDate.clone();

    clonedStartDate = formatDateByTime(clonedStartDate, 0, 0, 0, 0);
    clonedEndDate = formatDateByTime(clonedEndDate, 23, 59, 59, 999);

    return (clonedDate.equals(clonedStartDate) || clonedDate.after(clonedStartDate))
            && (clonedDate.equals(clonedEndDate) || clonedDate.before(clonedEndDate));
}

From source file:org.apache.lens.cube.metadata.DateUtil.java

public static CoveringInfo getYearlyCoveringInfo(Date from, Date to) {
    CoveringInfo monthlyCoveringInfo = getMonthlyCoveringInfo(from, to);
    if (monthlyCoveringInfo.getCountBetween() < 12) {
        return new CoveringInfo(0, false);
    }//from   ww w  .  java  2s  . c  om
    boolean coverable = monthlyCoveringInfo.isCoverable();
    if (!from.equals(DateUtils.truncate(from, MONTH))) {
        from = DateUtils.addMonths(DateUtils.truncate(from, MONTH), 1);
        coverable = false;
    }
    Calendar cal = Calendar.getInstance();
    cal.setTime(from);
    int fromMonth = cal.get(MONTH);
    int beginOffset = (12 - fromMonth % 12) % 12;
    int endOffset = (monthlyCoveringInfo.getCountBetween() - beginOffset) % 12;
    if (beginOffset > 0 || endOffset > 0) {
        coverable = false;
    }
    return new CoveringInfo((monthlyCoveringInfo.getCountBetween() - beginOffset - endOffset) / 12, coverable);
}

From source file:org.apache.lens.cube.metadata.DateUtil.java

public static CoveringInfo getQuarterlyCoveringInfo(Date from, Date to) {
    CoveringInfo monthlyCoveringInfo = getMonthlyCoveringInfo(from, to);
    if (monthlyCoveringInfo.getCountBetween() < 3) {
        return new CoveringInfo(0, false);
    }//ww w .  jav  a2 s .com
    boolean coverable = monthlyCoveringInfo.isCoverable();
    if (!from.equals(DateUtils.truncate(from, MONTH))) {
        from = DateUtils.addMonths(DateUtils.truncate(from, MONTH), 1);
        coverable = false;
    }
    Calendar cal = Calendar.getInstance();
    cal.setTime(from);
    int fromMonth = cal.get(MONTH);

    // Get the start date of the quarter
    int beginOffset = (3 - fromMonth % 3) % 3;
    int endOffset = (monthlyCoveringInfo.getCountBetween() - beginOffset) % 3;
    if (beginOffset > 0 || endOffset > 0) {
        coverable = false;
    }
    return new CoveringInfo((monthlyCoveringInfo.getCountBetween() - beginOffset - endOffset) / 3, coverable);
}