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.kalypso.zml.ui.table.commands.menu.ZmlCommandSetValuesBelow.java

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    try {/* www.java 2  s  .c  o m*/
        final IZmlTable table = ZmlHandlerUtil.getTable(event);
        final ZmlModelViewport model = table.getModelViewport();
        final IZmlTableSelection selection = table.getSelection();
        final IZmlModelValueCell active = selection.getFocusCell();
        if (active == null)
            return Status.CANCEL_STATUS;

        final IZmlModelColumn column = active.getColumn();
        final IZmlEditingStrategy strategy = model.getEditingStrategy(column);

        if (strategy.isAggregated()) {
            final ZmlModelCellLabelProvider provider = new ZmlModelCellLabelProvider(column);
            final String targetValue = provider.getText(table.getModelViewport(), active);

            IZmlModelValueCell ptr = model.findNextCell(active);
            while (ptr != null) {
                strategy.setValue(ptr, targetValue);

                ptr = model.findNextCell(ptr);
            }
        } else {
            final Object targetValue = active.getValue();
            final Date base = active.getIndexValue();

            final TupleModelTransaction transaction = new TupleModelTransaction(column.getTupleModel(),
                    column.getMetadata());

            column.accept(new IZmlModelColumnVisitor() {
                @Override
                public void visit(final IZmlModelValueCell ref) {
                    final Date current = ref.getIndexValue();
                    if (current.before(base) || current.equals(base))
                        return;

                    final TupleModelDataSet dataset = new TupleModelDataSet(column.getValueAxis(), targetValue,
                            KalypsoStati.BIT_USER_MODIFIED, IDataSourceItem.SOURCE_MANUAL_CHANGED);
                    transaction.add(new UpdateTupleModelDataSetCommand(ref.getModelIndex(), dataset, true));
                }
            });

            column.getTupleModel().execute(transaction);
        }

        doInterpolation(column);

        return Status.OK_STATUS;
    } catch (final Exception e) {
        throw new ExecutionException(Messages.ZmlCommandSetValuesBelow_0, e);
    }
}

From source file:org.alfresco.wcm.client.UgcServiceTest.java

public void testPostFeedback() {
    WebSite site = getWebSite();/*from w  w w. j a va2 s.c  o  m*/

    Section root = site.getRootSection();
    String rootId = root.getId();

    Asset indexAsset = assetFactory.getSectionAsset(root.getId(), "index.html");
    assertEquals("index.html", indexAsset.getName());
    assertEquals(rootId, indexAsset.getContainingSection().getId());

    log.info("Article id = " + indexAsset.getId());

    Date beforePost = new Date();
    String feedbackId = site.getUgcService().postFeedback(indexAsset.getId(), "Brian", "brian@theworld",
            "www.brian.com", UgcService.COMMENT_TYPE, null, "This is a fantastic article",
            new Random(System.currentTimeMillis()).nextInt(6));
    Date afterPost = new Date();

    long count = 0;
    VisitorFeedbackPage page = site.getUgcService().getFeedbackPage(indexAsset.getId(), 10, count);
    long totalSize = page.getTotalSize();
    boolean found = false;
    while (page.getSize() > 0) {
        List<VisitorFeedback> feedbackList = page.getFeedback();
        for (VisitorFeedback feedback : feedbackList) {
            ++count;
            if (!found) {
                found = (feedback.getId().equals(feedbackId));
                if (found) {
                    Date feedbackTime = feedback.getPostTime();
                    assertNotNull(feedbackTime);
                    assertTrue(feedbackTime.after(beforePost) || feedbackTime.equals(beforePost));
                    assertTrue(feedbackTime.before(afterPost) || feedbackTime.equals(afterPost));
                }
            }
        }
        page = site.getUgcService().getFeedbackPage(indexAsset.getId(), 10, count);
    }
    assertEquals(totalSize, count);
    assertTrue(found);
}

From source file:com.hyron.poscafe.CashRegister.java

public void setAccountDate(Date accountDate) {
    if (!accountDate.equals(this.accountDate)) {
        super.setChanged();
        super.notifyObservers(accountDate);
    }/*from   ww  w.  j a v a2s  .  com*/
    this.accountDate = accountDate;
}

From source file:hu.petabyte.redflags.engine.gear.indicator.hu.DecisionDateDiffersFromOpeningDateIndicator.java

@Override
protected IndicatorResult flagImpl(Notice notice) {
    String procType = fetchProcedureType(notice);
    if (!procType.equals("PR-1")) {
        return irrelevantData();
    }//from   w ww  . j  a  va  2 s.  c om

    parseFamilyMeta(notice);
    int selfIndex = memberIndexOfSelf(notice);
    int td3Index = memberIndexOfClosestTD3(notice, selfIndex);

    Notice deadlineDoc = null;
    Notice td3 = null;
    Procedure proc = null;
    Duration maintainDuration = null;
    if (null == (deadlineDoc = getDeadlineDoc(notice, selfIndex, td3Index))
            || null == (td3 = getTD3(notice, td3Index)) || null == (proc = td3.getProc())
            || null == (maintainDuration = proc.getMinMaintainDuration())) {
        return missingData();
    }

    Date td3Deadline = td3.getData().getDeadline();
    Date deadline = deadlineDoc.getData().getDeadline();
    String mod = td3Deadline.equals(deadline) ? "" : "mdost doksi: " + deadlineDoc.getUrl();

    if (0 == maintainDuration.getInDays()) {
        Date d = rawParser.parseDate(maintainDuration.getRaw());
        maintainDuration.setBegin(deadline);
        maintainDuration.setEnd(d);
        maintainDuration.fill();
    }

    LOG.trace("Deadline: {}", deadline);
    LOG.trace("Maintain: {}", proc.getMinMaintainDuration().getRaw());

    int maxDays = addToMaintainDays + maintainDuration.getInDays();
    for (Award a : notice.getAwards()) {
        Duration d = new Duration();
        d.setBegin(deadlineDoc.getData().getDeadline());
        d.setEnd(a.getDecisionDate());
        d.fill();
        LOG.trace("Decision: {} ({} days) (max={})", a.getDecisionDate(), d.getInDays(), maxDays);
        if (d.getInDays() > maxDays) {
            // System.out
            // .println("DECISION DATE FLAGGED DOCS;"
            // + td3.getUrl()
            // + ";"
            // + notice.getUrl()
            // + ";"
            // + String.format(
            // "Az ajnlatok felbontsa s a dnts kztt tl hossz id telt el: %d > %d %s",
            // d.getInDays(), maxDays, mod));
            return returnFlag("info", "days=" + d.getInDays(), "max=" + maxDays);
        }
    }

    return null;
}

From source file:org.openehealth.coala.converter.PXSDateConverterTest.java

/**
 * Tests for correct conversion from String to Date
 * Test method for {@link org.openehealth.coala.util.PXSDateConverter#stringToDate(java.lang.String)}.
 *///from w  ww.  j ava  2  s .c om
@Test
@Ignore
public void testStringToDate() {

    Date pxsDate = pxsDateConverter.stringToDate(referenceStringLong);
    assertTrue(pxsDate.getTime() == referenceDateLong.getTime());

    pxsDate = pxsDateConverter.stringToDate(referenceStringShort);
    assertTrue(pxsDate.equals(referenceDateShort));
}

From source file:org.jboss.jsfunit.test.richfaces.AjaxPollTest.java

public void testPoll_OnOffTest() throws InterruptedException, IOException {
    JSFSession jsfSession = JSFSessionFactory.makeSession("/richfaces/poll.jsf");
    JSFClientSession client = jsfSession.getJSFClientSession();
    RichFacesClient ajaxClient = new RichFacesClient(client);
    JSFServerSession server = jsfSession.getJSFServerSession();

    // Get the backing bean to check activity
    PollBean pb = (PollBean) server.getManagedBeanValue(_POLLBEAN);
    assertNotNull("Can't find PollBean", pb);
    // Make sure polling is enabled
    assertTrue("Polling is not enabled in the PollBean", pb.getPollEnabled());

    // Get poll control to check status
    UIPoll poll = (UIPoll) server.findComponent(_POLL_ID);
    assertNotNull("Can't find server side poll component", poll);
    int interval = poll.getInterval();
    // Make sure polling is enabled
    assertTrue("Polling is not enabled in the component", poll.isEnabled());

    // Make sure the date is updating
    Date startDate = pb.getLasttime();
    Thread.sleep(interval * 4);/* ww  w.j  a  va2s.c o m*/
    Date endDate = pb.getLasttime();
    assertFalse("Date is not being updated in the PollBean", startDate.equals(endDate));

    // Get control button and disable polling
    HtmlButtonInput button = (HtmlButtonInput) client.getElement(_BUTTON_ID);
    assertNotNull("Can't find polling control button [" + _BUTTON_ID + "]", button);
    button.click();

    // Wait for polling state to change
    Thread.sleep(interval * 2);

    // Make sure we're no longer polling
    assertFalse("Polling should be disabled in the PollBean", pb.getPollEnabled());
    // Check the server-side control also (TBD: This causes IllegalStateException)
    //      poll = (UIPoll)server.findComponent(_POLL_ID);
    //      assertFalse("Polling should be disabled in the component",poll.isEnabled());
    // Make sure the date is NOT updating
    startDate = pb.getLasttime();
    Thread.sleep(interval * 4);
    endDate = pb.getLasttime();
    assertTrue("Date should not be updating in the PollBean", startDate.equals(endDate));

    // Turn polling back on (page was updated, therefore we MUST re-get the control)
    button = (HtmlButtonInput) client.getElement(_BUTTON_ID);
    button.click();

    // Wait for polling state to change
    Thread.sleep(interval * 2);

    // Make sure we're polling again
    assertTrue("Polling is not enabled in the PollBean", pb.getPollEnabled());
    // Check the server-side control also (TBD: This causes IllegalStateException)      
    //      poll = (UIPoll)server.findComponent(_POLL_ID);
    //      assertTrue("Polling is not enabled in the component",poll.isEnabled());
    // Make sure the date is updating
    startDate = pb.getLasttime();
    Thread.sleep(interval * 4);
    endDate = pb.getLasttime();
    assertFalse("Date is not being updated in the PollBean", startDate.equals(endDate));

}

From source file:org.openmrs.module.pihmalawi.reporting.definition.cohort.evaluator.EncounterAfterTerminalStateCohortDefinitionEvaluator.java

public EvaluatedCohort evaluate(CohortDefinition cohortDefinition, EvaluationContext context) {
    EncounterAfterTerminalStateCohortDefinition cd = (EncounterAfterTerminalStateCohortDefinition) cohortDefinition;

    Cohort c = new Cohort();

    HqlQueryBuilder maxStateStart = new HqlQueryBuilder();
    maxStateStart.select("ps.patientProgram.patient.patientId", "ps.patientProgram.location.locationId",
            "max(ps.startDate)");
    maxStateStart.from(PatientState.class, "ps");
    maxStateStart.wherePatientIn("ps.patientProgram.patient.patientId", context);
    maxStateStart.whereEqual("ps.patientProgram.program", cd.getProgram());
    maxStateStart.whereIn("ps.patientProgram.location", cd.getLocations());
    maxStateStart.groupBy("ps.patientProgram.patient.patientId")
            .groupBy("ps.patientProgram.location.locationId");

    Map<Integer, Map<Integer, Date>> maxStateDates = getPatientLocationDateMap(maxStateStart, context);

    HqlQueryBuilder maxTerminalStart = new HqlQueryBuilder();
    maxTerminalStart.select("ps.patientProgram.patient.patientId", "ps.patientProgram.location.locationId",
            "max(ps.startDate)");
    maxTerminalStart.from(PatientState.class, "ps");
    maxTerminalStart.wherePatientIn("ps.patientProgram.patient.patientId", context);
    maxTerminalStart.whereEqual("ps.patientProgram.program", cd.getProgram());
    maxTerminalStart.whereIn("ps.patientProgram.location", cd.getLocations());
    maxTerminalStart.whereEqual("ps.state.terminal", true);
    maxTerminalStart.groupBy("ps.patientProgram.patient.patientId")
            .groupBy("ps.patientProgram.location.locationId");

    Map<Integer, Map<Integer, Date>> maxTerminalStateDates = getPatientLocationDateMap(maxTerminalStart,
            context);/*ww w. j  ava 2 s. com*/

    HqlQueryBuilder encounterQuery = new HqlQueryBuilder();
    encounterQuery.select("e.patient.patientId", "e.location.locationId", "max(e.encounterDatetime)");
    encounterQuery.from(Encounter.class, "e");
    encounterQuery.wherePatientIn("e.patient.patientId", context);
    encounterQuery.whereEqual("e.patient.voided", false);
    encounterQuery.whereIn("e.encounterType", cd.getEncounterTypes());
    encounterQuery.whereIn("e.location", cd.getLocations());
    encounterQuery.groupBy("e.patient.patientId").groupBy("e.location.locationId");

    Map<Integer, Map<Integer, Date>> maxEncounterDates = getPatientLocationDateMap(encounterQuery, context);

    for (Integer pId : maxEncounterDates.keySet()) {
        Map<Integer, Date> encounterDateMap = maxEncounterDates.get(pId);
        Map<Integer, Date> maxStateDateMap = maxStateDates.get(pId);
        Map<Integer, Date> maxTerminalStateDateMap = maxTerminalStateDates.get(pId);

        for (Integer locationId : encounterDateMap.keySet()) {
            Date encounterDate = encounterDateMap.get(locationId);
            Date stateDate = (maxStateDateMap != null ? maxStateDateMap.get(locationId) : null);
            Date terminalDate = (maxTerminalStateDateMap != null ? maxTerminalStateDateMap.get(locationId)
                    : null);
            if (terminalDate != null && encounterDate.after(terminalDate) && terminalDate.equals(stateDate)) {
                c.addMember(pId);
            }
        }
    }

    return new EvaluatedCohort(c, cd, context);
}

From source file:net.sourceforge.jaulp.lang.ObjectUtilsTest.java

/**
 * Test generic clone method.//  w w w  . j a v  a  2s  .  c o  m
 */
@Test(enabled = false)
public void testClone() {
    Date past = CreateDateUtils.newDate(2009, 3, 26, 10, 37, 04);
    Date otherCopy = ObjectUtils.clone(past);

    boolean result = past.equals(otherCopy);
    AssertJUnit.assertTrue("Cloned object should be equal with the source object.", result);

    String aString = "Hy there...";

    String clonedString = ObjectUtils.clone(aString);

    result = aString.equals(clonedString);
    AssertJUnit.assertTrue("Cloned object should be equal with the source object.", result);

    A a = new A();
    a.setA("a");

    A anotherCopy = ObjectUtils.clone(a);

    result = a.equals(anotherCopy);
    AssertJUnit.assertTrue("Cloned object should be equal with the source object.", result);
}

From source file:org.jboss.jsfunit.test.richfaces.AjaxPollTest.java

public void testPoll_StillRunning() throws InterruptedException, IOException {
    JSFSession jsfSession = JSFSessionFactory.makeSession("/richfaces/inplaceInput.jsf"); // Anything but the Polling page
    JSFClientSession client = jsfSession.getJSFClientSession();
    RichFacesClient ajaxClient = new RichFacesClient(client);
    JSFServerSession server = jsfSession.getJSFServerSession();

    // Get the backing bean to check activity
    PollBean pb = (PollBean) server.getManagedBeanValue(_POLLBEAN);
    assertNotNull("Can't find PollBean", pb);
    // Make sure the date is NOT updating
    Date startDate = pb.getLasttime();
    Thread.sleep(_EXPECTED_POLLING_INTERVAL * 4);
    Date endDate = pb.getLasttime();
    assertTrue("Date should not be updating in the PollBean",
            startDate == endDate || startDate.equals(endDate));
}

From source file:hr.fer.zemris.vhdllab.dao.impl.ClientLogDaoTest.java

/**
 * Created on can't be updated.// ww  w .  j a  v a  2s  . c om
 */
@Test
public void createdOnNotUpdateable() {
    entity.setName("name");
    entity.setUserId("userId");
    entity.setData("data");
    entity.setCreatedOn(new Date());
    dao.persist(entity);

    Date newCreatedOn = CREATED_ON;
    entity.setCreatedOn(newCreatedOn);
    dao.merge(entity);
    closeEntityManager(); // flush cache
    createEntityManager();
    ClientLog loaded = dao.load(entity.getId());
    assertFalse(newCreatedOn.equals(loaded.getCreatedOn()));
}