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.candlepin.policy.js.pool.PoolRules.java

private boolean checkForDateChange(Date start, Date end, Pool existingPool) {

    boolean datesChanged = (!start.equals(existingPool.getStartDate()))
            || (!end.equals(existingPool.getEndDate()));

    if (datesChanged) {
        existingPool.setStartDate(start);
        existingPool.setEndDate(end);/*from  w w w .ja va 2 s .  co  m*/
    }
    return datesChanged;
}

From source file:dk.dma.vessel.track.model.VesselTarget.java

/**
 * Update the static information fields from the AIS message
 * @param message the AIS message//ww w  .j  a v a  2s .c o  m
 * @param date the date of the message
 * @return if any fields were updated
 */
private boolean updateVesselStaticMessage(AisStaticCommon message, Date date) {

    // Check that this is a newer static update
    if (lastStaticReport != null && lastStaticReport.getTime() >= date.getTime()) {
        return false;
    }

    boolean updated = false;

    // Update the name
    String name = AisMessage.trimText(message.getName());
    if (StringUtils.isNotBlank(name) && !name.equals(this.name)) {
        this.name = name;
        updated = true;
    }

    // Update the call-sign
    String callsign = AisMessage.trimText(message.getCallsign());
    if (StringUtils.isNotBlank(callsign) && !callsign.equals(this.callsign)) {
        this.callsign = callsign;
        updated = true;
    }

    // Update the vessel type
    Integer vesselType = message.getShipType();
    if (!vesselType.equals(this.vesselType)) {
        this.vesselType = vesselType;
        updated = true;
    }

    if (message instanceof AisMessage5) {
        AisMessage5 msg5 = (AisMessage5) message;
        AisTargetDimensions dim = new AisTargetDimensions(msg5);

        // Update length
        Short length = (short) (dim.getDimBow() + dim.getDimStern());
        if (!length.equals(this.length)) {
            this.length = length;
            updated = true;
        }

        // Update width
        Short width = (short) (dim.getDimPort() + dim.getDimStarboard());
        if (!width.equals(this.width)) {
            this.width = width;
            updated = true;
        }

        // Update destination
        String destination = StringUtils.defaultIfBlank(AisMessage.trimText(msg5.getDest()), null);
        if (destination != null && !destination.equals(this.destination)) {
            this.destination = destination;
            updated = true;
        }

        // Update draught
        Float draught = msg5.getDraught() / 10.0f;
        if (msg5.getDraught() > 0 && !compare(draught, this.draught)) {
            this.draught = draught;
            updated = true;
        }

        // Update ETA
        Date eta = msg5.getEtaDate();
        if (eta != null && !eta.equals(this.eta)) {
            this.eta = eta;
            updated = true;
        }

        // Update IMO
        Long imo = msg5.getImo();
        if (msg5.getImo() > 0 && !imo.equals(this.imoNo)) {
            this.imoNo = imo;
            updated = true;
        }
    }

    // Only update lastStaticReport if any static field has been updated
    if (updated) {
        lastStaticReport = date;
    }

    return updated;
}

From source file:org.egov.ptis.client.util.PropertyTaxUtil.java

/**
 * Returns true if the date is later than dateToCompare OR date is same as dateToCompare
 *
 * @param date//from  www.  ja  va 2s. c o  m
 * @param dateToCompare
 * @return true if date is after dateToCompare or date is equal to dateToCompare
 */
public static boolean afterOrEqual(final Date date, final Date dateToCompare) {
    return date.after(dateToCompare) || date.equals(dateToCompare);
}

From source file:com.virtusa.akura.student.controller.StudentDisciplineController.java

/**
 * Manage Student Discipline details.//  w w w  .j a  v  a  2s  . c om
 * 
 * @param studentDiscipline - {@link StudentDiscipline}.
 * @param request - HttpServletRequest
 * @param model {@link ModelMap}
 * @param session {@link HttpSession}
 * @param bindingResult {@link BindingResult}
 * @return name of the view which is redirected to.
 * @throws AkuraAppException - throw this
 */
@RequestMapping(value = REQ_MAP_VALUE_SAVEORUPDATE, method = RequestMethod.POST)
public String saveOrUpdateStudentDiscipline(
        @ModelAttribute(MODEL_ATT_STUDENT_DISCIPLINE) StudentDiscipline studentDiscipline,
        BindingResult bindingResult, HttpServletRequest request, ModelMap model, HttpSession session)
        throws AkuraAppException {

    String strMessage = null;
    String result = VIEW_POST_MANAGE_STUDENT_DISCIPLINE;
    studentDisciplineValidator.validate(studentDiscipline, bindingResult);

    if (bindingResult.hasErrors()) {
        setAverageRatingValue(model, session);
        model.addAttribute(DISPLAY_PANEL, true);
        result = VIEW_GET_STUDENT_DISCIPLINE;

    } else {
        // check if StudentDiscipline exist or not
        if (studentDiscipline.getStudentDisciplineId() == 0
                && isExistsStudentDiscipline((Integer) session.getAttribute(STUDENT_ID), studentDiscipline)) {

            strMessage = new ErrorMsgLoader().getErrorMessage(AkuraWebConstant.STUDENT_DESCIPLINE_EXIST);
            model.addAttribute(MODEL_ATT_MESSAGE, strMessage);
            model.addAttribute(DISPLAY_PANEL, true);
            result = VIEW_GET_STUDENT_DISCIPLINE;
        } else if (session.getAttribute(STUDENT_ID) != null) {
            int studentId = Integer.parseInt(session.getAttribute(STUDENT_ID).toString());

            if (session.getAttribute(SESSION_USER_LOGIN) != null) {

                if (studentDiscipline != null) {

                    UserLogin userLogin = (UserLogin) session.getAttribute(SESSION_USER_LOGIN);

                    studentDiscipline.setStudentId(studentId);

                    // check if this student is on leave on the date of disciplinary action.
                    if ((studentService.checkStudentIsOnLeave(studentId, studentDiscipline.getDate())
                            || DateUtil.isHoliday(
                                    getHolidayList(DateUtil.getStringYear(studentDiscipline.getDate())),
                                    studentDiscipline.getDate()))
                            && (studentService.getStudentStatusId(studentId) != 1)) {

                        strMessage = new ErrorMsgLoader()
                                .getErrorMessage(STUDENT_LEAVE_DATE_DISCIPLINARY_ERROR);
                        model.addAttribute(MODEL_ATT_MESSAGE, strMessage);
                        model.addAttribute(DISPLAY_PANEL, true);
                        result = VIEW_GET_STUDENT_DISCIPLINE;

                    } else {

                        // if the start date of the student is less than the disciplinary date,
                        // save or edit.
                        Date startedDate = studentService.getStudentStartedDate(studentId);

                        if (startedDate != null && studentDiscipline.getDate().after(startedDate)
                                || (startedDate != null && startedDate.equals(studentDiscipline.getDate()))) {
                            if (studentDiscipline.getStudentDisciplineId() == 0) {
                                // add new record
                                studentDiscipline.setUserLoginId(userLogin.getUserLoginId());
                                studentService.addStudentDisciplineInfo(studentDiscipline);
                            } else {
                                // edit record, UserLoginId must Not change( because admin can change any
                                // record)
                                if (studentDiscipline.getUserLoginId() == userLogin.getUserLoginId()
                                        || userLogin.getUserRoleId() == 1) {
                                    studentService.editStudentDisciplineInfo(studentDiscipline);
                                }
                            }
                        } else {
                            if (startedDate != null) {
                                strMessage = new ErrorMsgLoader().getErrorMessage(STUDENT_FIRST_DATE_ERROR);
                                model.addAttribute(MODEL_ATT_MESSAGE, strMessage);
                                model.addAttribute(DISPLAY_PANEL, true);
                                result = VIEW_GET_STUDENT_DISCIPLINE;
                            }
                        }

                    }
                }

            }
        }
    }
    return result;
}

From source file:jp.co.ctc_g.jfw.core.util.Dates.java

/**
 * 2?1???????????./* www.j  a  v  a2s  .  c om*/
 * @param fromDate1 
 * @param toDate1 
 * @param fromDate2 2
 * @param toDate2 2
 * @return true:?????false:??????
 */
public static boolean isDateInclude(Date fromDate1, Date toDate1, Date fromDate2, Date toDate2) {

    fromDate1 = truncate(fromDate1, Dates.DAY);
    toDate1 = truncate(toDate1, Dates.DAY);
    fromDate2 = truncate(fromDate2, Dates.DAY);
    toDate2 = truncate(toDate2, Dates.DAY);
    if ((fromDate1.before(fromDate2) || fromDate1.equals(fromDate2)) && // 11??2???
            (toDate1.after(fromDate2) || toDate1.equals(fromDate2))
            && (fromDate1.before(toDate2) || fromDate1.equals(toDate2)) && // ???11??2???
            (toDate1.after(toDate2) || toDate1.equals(toDate2)))
        return true;
    return false;
}

From source file:com.qcadoo.mes.orders.hooks.OrderHooks.java

public boolean setDateChanged(final DataDefinition dataDefinition, final FieldDefinition fieldDefinition,
        final Entity order, final Object fieldOldValue, final Object fieldNewValue) {
    OrderState orderState = OrderState.of(order);
    if (fieldOldValue != null && fieldNewValue != null && !orderState.equals(OrderState.PENDING)) {

        Date oldDate = DateUtils.parseDate(fieldOldValue);
        Date newDate = DateUtils.parseDate(fieldNewValue);
        if (!oldDate.equals(newDate)) {
            order.setField(OrderFields.DATES_CHANGED, true);
            order.setField(getSourceFieldName(fieldDefinition), fieldOldValue);
        }//from  ww w .  j  a v a 2 s  .c  o m
    }

    return true;
}

From source file:org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_9.VisitController1_9Test.java

@Test
public void shouldEditAVisit() throws Exception {
    final String newVisitTypeUuid = RestTestConstants1_9.VISIT_TYPE_UUID;
    final String newLocationUuid = "9356400c-a5a2-4532-8f2b-2361b3446eb8";
    final String newIndicationConceptUuid = "c607c80f-1ea9-4da3-bb88-6276ce8868dd";
    final Date newStartDatetime = new Date();
    final Date newStopDatetime = new Date();
    Visit visit = service.getVisitByUuid(RestTestConstants1_9.VISIT_UUID);
    Assert.assertNotNull(visit);/*from   w  w  w  .j a  va2s  . c  o  m*/
    //sanity checks
    Assert.assertFalse(newVisitTypeUuid.equalsIgnoreCase(visit.getVisitType().getUuid()));
    Assert.assertFalse(newLocationUuid.equalsIgnoreCase(visit.getLocation().getUuid()));
    Assert.assertFalse(newIndicationConceptUuid.equalsIgnoreCase(visit.getIndication().getUuid()));
    Assert.assertFalse(newStartDatetime.equals(visit.getStartDatetime()));
    Assert.assertFalse(newStopDatetime.equals(visit.getStopDatetime()));

    String json = "{ \"visitType\":\"" + newVisitTypeUuid + "\", \"location\":\"" + newLocationUuid
            + "\", \"indication\":\"" + newIndicationConceptUuid + "\", \"startDatetime\":\""
            + DATE_FORMAT.format(newStartDatetime) + "\", \"stopDatetime\":\""
            + DATE_FORMAT.format(newStopDatetime) + "\" }";

    handle(newPostRequest(getURI() + "/" + getUuid(), json));

    Visit updated = service.getVisitByUuid(RestTestConstants1_9.VISIT_UUID);
    Assert.assertNotNull(updated);
    Assert.assertEquals(newVisitTypeUuid, updated.getVisitType().getUuid());
    Assert.assertEquals(newLocationUuid, updated.getLocation().getUuid());
    Assert.assertEquals(newIndicationConceptUuid, updated.getIndication().getUuid());
    Assert.assertEquals(newStartDatetime, updated.getStartDatetime());
    Assert.assertEquals(newStopDatetime, updated.getStopDatetime());
}

From source file:controller.ClientController.java

@RequestMapping("/annuler")
public String annulercontratAction(HttpServletRequest request, HttpSession session) throws ParseException {
    //ClientConnecte cli = new ClientConnecte((Client) session.getAttribute("UserConnected"));
    //session.removeAttribute("UserConnected");

    SimpleDateFormat sdf = new SimpleDateFormat("yy-MM-dd");
    int idvideo = Integer.parseInt(request.getParameter("idvideo"));

    Video vid = vidBDD.VideoPrec(idvideo).get(0);

    //System.out.println(""+datedebut);
    //System.out.println("Con De type Date:"+ddebut);
    Date currentDate = new Date();
    String datecourante = sdf.format(currentDate);
    Date dcourante = sdf.parse(datecourante);
    //System.out.println(""+datecourante);
    //System.out.println("Cu De type Date:"+dcourante);

    //Raccourci la date de validation du contrat  la date courante
    if (dcourante.after(vid.getDateDebut()) || dcourante.equals(vid.getDateDebut())) {
        //System.out.println("Date courant sup ou egale  celle du cntrat");
        vid.setDateFin(dcourante);//from   w w  w.jav  a2s.com
        this.vidBDD.updComContrat(vid, "annuler");
    } else {
        //supprime le contrat si il n'est pas commenc
        //System.out.println("Date courant inf  celle du cntrat");
        vidBDD.deleteComContrat(idvideo);
    }

    return "redirect:/client";
}

From source file:org.openmrs.module.webservices.rest19ext.web.v1_0.controller.VisitControllerTest.java

@Test
public void shouldEditAVisit() throws Exception {
    final String newVisitTypeUuid = Rest19ExtTestConstants.VISIT_TYPE_UUID;
    final String newLocationUuid = "9356400c-a5a2-4532-8f2b-2361b3446eb8";
    final String newIndicationConceptUuid = "c607c80f-1ea9-4da3-bb88-6276ce8868dd";
    final Date newStartDatetime = new Date();
    final Date newStopDatetime = new Date();
    Visit visit = service.getVisitByUuid(Rest19ExtTestConstants.VISIT_UUID);
    Assert.assertNotNull(visit);/*from   w ww.  ja  v a2  s.c  om*/
    //sanity checks
    Assert.assertFalse(newVisitTypeUuid.equalsIgnoreCase(visit.getVisitType().getUuid()));
    Assert.assertFalse(newLocationUuid.equalsIgnoreCase(visit.getLocation().getUuid()));
    Assert.assertFalse(newIndicationConceptUuid.equalsIgnoreCase(visit.getIndication().getUuid()));
    Assert.assertFalse(newStartDatetime.equals(visit.getStartDatetime()));
    Assert.assertFalse(newStopDatetime.equals(visit.getStopDatetime()));

    String json = "{ \"visitType\":\"" + newVisitTypeUuid + "\", \"location\":\"" + newLocationUuid
            + "\", \"indication\":\"" + newIndicationConceptUuid + "\", \"startDatetime\":\""
            + DATE_FORMAT.format(newStartDatetime) + "\", \"stopDatetime\":\""
            + DATE_FORMAT.format(newStopDatetime) + "\" }";

    SimpleObject post = new ObjectMapper().readValue(json, SimpleObject.class);
    controller.update(Rest19ExtTestConstants.VISIT_UUID, post, request, response);

    Visit updated = service.getVisitByUuid(Rest19ExtTestConstants.VISIT_UUID);
    Assert.assertNotNull(updated);
    Assert.assertEquals(newVisitTypeUuid, updated.getVisitType().getUuid());
    Assert.assertEquals(newLocationUuid, updated.getLocation().getUuid());
    Assert.assertEquals(newIndicationConceptUuid, updated.getIndication().getUuid());
    Assert.assertEquals(newStartDatetime, updated.getStartDatetime());
    Assert.assertEquals(newStopDatetime, updated.getStopDatetime());
}

From source file:org.openadaptor.auxil.expression.BinaryOp.java

protected Object dateOp(Date d1, Date d2) throws ExpressionException {
    Object result;/*from   w w w  .  j  a v  a  2s. c o m*/
    switch (op) {

    case ExpressionToken.OP_PLUS:
        result = new Long(d1.getTime() + d2.getTime());
        break;
    case ExpressionToken.OP_MINUS:
        result = new Long(d1.getTime() - d2.getTime());
        break;

    case ExpressionToken.OP_EQ:
        result = new Boolean(d1.equals(d2));
        break;
    case ExpressionToken.OP_NE:
        result = new Boolean(!(d1.equals(d2)));
        break;

    case ExpressionToken.OP_GT:
        result = new Boolean(d1.compareTo(d2) > 0);
        break;

    case ExpressionToken.OP_LT:
        result = new Boolean(d1.compareTo(d2) < 0);
        break;

    case ExpressionToken.OP_LE:
        result = new Boolean(d1.compareTo(d2) <= 0);
        break;

    case ExpressionToken.OP_GE:
        result = new Boolean(d1.compareTo(d2) >= 0);
        break;
    default:
        throw new ExpressionException("Attempted unrecognised expression operation: " + op);
        // break;
    }
    return result;
}