Example usage for java.util Date compareTo

List of usage examples for java.util Date compareTo

Introduction

In this page you can find the example usage for java.util Date compareTo.

Prototype

public int compareTo(Date anotherDate) 

Source Link

Document

Compares two Dates for ordering.

Usage

From source file:org.egov.stms.web.controller.masters.DonationMasterController.java

@RequestMapping(value = "/fromDateValidationWithActiveRecord", method = RequestMethod.GET)
@ResponseBody/*from www. ja  va2  s . c  om*/
public String validateFromDateWithActiveDate(@RequestParam("propertyType") final PropertyType propertyType,
        @RequestParam("fromDate") final Date date) {
    final SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy");
    if (date != null) {
        final List<DonationMaster> donationList = donationMasterService
                .getLatestActiveRecordByPropertyTypeAndActive(propertyType, true);
        if (!donationList.isEmpty()) {
            final DonationMaster existingActiveDonationObject = donationList.get(0);
            if (existingActiveDonationObject.getFromDate().compareTo(new Date()) >= 0
                    && date.compareTo(existingActiveDonationObject.getFromDate()) < 0)
                return formatter.format(existingActiveDonationObject.getFromDate()).toString();
        }
    }
    return "true";
}

From source file:org.openvpms.archetype.rules.patient.reminder.ReminderRulesTestCase.java

/**
 * Tests the {@link ReminderRules#getDocumentFormReminder} method, when the <em>act.patientDocumentForm</em> is
 * linked to product with reminder types.
 */// ww  w. j a  v  a  2s .  co m
@Test
public void testGetDocumentFormReminderForProduct() {
    Party patient = TestHelper.createPatient();
    Product product = TestHelper.createProduct();
    DocumentAct form = PatientTestHelper.createDocumentForm(patient, product);

    // verify a form not associated with a product with reminders returns null
    assertNull(rules.getDocumentFormReminder(form));

    EntityBean productBean = new EntityBean(product);
    Entity reminderType1 = createReminderType();
    EntityRelationship productReminder1 = productBean.addNodeRelationship("reminders", reminderType1);
    IMObjectBean prodReminder1Bean = new IMObjectBean(productReminder1);
    prodReminder1Bean.setValue("period", 2); // due date will fall 2 years from start time

    save(product, reminderType1);

    Act reminder1 = rules.getDocumentFormReminder(form);
    assertNotNull(reminder1);
    assertTrue(reminder1.isNew()); // reminders from products should not be persistent
    Date dueDate1 = rules.calculateProductReminderDueDate(form.getActivityStartTime(), productReminder1);
    checkReminder(reminder1, reminderType1, patient, product, form, dueDate1);

    Entity reminderType2 = createReminderType();
    EntityRelationship productReminder2 = productBean.addNodeRelationship("reminders", reminderType2);
    save(product, reminderType2);

    Date dueDate2 = rules.calculateProductReminderDueDate(form.getActivityStartTime(), productReminder2);
    assertTrue(dueDate2.compareTo(dueDate1) < 0);

    Act reminder2 = rules.getDocumentFormReminder(form);
    assertNotNull(reminder2);
    assertTrue(reminder2.isNew()); // reminders from products should not be persistent
    checkReminder(reminder2, reminderType2, patient, product, form, dueDate2);
}

From source file:org.hoteia.qalingo.core.domain.Customer.java

public CustomerCredential getCurrentCredential() {
    if (credentials != null && Hibernate.isInitialized(credentials)) {
        List<CustomerCredential> sortedObjects = new LinkedList<CustomerCredential>(credentials);
        Collections.sort(sortedObjects, new Comparator<CustomerCredential>() {
            @Override/*from w w w  . ja va2 s.  c  o  m*/
            public int compare(CustomerCredential o1, CustomerCredential o2) {
                if (o1 != null && o2 != null) {
                    Date order1 = o1.getDateCreate();
                    Date order2 = o2.getDateCreate();
                    if (order1 != null && order2 != null) {
                        return order1.compareTo(order2);
                    } else {
                        return o1.getId().compareTo(o2.getId());
                    }
                }
                return 0;
            }
        });
        if (sortedObjects != null && sortedObjects.size() > 0) {
            return sortedObjects.get(0);
        }
    }
    return null;
}

From source file:org.araqne.pkg.PackageManagerService.java

private boolean needUpdate(PackageDescriptor installedPackage, PackageVersionHistory history) {
    int versionDiff = history.getVersion().compareTo(installedPackage.getVersion());

    Date currentDate = installedPackage.getDate();
    Date latestDate = history.getLastUpdated();

    if (versionDiff > 0 || (versionDiff == 0 && currentDate.compareTo(latestDate) < 0))
        return true;

    if (versionDiff == 0 && currentDate.compareTo(latestDate) > 0) {
        logger.warn("repository version is older. curious.");
    }//from   w w  w .  j a v  a  2 s. c o m

    return false;
}

From source file:algo.ad.feeder.ArtificialTweetsEmitterSpout.java

@Override
public void processRow(ResultSet rs) throws SQLException {
    // ///////////////////////////////
    //TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
    //System.out.println("ATE:Default TimeZone:"+TimeZone.getDefault());
    Tweet tweet = mapper.mapRow(rs, 0);//from www  . j a v  a  2  s.c om
    Date currentDate = tweet.getCreated_at();

    if (nextAggregatedDate == null) {

        try {

            nextAggregatedDate = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").parse("2013-06-20 18:00:00");

            //   AggregateUtilityFunctions.addMinutesToDate(
            //AGGREGATION_FACTOR_MINUTES, currentDate);
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }

    // while (!tweets.isEmpty()) {
    // While loop to emit the tuples with the aggregation condition
    if (currentDate.compareTo(nextAggregatedDate) <= 0) {
        _collector.emit(new Values(tweet.getTweet_id(), tweet.getSentiment().getSentimentCode(),
                tweet.getCreated_at(), nextAggregatedDate, 1));
        // tweet = tweets.remove(0);
        //currentDate = tweet.getCreated_at();
    } else {
        do {
            _collector.emit(new Values(tweet.getTweet_id(), 0, tweet.getCreated_at(), nextAggregatedDate, 0));

            _collector.emit(new Values(tweet.getTweet_id(), 2, tweet.getCreated_at(), nextAggregatedDate, 0));

            _collector.emit(new Values(tweet.getTweet_id(), 4, tweet.getCreated_at(), nextAggregatedDate, 0));

            //System.out.println("||Aggregate Date::" + nextAggregatedDate);

            // update for next aggregation range;
            nextAggregatedDate = AggregateUtilityFunctions.addMinutesToDate(AGGREGATION_FACTOR_MINUTES,
                    nextAggregatedDate);

        } while (currentDate.compareTo(nextAggregatedDate) > 0);

        _collector.emit(new Values(tweet.getTweet_id(), tweet.getSentiment().getSentimentCode(),
                tweet.getCreated_at(), nextAggregatedDate, 1));
    }

    Utils.sleep(SLEEP_FACTOR_MILLI_SEC);
}

From source file:org.mifos.accounts.productdefinition.business.PrdOfferingBO.java

private PrdStatusEntity getPrdStatus(final Date startDate, final ProductTypeEntity prdType)
        throws ProductDefinitionException {
    logger.debug("getting the Product status for prdouct offering with start date :" + startDate
            + " and product Type :" + prdType.getProductTypeID());
    PrdStatus prdStatus = null;//from  w ww  .j  ava2s.  co m
    if (startDate.compareTo(DateUtils.getCurrentDateWithoutTimeStamp()) == 0) {
        prdStatus = getActivePrdStatus(prdType);
    } else {
        prdStatus = getInActivePrdStatus(prdType);
    }
    try {
        logger.debug("getting the Product status for product status :" + prdStatus);
        return new PrdOfferingPersistence().getPrdStatus(prdStatus);
    } catch (PersistenceException e) {
        throw new ProductDefinitionException(e);
    }
}

From source file:org.apache.camel.bam.rules.TemporalRule.java

public void processExpired(ActivityState activityState) throws Exception {
    Processor processor = getOverdueAction();
    if (processor != null) {
        Date now = new Date();
        /*//from www .  j  a va  2  s.c  o  m
                    TODO this doesn't work and returns null for some strange reason
                    ProcessInstance instance = activityState.getProcessInstance();
                    ActivityState secondState = second.getActivityState(instance);
                    if (secondState == null) {
        log.error("Could not find the second state! Process is: " 
        + instance + " with first state: " + first.getActivityState(instance) 
        + " and the state I was called with was: " + activityState);
                    }
        */

        ActivityState secondState = activityState;
        Date overdue = secondState.getTimeOverdue();
        if (now.compareTo(overdue) >= 0) {
            Exchange exchange = createExchange();
            exchange.getIn().setBody(activityState);
            processor.process(exchange);
        } else {
            LOG.warn("Process has not actually expired; the time is: " + now + " but the overdue time is: "
                    + overdue);
        }
    }
}

From source file:com.marcohc.robotocalendar.RobotoCalendarView.java

public void selectDay(Date currentDate) {
    if (startDay == null) {
        selectStartDay(currentDate);/*from  w w  w. j  a  va2  s .  c om*/
    } else {
        if (startDay != null && endDay != null) {
        } else {
            if (currentDate.compareTo(startDay) >= 0) {
                selectEndDay(currentDate);
            } else {
                //do nothing
            }
        }
    }
    lastSelectedDay = currentDate;
}

From source file:com.amaze.filemanager.asynchronous.asynctasks.LoadFilesListTask.java

private ArrayList<LayoutElementParcelable> listRecentFiles() {
    ArrayList<LayoutElementParcelable> recentFiles = new ArrayList<>();
    final String[] projection = { MediaStore.Files.FileColumns.DATA,
            MediaStore.Files.FileColumns.DATE_MODIFIED };
    Calendar c = Calendar.getInstance();
    c.set(Calendar.DAY_OF_YEAR, c.get(Calendar.DAY_OF_YEAR) - 2);
    Date d = c.getTime();
    Cursor cursor = this.c.getContentResolver().query(MediaStore.Files.getContentUri("external"), projection,
            null, null, null);/*from   w w  w .  j av  a2  s. c  o  m*/
    if (cursor == null)
        return recentFiles;
    if (cursor.getCount() > 0 && cursor.moveToFirst()) {
        do {
            String path = cursor.getString(cursor.getColumnIndex(MediaStore.Files.FileColumns.DATA));
            File f = new File(path);
            if (d.compareTo(new Date(f.lastModified())) != 1 && !f.isDirectory()) {
                HybridFileParcelable strings = RootHelper.generateBaseFile(new File(path), showHiddenFiles);
                if (strings != null) {
                    LayoutElementParcelable parcelable = createListParcelables(strings);
                    if (parcelable != null)
                        recentFiles.add(parcelable);
                }
            }
        } while (cursor.moveToNext());
    }
    cursor.close();
    Collections.sort(recentFiles, (lhs, rhs) -> -1 * Long.valueOf(lhs.date).compareTo(rhs.date));
    if (recentFiles.size() > 20)
        for (int i = recentFiles.size() - 1; i > 20; i--) {
            recentFiles.remove(i);
        }
    return recentFiles;
}