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.broadleafcommerce.core.order.domain.OrderImpl.java

@Override
public boolean equals(Object obj) {
    if (this == obj) {
        return true;
    }// www.j av  a  2s.  c o m
    if (obj == null) {
        return false;
    }
    if (!getClass().isAssignableFrom(obj.getClass())) {
        return false;
    }
    OrderImpl other = (OrderImpl) obj;

    if (id != null && other.id != null) {
        return id.equals(other.id);
    }

    if (customer == null) {
        if (other.customer != null) {
            return false;
        }
    } else if (!customer.equals(other.customer)) {
        return false;
    }
    Date myDateCreated = auditable != null ? auditable.getDateCreated() : null;
    Date otherDateCreated = other.auditable != null ? other.auditable.getDateCreated() : null;
    if (myDateCreated == null) {
        if (otherDateCreated != null) {
            return false;
        }
    } else if (!myDateCreated.equals(otherDateCreated)) {
        return false;
    }
    return true;
}

From source file:org.openmrs.api.impl.ProgramWorkflowServiceImpl.java

/**
 * @deprecated use{@link #unretireProgram(Program program)} 
 * @see org.openmrs.api.ProgramWorkflowService#retireProgram(org.openmrs.Program)
 *//*from   w  w w .j a  v  a2s  .c  om*/
@Deprecated
public Program unRetireProgram(Program program) throws APIException {
    Date lastModifiedDate = program.getDateChanged();
    program.setRetired(false);
    for (ProgramWorkflow workflow : program.getAllWorkflows()) {
        if (lastModifiedDate != null && lastModifiedDate.equals(workflow.getDateChanged())) {
            workflow.setRetired(false);
            for (ProgramWorkflowState state : workflow.getStates()) {
                if (lastModifiedDate.equals(state.getDateChanged())) {
                    state.setRetired(false);
                }
            }
        }
    }
    return Context.getProgramWorkflowService().saveProgram(program);
}

From source file:at.jclehner.rxdroid.DrugListActivity.java

@SuppressWarnings("deprecation")
private void showDoseDialog(Drug drug, Date date, int doseTime, boolean forceShow) {
    if (toastIfPastMaxHistoryAge(date))
        return;/*from w  w  w . j ava2 s.  c om*/
    else if (!date.equals(mCurrentDate)) {
        Log.i(TAG, "DoseView date " + DateTime.toDateString(date) + " differs from Activity date "
                + DateTime.toDateString(mCurrentDate) + " ");

        invalidateViewPager();
        date = mCurrentDate;

        if (BuildConfig.DEBUG)
            Toast.makeText(this, "Invoked workaround!", Toast.LENGTH_SHORT).show();
    }

    final Bundle args = new Bundle();
    args.putInt(DoseDialog.ARG_DRUG_ID, drug.getId());
    args.putInt(DoseDialog.ARG_DOSE_TIME, doseTime);
    args.putSerializable(DoseDialog.ARG_DATE, date);
    args.putBoolean(DoseDialog.ARG_FORCE_SHOW, forceShow);

    showDialog(R.id.dose_dialog, args);
}

From source file:myorg.relex.One2OneTest.java

/**
 * This test demonstrates use of cascades in a one-to-one 
 * bi-directional relationship where all cascades come
 * from the inverse/parent side of the relationship.
 *//*  w w  w. j a v  a 2  s.c  o m*/
@Test
public void testOne2OneCascadeFromInverse() {
    log.info("*** testOne2OneCascadeFromInverse ***");
    Ticket ticket = new Ticket();
    ticket.setDate(new GregorianCalendar(2013, Calendar.MARCH, 16).getTime());
    Passenger passenger = new Passenger(ticket, "Fred"); //set inverse side
    ticket.setPassenger(passenger); //set the owning side
    em.persist(ticket); //persist from inverse side
    em.flush();
    assertTrue("ticket not managed", em.contains(ticket));
    assertTrue("passenger not managed", em.contains(passenger));

    log.debug("detach both instances from the persistence context");
    em.detach(ticket);
    assertFalse("ticket managed", em.contains(ticket));
    assertFalse("passenger managed", em.contains(passenger));

    log.debug("perform a bulk update to both objects");
    ticket = em.find(Ticket.class, ticket.getId());
    Date newDate = new GregorianCalendar(2013, Calendar.APRIL, 1).getTime();
    String newName = "Frederick";
    em.createQuery("update Ticket t set t.date=:date").setParameter("date", newDate, TemporalType.DATE)
            .executeUpdate();
    em.createQuery("update Passenger p set p.name=:name where p.name='Fred'").setParameter("name", newName)
            .executeUpdate();
    assertFalse("unexpected date", newDate.equals(ticket.getDate()));
    assertFalse("unexpected name", newName.equals(ticket.getPassenger().getName()));
    em.refresh(ticket);
    assertTrue("date not refreshed", newDate.equals(ticket.getDate()));
    assertTrue("name not refreshed", newName.equals(ticket.getPassenger().getName()));

    log.debug("merging changes from inverse side");
    Ticket ticket2 = new Ticket(ticket.getId());
    ticket2.setDate(new GregorianCalendar(2014, Calendar.APRIL, 1).getTime());
    Passenger passenger2 = new Passenger(passenger.getId());
    passenger2.setName("Rick");
    ticket2.setPassenger(passenger2);
    passenger2.setTicket(ticket2);
    assertFalse("unexpected date", ticket2.getDate().equals(ticket.getDate()));
    assertFalse("unexpected name", ticket2.getPassenger().getName().equals(ticket.getPassenger().getName()));
    ticket = em.merge(ticket2);
    em.flush();
    assertTrue("date not merged", ticket2.getDate().equals(ticket.getDate()));
    assertTrue("name not merged", ticket2.getPassenger().getName().equals(ticket.getPassenger().getName()));

    log.debug("delete the entities from the inverse side");
    assertNotNull("ticket not found", em.find(Ticket.class, ticket.getId()));
    assertNotNull("passenger not found", em.find(Passenger.class, ticket.getPassenger().getId()));
    em.remove(ticket);
    em.flush();
    assertNull("ticket not removed", em.find(Ticket.class, ticket.getId()));
    assertNull("passenger not removed", em.find(Passenger.class, ticket.getPassenger().getId()));
}

From source file:Forms.frm_Penghuni.java

public boolean validasitanggal() {

    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    Date sekarang = new Date();
    String sekarang1 = dateFormat.format(sekarang);
    //        Date tanggal_sekarang = dateFormat.format(sekarang);
    String tgl_lahir = dateFormat.format(dcTanggalLahirPenghuni.getDate());
    //        Date tgl_lahir = dcTanggalLahirPenghuni.getDate();

    Date sek;/*from www  . j a v  a2  s  . c  o  m*/
    try {
        sek = dateFormat.parse(sekarang1);
        Date lahir = dateFormat.parse(tgl_lahir);

        if (lahir.equals(sek)) {
            JOptionPane.showMessageDialog(null,
                    "Tanggal Lahir Sama dengan Hari Ini.. \n Silahkan Isi Dengan Benar!");
            dcTanggalLahirPenghuni.requestFocus();
            return false;
        } else if (lahir.after(sek)) {
            JOptionPane.showMessageDialog(null,
                    "Apakah Penghuni berasal dari masa depan?.. \n Silahkan Isi Dengan Benar!");
            dcTanggalLahirPenghuni.requestFocus();
            return false;
        } else {
            return true;
        }
    } catch (ParseException ex) {
        Logger.getLogger(frm_Penghuni.class.getName()).log(Level.SEVERE, null, ex);
    }

    return false;

}

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

private void setStartDate(final Entity order) {
    Long orderId = order.getId();

    if (orderId == null) {
        return;/*from w ww  . j a v  a 2s  . c om*/
    }

    Date startDate = order.getDateField(OrderFields.START_DATE);
    if (startDate == null) {
        return;
    }

    Entity orderFromDB = orderService.getOrder(orderId);

    String state = order.getStringField(OrderFields.STATE);

    Date startDateDB = new Date();
    if (orderFromDB.getDateField(OrderFields.START_DATE) != null) {
        startDateDB = orderFromDB.getDateField(OrderFields.START_DATE);
    }
    if (OrderState.PENDING.getStringValue().equals(state) && !startDate.equals(startDateDB)) {
        order.setField(OrderFields.DATE_FROM, startDate);
    }
    if ((OrderState.IN_PROGRESS.getStringValue().equals(state)
            || OrderState.COMPLETED.getStringValue().equals(state)
            || OrderState.ABANDONED.getStringValue().equals(state)) && !startDate.equals(startDateDB)) {
        order.setField(OrderFields.EFFECTIVE_DATE_FROM, startDate);
    }
    if (OrderState.ACCEPTED.getStringValue().equals(state) && !startDateDB.equals(startDate)) {
        order.setField(OrderFields.CORRECTED_DATE_FROM, startDate);
    }
}

From source file:com.tservice.Logica.PersistenceFacede.java

private boolean licenciaVigente(Publicante pu) {

    boolean vigente = false;
    List<Factura> facturas = new LinkedList<>();

    for (Factura fac : pu.getFacturas()) {
        facturas.add(fac);/*  w  w w .  ja  va  2 s .c  o  m*/

        Factura facturaActual = getFacturaActual(facturas);

        //Si tiene factura actual
        if (facturaActual != null) {

            Date fechaActual = facturaActual.getFecha();
            int vigenciaDias = facturaActual.getLicencias().getVigenciaDias();
            Date fechaVencimiento;

            System.out.println("Dias vigencia " + vigenciaDias);
            //Sumar dias a fecha
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(fechaActual);
            calendar.add(Calendar.DAY_OF_YEAR, vigenciaDias);
            fechaVencimiento = calendar.getTime();

            System.out.println("Fecha " + vigenciaDias);

            //Si la fecha de vencimiento es menor o igual a la fecha actual
            vigente = fechaVencimiento.after(new Date()) || fechaVencimiento.equals(new Date());

        }
    }
    return vigente;
}

From source file:net.sourceforge.subsonic.service.MediaScannerService.java

private void updateAlbum(MediaFile file, Date lastScanned, Map<String, Integer> albumCount) {
    if (file.getAlbumName() == null || file.getArtist() == null || file.getParentPath() == null
            || !file.isAudio()) {/* w  w w. ja  v a 2s  .  c  om*/
        return;
    }

    Album album = albumDao.getAlbumForFile(file);
    if (album == null) {
        album = new Album();
        album.setPath(file.getParentPath());
        album.setName(file.getAlbumName());
        album.setArtist(file.getArtist());
        album.setCreated(file.getChanged());
    }
    if (album.getCoverArtPath() == null) {
        MediaFile parent = mediaFileService.getParentOf(file);
        if (parent != null) {
            album.setCoverArtPath(parent.getCoverArtPath());
        }
    }
    boolean firstEncounter = !lastScanned.equals(album.getLastScanned());
    if (firstEncounter) {
        album.setDurationSeconds(0);
        album.setSongCount(0);
        Integer n = albumCount.get(file.getArtist());
        albumCount.put(file.getArtist(), n == null ? 1 : n + 1);
    }
    if (file.getDurationSeconds() != null) {
        album.setDurationSeconds(album.getDurationSeconds() + file.getDurationSeconds());
    }
    if (file.isAudio()) {
        album.setSongCount(album.getSongCount() + 1);
    }

    album.setLastScanned(lastScanned);
    album.setPresent(true);
    albumDao.createOrUpdateAlbum(album);
    if (firstEncounter) {
        searchService.index(album);
    }

    // Update the file's album artist, if necessary.
    if (!ObjectUtils.equals(album.getArtist(), file.getAlbumArtist())) {
        file.setAlbumArtist(album.getArtist());
        mediaFileDao.createOrUpdateMediaFile(file);
    }
}

From source file:org.castor.cpa.test.test10.TestTypeHandling.java

public void testDateParameterized() throws PersistenceException, ParseException {
    LOG.debug("Testing date->int/numeric/char parameterized conversion");
    SimpleDateFormat df = new SimpleDateFormat();
    df.applyPattern("yyyy/MM/dd");
    Date date = df.parse("2000/05/27");
    df.applyPattern("yyyy/MM/dd HH:mm:ss.SSS");
    Date time = df.parse("2000/05/27 02:16:01.234");
    df.applyPattern("yyyy/MM/dd HH:mm:ss.SSS");
    Date timestamp = df.parse("2000/05/27 02:16:01.234");
    _db.begin();//from  w  ww  .j  a  v a  2s .  c  om
    _oql.bind(TypeHandling.DEFAULT_ID);
    Enumeration<?> enumeration = _oql.execute();
    if (enumeration.hasMoreElements()) {
        TypeHandling types = (TypeHandling) enumeration.nextElement();
        types.setDate2(date);
        types.setTime2(time);
        types.setTimestamp2(timestamp);
    }
    _db.commit();

    _db.begin();
    _oql.bind(TypeHandling.DEFAULT_ID);
    enumeration = _oql.execute();
    if (enumeration.hasMoreElements()) {
        TypeHandling types = (TypeHandling) enumeration.nextElement();
        if (!date.equals(types.getDate2())) {
            LOG.error("date/int value was not set");
            fail("date/int value was not set");
        }
        if (!time.equals(types.getTime2())) {
            LOG.error("time/string value was not set");
            fail("time/string vlaue was not set");
        }
        if (!timestamp.equals(types.getTimestamp2())) {
            LOG.error("timestamp/numeric value was not set");
            LOG.error("timestamp was set to: " + df.format(timestamp));
            LOG.error("with oid: " + timestamp.hashCode());
            LOG.error("timestamp is: " + df.format(types.getTimestamp2()));
            LOG.error("with oid: " + types.getTimestamp2().hashCode());
            fail("timestamp/numeric value was not set");
        }
    } else {
        LOG.error("failed to load object");
        fail("failed to load object");
    }
    _db.commit();
    LOG.debug("OK: date->int/numeric/char conversion passed");
}

From source file:com.clustercontrol.composite.FacilityTreeComposite.java

/**
 * ????// ww  w  .  j av  a2s.c om
 */
@Override
public void update() {
    // ?????????
    if (this.ownerRoleId != null) {
        try {
            if (this.selectNodeOnly) {
                // ???
                m_log.debug("getNodeFacilityTree " + managerName);
                treeItem = addEmptyParent(RepositoryEndpointWrapper.getWrapper(managerName)
                        .getNodeFacilityTree(this.ownerRoleId));
                if (treeItem != null && treeItem.getChildren() != null
                        && treeItem.getChildren().get(0) != null) {
                    Collections.sort(treeItem.getChildren().get(0).getChildren(),
                            new Comparator<FacilityTreeItem>() {
                                @Override
                                public int compare(FacilityTreeItem o1, FacilityTreeItem o2) {
                                    FacilityInfo info1 = ((FacilityTreeItem) o1).getData();
                                    FacilityInfo info2 = ((FacilityTreeItem) o2).getData();
                                    int order1 = info1.getDisplaySortOrder();
                                    int order2 = info2.getDisplaySortOrder();
                                    if (order1 == order2) {
                                        String object1 = info1.getFacilityId();
                                        String object2 = info2.getFacilityId();
                                        return object1.compareTo(object2);
                                    } else {
                                        return (order1 - order2);
                                    }
                                }
                            });
                }
            } else {
                m_log.debug("getFacilityTree " + managerName);
                treeItem = addEmptyParent(
                        RepositoryEndpointWrapper.getWrapper(managerName).getFacilityTree(this.ownerRoleId));
            }
        } catch (Exception e) {
            m_log.warn("getTreeItem(), " + e.getMessage(), e);
            return;
        }
    } else {
        treeItem = FacilityTreeCache.getTreeItem(managerName);
    }

    Date cacheDate = null;
    if (managerName != null) {
        cacheDate = FacilityTreeCache.getCacheDate(managerName);
    }
    if (cacheDate != null && cacheDate.equals(this.cacheDate)) {
        return;
    }
    this.cacheDate = cacheDate;

    if (null == treeItem) {
        m_log.trace("treeItem is null. Skip.");
    } else {
        FacilityTreeItem scope = (treeItem.getChildren()).get(0);
        scope.getData().setFacilityName(HinemosMessage.replace(scope.getData().getFacilityName()));

        m_log.debug("internal=" + internal + ", unregistered=" + unregistered);

        //????
        if (!internal) {
            if (managerName == null) {
                for (FacilityTreeItem managerScope : scope.getChildren()) {
                    if (!FacilityTreeItemUtil.removeChild(managerScope,
                            FacilityTreeAttributeConstant.INTERNAL_SCOPE)) {
                        m_log.warn("failed removing " + FacilityTreeAttributeConstant.INTERNAL_SCOPE);
                    }
                }
            } else {
                if (!FacilityTreeItemUtil.removeChild(scope, FacilityTreeAttributeConstant.INTERNAL_SCOPE)) {
                    m_log.warn("failed removing " + FacilityTreeAttributeConstant.INTERNAL_SCOPE
                            + ", managerName=" + managerName);
                }
            }
        }
        if (!unregistered) {
            if (managerName == null) {
                for (FacilityTreeItem managerScope : scope.getChildren()) {
                    if (!FacilityTreeItemUtil.removeChild(managerScope,
                            FacilityTreeAttributeConstant.UNREGISTERED_SCOPE)) {
                        m_log.warn("failed removing " + FacilityTreeAttributeConstant.UNREGISTERED_SCOPE);
                    }
                }
            } else {
                if (!FacilityTreeItemUtil.removeChild(scope,
                        FacilityTreeAttributeConstant.UNREGISTERED_SCOPE)) {
                    m_log.warn("failed removing " + FacilityTreeAttributeConstant.UNREGISTERED_SCOPE
                            + ", managerName=" + managerName);
                }
            }
        }
        if (rootFacilityId != null) {
            // rootFacilityId??
            FacilityTreeItemUtil.keepChild(scope, rootFacilityId);
        }
        if (scopeOnly) {
            FacilityTreeItemUtil.removeNode(scope);
        }

        // SWT?????
        checkAsyncExec(new Runnable() {
            @Override
            public void run() {
                m_log.trace("FacilityTreeComposite.checkAsyncExec() do runnnable");

                Control control = treeViewer.getControl();
                if (control == null || control.isDisposed()) {
                    m_log.info("treeViewer is disposed. ");
                    return;
                }

                FacilityTreeItem oldTreeItem = (FacilityTreeItem) treeViewer.getInput();
                m_log.debug("run() oldTreeItem=" + oldTreeItem);
                if (null != oldTreeItem) {
                    if (!oldTreeItem.equals(treeItem)) {
                        ArrayList<String> expandIdList = new ArrayList<String>();
                        for (Object item : treeViewer.getExpandedElements()) {
                            expandIdList.add(((FacilityTreeItem) item).getData().getFacilityId());
                        }
                        m_log.debug("expandIdList.size=" + expandIdList.size());
                        treeViewer.setInput(treeItem);
                        treeViewer.refresh();
                        expand(treeItem, expandIdList);
                    }
                } else {
                    treeViewer.setInput(treeItem);
                    List<FacilityTreeItem> selectItem = treeItem.getChildren();
                    treeViewer.setSelection(new StructuredSelection(selectItem.get(0)), true);
                    //???
                    treeViewer.expandToLevel(3);
                }
                if (checkflg) {
                    // ???
                    setCheckedTreeInfo(selectFacilityList);
                }
            }

            private void expand(FacilityTreeItem item, List<String> expandIdList) {
                if (expandIdList.contains(item.getData().getFacilityId())) {
                    treeViewer.expandToLevel(item, 1);
                }
                for (FacilityTreeItem child : item.getChildren()) {
                    expand(child, expandIdList);
                }
            }
        });
    }
}