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:mekhq.campaign.mission.Contract.java

/**
 * Get the number of months left in this contract after the given date. Partial months are counted as
 * full months./* w ww .  j  a  v  a  2 s.c  o  m*/
 *
 * @param date
 * @return
 */
public int getMonthsLeft(Date date) {
    GregorianCalendar cal = new GregorianCalendar();
    cal.setTime(date);
    cal.add(Calendar.MONTH, 1);
    date = cal.getTime();
    int monthsLeft = 0;
    while (date.before(endDate) || date.equals(endDate)) {
        monthsLeft++;
        cal.add(Calendar.MONTH, 1);
        date = cal.getTime();
    }
    return monthsLeft;
}

From source file:org.openmrs.module.openconceptlab.updater.Importer.java

/**
 * @param oldItem/* w ww  . j  a va 2 s .  c  o  m*/
 * @param newMapping
 * @return boolean
 * @should should return true if any of updatedOn is null
 * @should should return false if both updatedOn are null
 * @should should return if mapping's updatedOn is after
 */

public boolean isMappingUpToDate(Item oldItem, OclMapping newMapping) {
    Date oldUpdatedOn = oldItem.getUpdatedOn();
    Date newUpdatedOn = newMapping.getUpdatedOn();
    //mapping never was updated
    if (oldUpdatedOn == null && newUpdatedOn == null) {
        return true;
    }
    //mapping was updated at least once
    else if (oldUpdatedOn != null && newUpdatedOn != null) {
        return newUpdatedOn.equals(oldUpdatedOn);
    }
    //this is first update - old version updatedOn is null
    else
        return false;
}

From source file:com.collabnet.ccf.pi.sfee.v44.SFEEAppHandler.java

private void addComments(List<ArtifactSoapDO> artifactHistory, ArtifactSoapDO artifact, Date lastModifiedDate,
        String connectorUser, String resyncUser) {
    try {/*w w w  . j av  a 2 s.c om*/
        CommentSoapList commentList = mSfSoap.getCommentList(mSessionId, artifact.getId());
        CommentSoapRow[] comments = commentList.getDataRows();
        if (comments != null) {
            for (CommentSoapRow comment : comments) {
                String createdBy = comment.getCreatedBy();
                Date createdDate = comment.getDateCreated();
                if (createdBy.equals(connectorUser) || createdBy.equals(resyncUser)) {
                    continue;
                }
                if (lastModifiedDate.after(createdDate) || lastModifiedDate.equals(createdDate)) {
                    continue;
                }
                String description = comment.getDescription();
                description = "\nOriginal commenter: " + createdBy + "\n" + description;
                boolean commentSet = false;
                for (ArtifactSoapDO artifactDO : artifactHistory) {
                    // TODO If nothing is matching what will happen?
                    // if(artifactDO.getLastModifiedDate().after(createdDate)
                    // ||
                    // artifactDO.getLastModifiedDate().equals(createdDate)){
                    // TODO If more than one comment is added, How this will
                    // behave?
                    this.addComment(ArtifactMetaData.SFEEFields.commentText.getFieldName(), artifactDO,
                            description);
                    commentSet = true;
                    break;
                    // }
                }
                if (!commentSet) {
                    log.error("Comment " + description + " Could not be set " + createdDate);
                }
            }
        }
    } catch (RemoteException e) {
        log.error("Could not get comments list for artifact " + artifact.getId() + ": " + e.getMessage());
    }
}

From source file:org.jvnet.hudson.plugins.thinbackup.backup.BackupSet.java

/**
 * @param date date to search for/*from   w ww  . j  a v  a  2  s. c  o  m*/
 * @return true if a backup for the given date exists in this BackupSet.
 */
public boolean containsBackupForDate(final Date date) {
    if ((date == null) || !isValid()) {
        return false;
    }

    Date tmp = null;

    boolean inDiffs = false;
    if (diffBackupsNames != null) {
        for (final String diffBackupName : diffBackupsNames) {
            tmp = Utils.getDateFromBackupDirectoryName(diffBackupName);
            inDiffs = (tmp != null) && date.equals(tmp);
            if (inDiffs) {
                break;
            }
        }
    }

    tmp = Utils.getDateFromBackupDirectoryName(fullBackupName);
    return (inDiffs || ((tmp != null) && date.equals(tmp)));
}

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

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

    if (orderId == null) {
        return;//from  w  ww .j av a  2s .c o  m
    }

    Date finishDate = order.getDateField(OrderFields.FINISH_DATE);
    if (finishDate == null) {
        return;
    }

    Entity orderFromDB = orderService.getOrder(orderId);

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

    Date finishDateDB = new Date();
    if (orderFromDB.getDateField(OrderFields.FINISH_DATE) != null) {
        finishDateDB = orderFromDB.getDateField(OrderFields.FINISH_DATE);
    }
    if (OrderState.PENDING.getStringValue().equals(state) && !finishDateDB.equals(finishDate)) {
        order.setField(OrderFields.DATE_TO, finishDate);
    }
    if ((OrderState.COMPLETED.getStringValue().equals(state)
            || OrderState.ABANDONED.getStringValue().equals(state)) && !finishDateDB.equals(finishDate)) {
        order.setField(OrderFields.EFFECTIVE_DATE_TO, finishDate);
    }
    if ((OrderState.ACCEPTED.getStringValue().equals(state)
            || OrderState.IN_PROGRESS.getStringValue().equals(state)) && !finishDateDB.equals(finishDate)) {
        order.setField(OrderFields.CORRECTED_DATE_TO, finishDate);
    }
}

From source file:com.enonic.cms.core.content.ContentEntity.java

private boolean isAvailableByDateTime(Date date) {
    if (availableFrom == null) {
        return false;
    }//from w  w  w .  j  a  v  a  2s. c o  m

    if (availableFrom.after(date)) {
        return false;
    }

    if (availableTo != null) {
        if (date.after(availableTo) || date.equals(availableTo)) {
            return false;
        }
    }

    return true;
}

From source file:dk.nsi.haiba.minipasconverter.dao.impl.MinipasHAIBADAOImpl.java

@Override
public MinipasSyncStructure syncTest(int year, Collection<MinipasTADM> minipasRows) {
    Monitor mon = MonitorFactory.start("MinipasSyncDAOImpl.test");
    MinipasSyncStructureImpl returnValue = new MinipasSyncStructureImpl();
    Map<String, SyncStruct> pendingIdnummersForYear = getPendingIdNummersForYear(year);
    for (MinipasTADM minipasTADM : minipasRows) {
        Date skemaopdat = null;
        // remove the query result. the remains are considered deleted
        SyncStruct syncStruct = pendingIdnummersForYear.remove(minipasTADM.getIdnummer());
        if (syncStruct != null) {
            skemaopdat = syncStruct.aSkemaOpdat;
        }/*from   ww  w  . j a va 2s  .  c o m*/
        Date d = minipasTADM.getSkemaopdat() != null ? minipasTADM.getSkemaopdat()
                : minipasTADM.getSkemaopret();
        if (skemaopdat == null) {
            returnValue.aCreated.add(minipasTADM);
        } else if (!skemaopdat.equals(d)) {
            if (aLog.isTraceEnabled()) {
                aLog.trace("test: " + aSimpleDateFormat.format(skemaopdat) + "!=" + d + " for "
                        + minipasTADM.getIdnummer());
            }
            returnValue.aUpdated.add(minipasTADM);
        }
    }
    mon.stop();
    return returnValue;
}

From source file:org.openmainframe.ade.ext.output.ExtJaxbAnalyzedPeriodV2XmlStorer.java

/**
 * Override superclass to use the new JAXB classes.
 *//*w  w w . j av  a2  s.co  m*/
@Override
public void incomingObject(IAnalyzedInterval analyzedInterval) throws AdeException, AdeFlowException {
    if (analyzedInterval.getInterval().getSource().getSourceId().equals(m_source)) {
        throw new AdeFlowException("Cannot process analyzed interval of source other than "
                + m_source.getSourceId() + ". Got analyzed interval from source "
                + analyzedInterval.getInterval().getSource().getSourceId());
    }
    Date periodStart = PeriodUtils
            .getContainingPeriodStart(new Date(analyzedInterval.getIntervalEndTime() - 1));
    if (!periodStart.equals(m_periodStartDate)) {
        if (m_inPeriod) {
            closePeriod();
        }
        startNewPeriod(analyzedInterval);
    }

    int index = getIntervalIndex(analyzedInterval);

    m_lastKnownModelInternalID = analyzedInterval.getModelInternalId();
    /* Retrieve the Model Data Here.  Force refresh, in case the Model's Analysis Group Change without impacting
     * the model internal ID. */
    /* Note: Checking of model version is not required here.  This method is used to output the analysis result
     * using an existing model.  If the model is not understandable by our code, this method would not have been
     * called.
     */
    m_xmlMetaData.retrieveXMLMetaData(m_lastKnownModelInternalID, true, m_framingFlowType.getDuration());

    /* Note: the value in m_aiVec must be the same as the value from AdeCore.  Any manipulation of the
     * value to be output to the XML is done in writePeriod(). */
    m_aiVec[index].m_results_file = Ade.getAde().getConfigProperties().getOutputFilenameGenerator()
            .getIntervalXmlFileRelativeToIndex(analyzedInterval, m_framingFlowType);
    m_aiVec[index].m_num_unique_msg_ids = analyzedInterval.getNumUniqueMessageIds();
    m_aiVec[index].m_anomaly_score = analyzedInterval.getScore();
    m_aiVec[index].m_modelQualityIndicator = m_xmlMetaData.getLimitedModelIndicator();
    NewAndNeverSeenBeforeMessages messages = NewAndNeverSeenBeforeMessagesUtils
            .processAnalyzedInterval(analyzedInterval);
    m_aiVec[index].m_numNewMessages = messages.getNumNewMessages();
    m_aiVec[index].m_numNeverSeenBeforeMessages = messages.getNumNeverSeenBeforeMessages();

    if (m_refreash_periods) {
        writePeriod();
    }
}

From source file:architecture.user.MultiProviderUserManager.java

private boolean equals(Date a, Date b) {
    if (a == null && b == null)
        return true;
    return a != null && a.equals(b);
}

From source file:de.micromata.genome.gwiki.pagelifecycle_1_0.action.WorkflowPopupActionBean.java

/**
 * returns a list of all available (offline) branches for assign an article to
 *///from   ww w . j  a  va2 s  . c  om
public List<Map<String, Object>> getAvailableBranches() {
    List<String> allTenants = getWikiSelector().getMptIdSelector().getTenants(GWikiWeb.getRootWiki());
    List<Map<String, Object>> branchProps = new ArrayList<Map<String, Object>>();

    // default new branch is selected
    this.selectedBranch = NEW_BRANCH;

    for (String tenantId : allTenants) {

        // if approve you have to copy the file in a branch other than draft
        if (PlcConstants.DRAFT_ID.equalsIgnoreCase(tenantId) == true
                && FileState.APPROVED_CHIEF_EDITOR.name().equals(newPageState) == true) {
            continue;
        }

        GWikiProps branchInfoProp = wikiContext.runInTenantContext(tenantId, getWikiSelector(),
                new CallableX<GWikiProps, RuntimeException>() {
                    @Override
                    public GWikiProps call() throws RuntimeException {
                        return PlcUtils.getBranchInfo(wikiContext);
                    }
                });

        if (branchInfoProp == null) {
            continue;
        }

        // only add offline branches
        if (BranchState.OFFLINE.name()
                .equals(branchInfoProp.getStringValue(PlcConstants.BRANCH_INFO_BRANCH_STATE)) == true) {
            Map<String, Object> m = new HashMap<String, Object>();
            m.putAll(branchInfoProp.getMap());
            m.put("RELEASE_DATE_DATE", GWikiProps
                    .parseTimeStamp(branchInfoProp.getStringValue(PlcConstants.BRANCH_INFO_RELEASE_DATE)));
            branchProps.add(m);

            // if branch release date matches article release date -> preselect branch
            String release = branchInfoProp.getStringValue(PlcConstants.BRANCH_INFO_RELEASE_DATE);
            Date branchReleaseDate = GWikiProps.parseTimeStamp(release);
            if (branchReleaseDate != null && branchReleaseDate.equals(getStartDateOfArticle())) {
                selectedBranch = branchInfoProp.getStringValue(PlcConstants.BRANCH_INFO_BRANCH_ID);
            }
        }
    }
    return branchProps;
}