Example usage for java.sql Date equals

List of usage examples for java.sql Date equals

Introduction

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

Prototype

public boolean equals(Object obj) 

Source Link

Document

Compares two dates for equality.

Usage

From source file:org.apache.hadoop.hive.ql.udf.UDFOPNotEqual.java

public Boolean evaluate(Date a, Date b) {
    Boolean r = null;/* w w w . j a  va  2 s.  c o  m*/
    if ((a == null) || (b == null)) {
        r = null;
    } else {
        r = Boolean.valueOf(!a.equals(b));
    }
    // LOG.info("evaluate(" + a + "," + b + ")=" + r);
    return r;
}

From source file:org.apache.hadoop.hive.ql.udf.UDFOPEqual.java

public Boolean evaluate(Date a, Date b) {
    Boolean r = null;/*from w  w  w. jav a  2  s . c  om*/
    if ((a == null) || (b == null)) {
        r = null;
    } else {
        r = Boolean.valueOf(a.equals(b));
    }
    // LOG.info("evaluate(" + a + "," + b + ")=" + r);
    return r;
}

From source file:org.kuali.kra.committee.bo.CommitteeScheduleTest.java

@Test
public void testIsActiveFor() {
    // create two schedules with two different dates. one in November and the other in December
    CommitteeSchedule novemberSchedule = new CommitteeSchedule();
    novemberSchedule.setScheduledDate(Date.valueOf("2011-11-25"));

    CommitteeSchedule decemberSchedule = new CommitteeSchedule();
    decemberSchedule.setScheduledDate(Date.valueOf("2011-12-25"));

    // create four committee membership mock objects, 
    // one active only for November date, one active for only December date, 
    // one active for both dates, and the last inactive for both dates.
    CommitteeMembership novemberMember = new CommitteeMembership() {
        public boolean isActive(Date date) {
            if (date.equals(Date.valueOf("2011-11-25"))) {
                return true;
            } else {
                return false;
            }//from ww  w . jav a2s .  c  o m
        }
    };
    novemberMember.setPersonId("novemberPerson");

    CommitteeMembership decemberMember = new CommitteeMembership() {
        public boolean isActive(Date date) {
            if (date.equals(Date.valueOf("2011-12-25"))) {
                return true;
            } else {
                return false;
            }
        }
    };
    decemberMember.setPersonId("decemberPerson");

    CommitteeMembership novemberDecemberMember = new CommitteeMembership() {
        public boolean isActive(Date date) {
            if ((date.equals(Date.valueOf("2011-12-25"))) || (date.equals(Date.valueOf("2011-11-25")))) {
                return true;
            } else {
                return false;
            }
        }
    };
    novemberDecemberMember.setPersonId("novemberDecemberPerson");

    CommitteeMembership neitherNovemberNorDecemberMember = new CommitteeMembership() {
        public boolean isActive(Date date) {
            if (!(date.equals(Date.valueOf("2011-12-25"))) && !(date.equals(Date.valueOf("2011-11-25")))) {
                return true;
            } else {
                return false;
            }
        }
    };
    neitherNovemberNorDecemberMember.setPersonId("neitherNovemberNorDecemberPerson");

    // create the committee instance and add the memberships to it
    Committee committee = new Committee();
    committee.getCommitteeMemberships().add(novemberMember);
    committee.getCommitteeMemberships().add(decemberMember);
    committee.getCommitteeMemberships().add(novemberDecemberMember);
    committee.getCommitteeMemberships().add(neitherNovemberNorDecemberMember);

    // set the committee instance on the two schedules created earlier
    decemberSchedule.setCommittee(committee);
    novemberSchedule.setCommittee(committee);

    assertTrue(novemberSchedule.isActiveFor("novemberPerson"));
    assertTrue(decemberSchedule.isActiveFor("decemberPerson"));

    assertFalse(novemberSchedule.isActiveFor("decemberPerson"));
    assertFalse(decemberSchedule.isActiveFor("novemberPerson"));

    assertTrue(decemberSchedule.isActiveFor("novemberDecemberPerson"));
    assertTrue(novemberSchedule.isActiveFor("novemberDecemberPerson"));

    assertFalse(novemberSchedule.isActiveFor("neitherNovemberNorDecemberPerson"));
    assertFalse(decemberSchedule.isActiveFor("neitherNovemberNorDecemberPerson"));

    assertFalse(novemberSchedule.isActiveFor(null));
    decemberSchedule.setCommittee(null);
    assertFalse(decemberSchedule.isActiveFor("decemberPerson"));
    // restore committee
    decemberSchedule.setCommittee(committee);
    assertTrue(decemberSchedule.isActiveFor("decemberPerson"));

}

From source file:com.github.binarywang.demo.spring.controller.WebController.java

/**
 * 8:30 ~ 11:30/*from  www. j  a  v  a 2  s .c  o m*/
 * 2:00 ~ 4:00
 * 5 vehicles per hour
 * ???2
 * ?2
 * ?
 * @param session
 * @param file1
 * @param name
 * @param chepai
 * @param date
 * @param tel
 * @param file2
 * @return
 */
@RequestMapping("/uploader/yuyue")
@ResponseBody
public Map<String, Object> yuyue(HttpSession session,
        @RequestParam(name = "file1", required = false) MultipartFile file1,
        @RequestParam(name = "name", required = true) String name,
        @RequestParam(name = "chepai", required = true) String chepai,
        @RequestParam(name = "date", required = true) String date,
        @RequestParam(name = "tel", required = true) String tel,
        @RequestParam(name = "file2", required = false) MultipartFile file2,
        @RequestParam(name = "serverId", required = true) String serverId,
        @RequestParam(name = "time", required = true) int time) throws ParseException {
    Map<String, Object> ret = new HashMap<String, Object>();
    Date date1 = Date.valueOf(date);
    if (date1.before(Calendar.getInstance().getTime()) || date1.equals(Calendar.getInstance().getTime())) {
        ret.put("success", false);
        ret.put("reason", "????1-7");
        return ret;
    }
    if (wxService.getDayCounter().getCount(Calendar.getInstance().getTime(), date1) > 7) {
        ret.put("success", false);
        ret.put("reason", "?7");
        return ret;
    }
    if (wxService.getDayCounter().getCount(Calendar.getInstance().getTime(), date1) < 1) {
        ret.put("success", false);
        ret.put("reason", "???");
        return ret;
    }
    if (wxService.getDayCounter().isHoliday(date1)) {
        ret.put("success", false);
        ret.put("reason", "????");
        return ret;
    }
    WxMpUser wxMpUser = (WxMpUser) session.getAttribute("userOpenId");
    if (wxMpUser == null) {
        ret.put("success", false);
        ret.put("reason", "");
        return ret;
    }
    if (appointmentDao.findInOrderingAppointmentByOpenId(wxMpUser.getOpenId()).size() > 0) {
        ret.put("success", false);
        ret.put("reason", "??");
        return ret;
    }
    if (appointmentDao.isInBlackList(tel, wxMpUser.getOpenId())) {
        ret.put("success", false);
        ret.put("reason", "3????");
    }
    if (appointmentDao.findCountByOpenId(wxMpUser.getOpenId()) > 2) {
        ret.put("success", false);
        ret.put("reason", "???");
        return ret;
    }
    if (appointmentDao.findCountByTel(tel) > 2) {
        ret.put("success", false);
        ret.put("reason", "???");
        return ret;
    }

    if (appointmentDao.countForDay(date, time) >= 15 && time == 0) {
        ret.put("success", false);
        ret.put("reason", "??");
        return ret;
    }
    if (appointmentDao.countForDay(date, time) >= 10 && time == 1) {
        ret.put("success", false);
        ret.put("reason", "??");
        return ret;
    }

    Appointment appointment = new Appointment();
    appointment.setName(wxMpUser.getNickname());
    appointment.setOpenId(wxMpUser.getOpenId());
    appointment.setRealName(name);
    appointment.setChepai(chepai);
    appointment.setDate(date1);
    appointment.setDriverLicense("");
    appointment.setTel(tel);
    appointment.setServerId(serverId);
    appointment.setTime(time);
    appointmentDao.save(appointment);
    ret.put("success", true);
    return ret;
}

From source file:net.niyonkuru.koodroid.ui.DataDetailFragment.java

private XYMultipleSeriesDataset getBarDataset(Cursor cursor, int x, int maxX) {
    XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();

    XYSeries series = new XYSeries(null);

    Calendar cal = Calendar.getInstance();
    CalendarUtils.trimTimestamp(cal);//from www  .  j  ava2s.  co  m

    if (cursor.isClosed() || !cursor.moveToFirst())
        return null;

    while (x <= maxX) {
        double count = 0;

        if (!cursor.isAfterLast()) { /* cursor has data */
            Date rowDate = new Date(cal.getTimeInMillis());
            Date currDate = Date.valueOf(cursor.getString(UsagesQuery.DATE));

            if (rowDate.equals(currDate)) {
                count = cursor.getDouble(UsagesQuery.COUNT);
                cursor.moveToNext();
            }
        }
        cal.add(Calendar.DAY_OF_YEAR, -1);

        series.add(x++, count);
    }
    dataset.addSeries(series);

    return dataset;
}

From source file:edu.ku.kuali.kra.negotiations.service.NegotiationServiceImpl.java

private boolean isDateBetween(Date checkDate, Date rangeStart, Date rangeEnd) {
    if (rangeStart == null) {
        return false;
    }//from  w ww  . j av  a  2 s.  c om
    if (checkDate == null) {
        checkDate = new Date(Calendar.getInstance().getTimeInMillis());
    }
    if (rangeEnd == null) {
        rangeEnd = new Date(Calendar.getInstance().getTimeInMillis());
    }
    boolean startOk = rangeStart.equals(checkDate) || rangeStart.before(checkDate);
    boolean endOk = rangeEnd.equals(checkDate) || rangeEnd.after(checkDate);
    return startOk && endOk;
}

From source file:org.kuali.kra.award.paymentreports.closeout.AwardCloseoutServiceImpl.java

public void updateCloseoutDueDatesBeforeSave(Award award) {
    Map<String, Object> closeoutDueDates = new HashMap<String, Object>();
    Date finalExpirationDate = award.getAwardAmountInfos().get(award.getIndexOfLastAwardAmountInfo())
            .getFinalExpirationDate();//from w  w  w  .j  av a2 s. c o m
    java.util.Date dateCalculatedUsingFrequency;
    //java.util.Date dateCalculatedUsingFrequencyOld;
    boolean allDueDatesAreEqual;
    String closeoutReportTypeCode;

    //java.util.Date dateCalculatedUsingFinalInvoiceDue = getDateCalculatedUsingFinalInvoiceDue(award, finalExpirationDate).getTime();

    refreshAwardReportTerms(award.getAwardReportTermItems());

    for (KeyValue kl : (new CloseoutReportTypeValuesFinder()).getKeyValues()) {
        closeoutReportTypeCode = kl.getKey().toString();
        allDueDatesAreEqual = true;
        dateCalculatedUsingFrequency = null;
        //dateCalculatedUsingFrequencyOld = null;
        List<AwardReportTerm> awardReportTerms = filterAwardReportTerms(award.getAwardReportTermItems(),
                closeoutReportTypeCode);
        if (awardReportTerms.size() == 0) {
            closeoutDueDates.put(closeoutReportTypeCode, null);
        } else {
            Calendar calendar = getDateTimeService().getCalendar(finalExpirationDate);
            java.util.Date dueDate = null;
            for (AwardReportTerm awardReportTerm : awardReportTerms) {
                dateCalculatedUsingFrequency = getCloseoutDueDate(finalExpirationDate, awardReportTerm,
                        calendar);
                if (dueDate != null && !dueDate.equals(dateCalculatedUsingFrequency)) {
                    allDueDatesAreEqual = false;
                    break;
                }
                dueDate = dateCalculatedUsingFrequency;
            }
            if (dateCalculatedUsingFrequency != null) {
                updateCloseoutDueDate(closeoutDueDates, dateCalculatedUsingFrequency, allDueDatesAreEqual,
                        closeoutReportTypeCode);
            }
        }
    }

    assignedDueDatesOnAwardCloseouts(award.getAwardCloseoutItems(), closeoutDueDates);

}

From source file:org.kuali.kra.award.paymentreports.awardreports.reporting.service.ReportTrackingServiceImpl.java

private boolean dateCompare(Date formDate, Date dbDate) {
    boolean retVal = false;
    if (formDate == null && dbDate == null) {
        retVal = true;/*  w w  w  .j av  a  2s.  c  o  m*/
    } else {
        if (formDate != null && dbDate != null && formDate.equals(dbDate)) {
            retVal = true;
        }
    }
    return retVal;
}

From source file:org.kuali.kra.award.paymentreports.awardreports.reporting.ReportTracking.java

private boolean dateEquals(Date date1, Date date2) {
    boolean retVal = false;
    if (date1 == null && date2 == null) {
        retVal = true;/*  w w  w.  jav  a2  s .  co m*/
    } else if (date1 != null && date2 != null && date1.equals(date2)) {
        return true;
    }
    return retVal;
}

From source file:nl.strohalm.cyclos.setup.migrations.version3_6.ClosedAccountBalancesMigration.java

@Override
public int execute(final JDBCWrapper jdbc) throws SQLException {

    // First, ensure the account status still exists, ie, not already migrated
    ResultSet accountStatusExists = null;
    try {//from w ww . ja  v a  2  s .com
        accountStatusExists = jdbc.query("select 1 from account_status limit 1");
    } catch (final SQLException e) {
        // The already does not exists. Exit.
        return 0;
    } finally {
        JDBCWrapper.closeQuietly(accountStatusExists);
    }

    // Populate the account limit logs from both the account status and the pending account status tables
    jdbc.execute(
            "insert into account_limit_logs " + " (account_id, date, by_id, credit_limit, upper_credit_limit) "
                    + " select account_id, date, credit_limit_by_id, credit_limit, upper_credit_limit"
                    + " from account_status" + " where credit_limit_by_id is not null");

    jdbc.execute(
            "insert into account_limit_logs " + " (account_id, date, by_id, credit_limit, upper_credit_limit) "
                    + " select account_id, date, by_id, lower_limit, upper_limit"
                    + " from pending_account_status" + " where type = 'lim'");

    // Populate the amount_reservations table from pending transfers, scheduled payments which reserves the total amount and their installments
    jdbc.execute("insert into amount_reservations" + " (subclass, account_id, date, amount, transfer_id)"
            + " select 'P', from_account_id, date, amount, id " + " from transfers t " + " where t.status = ? ",
            Payment.Status.PENDING.getValue());
    jdbc.execute(
            "insert into amount_reservations" + " (subclass, account_id, date, amount, scheduled_payment_id)"
                    + " select 'S', from_account_id, date, amount, id " + " from scheduled_payments "
                    + " where reserve_amount = true ");
    jdbc.execute(
            "insert into amount_reservations" + " (subclass, account_id, date, amount, transfer_id)"
                    + " select 'I', t.from_account_id, ifnull(t.process_date, t.date), -t.amount, t.id "
                    + " from transfers t inner join scheduled_payments sp on t.scheduled_payment_id = sp.id"
                    + " where sp.reserve_amount = true and t.status <> ? ",
            Payment.Status.SCHEDULED.getValue());

    // Iterate each account
    int results = 0;
    final ResultSet accounts = jdbc.query("select id, creation_date from accounts");
    try {
        while (accounts.next()) {
            final long accountId = accounts.getLong("id");
            final Date creationDate = new Date(DateUtils
                    .truncate(accounts.getTimestamp("creation_date"), Calendar.DAY_OF_MONTH).getTime());
            // Get, by day, each diff, either for balance or reserved amount
            ResultSet diffs = jdbc.query(" select * from ( "
                    + "     select 'B' as type, b.date, b.balance as diff" + "     from ( "
                    + "         select date(date) as date, sum(amount) as balance " + "         from ( "
                    + "             select t.process_date as date, "
                    + "             case when t.chargeback_of_id is null then "
                    + "                 case when t.from_account_id = ? then -t.amount else t.amount end "
                    + "             else "
                    + "                 case when t.to_account_id = ? then t.amount else -t.amount end "
                    + "             end as amount " + "             from transfers t "
                    + "             where (t.from_account_id = ? or t.to_account_id = ?) "
                    + "               and t.process_date is not null " + "         ) t "
                    + "         group by date(date) " + "     ) b " + "     union "
                    + "     select 'R', date(r.date), sum(r.amount) " + "     from amount_reservations r "
                    + "     where r.account_id = ? " + "     group by date(r.date) " + " ) t "
                    + " where date < current_date() " + " order by date", accountId, accountId, accountId,
                    accountId, accountId);
            Date lastDate = creationDate;
            double balance = 0;
            double reserved = 0;
            try {
                boolean hasData = false;
                while (diffs.next()) {
                    hasData = true;
                    boolean isBalance = "B".equals(diffs.getString("type"));
                    Date date = diffs.getDate("date");
                    double diff = diffs.getDouble("diff");
                    if (!lastDate.equals(date)) {
                        // Insert a closed balance when the date changes
                        results += jdbc.execute(
                                "insert into closed_account_balances (date, account_id, balance, reserved) values (?, ?, ?, ?)",
                                nextDay(lastDate), accountId, balance, reserved);
                    }
                    if (isBalance) {
                        balance += diff;
                    } else {
                        reserved += diff;
                    }
                    lastDate = date;
                }
                if (hasData) {
                    // There is a last closed balance to insert
                    results += jdbc.execute(
                            "insert into closed_account_balances (date, account_id, balance, reserved) values (?, ?, ?, ?)",
                            nextDay(lastDate), accountId, balance, reserved);
                }
            } finally {
                JDBCWrapper.closeQuietly(diffs);
            }
            // Set the last closing date
            jdbc.execute("update accounts set last_closing_date = ? where id = ?", lastDate, accountId);
        }
    } finally {
        JDBCWrapper.closeQuietly(accounts);
    }

    // Now it is safe to drop the account_status table
    jdbc.execute("drop table account_status");
    jdbc.execute("drop table pending_account_status");

    return results;
}