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:com.kyne.webby.rtk.web.Connection.java

public void cleanOldAuthentications() {
    final Calendar cal = Calendar.getInstance();
    cal.add(Calendar.MINUTE,//w ww. jav a  2  s.  co m
            -1 * WebbyYAMLParser.getInt("webby.sessionTimeout", this.rtkModule.getPluginConf(), 10));
    final Date limit = cal.getTime();
    for (final String userAdress : this.webServer.getConnectedAdmins().keySet()) {
        final Date date = this.webServer.getConnectedAdmins().get(userAdress);
        if (date.compareTo(limit) < 0) {
            LogHelper.info("User " + userAdress + " has been connected more than "
                    + WebbyYAMLParser.getInt("webby.sessionTimeout", this.rtkModule.getPluginConf(), 10)
                    + " minute(s) ago, and will be disconnected");
            this.logOut(userAdress);
        }
    }
}

From source file:cx.ring.model.Conversation.java

public Date getLastInteraction() {
    if (!current_calls.isEmpty()) {
        return new Date();
    }//ww w.j av  a  2  s  .  co m
    Date d = new Date(0);

    //for (Map.Entry<String, HistoryEntry> e : history.entrySet()) {
    for (HistoryEntry e : history.values()) {
        Date nd = e.getLastInteraction();
        if (d.compareTo(nd) < 0)
            d = nd;
    }
    return d;
}

From source file:org.apache.lens.cube.metadata.CubeFactTable.java

/**
 * Get partition value strings for given range, for the specified updateInterval
 *
 * @param fromDate/*  ww w.  j a  v  a 2 s.com*/
 * @param toDate
 * @param interval
 * @return
 */
public List<String> getPartitions(Date fromDate, Date toDate, UpdatePeriod interval) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(fromDate);
    List<String> partitions = new ArrayList<String>();
    Date dt = cal.getTime();
    while (dt.compareTo(toDate) < 0) {
        String part = interval.format(cal.getTime());
        partitions.add(part);
        cal.add(interval.calendarField(), 1);
        dt = cal.getTime();
    }
    return partitions;
}

From source file:org.codice.ddf.landing.LandingPage.java

private void sortAnnouncementsByDate() {
    Collections.sort(announcements, new Comparator<String>() {
        @Override//from  ww w . j  a v  a2s . c  o m
        public int compare(String firstAnnouncement, String secondAnnouncement) {
            // Try to extract the dates from the announcements.
            String firstDateString = extractDate(firstAnnouncement, false);
            String secondDateString = extractDate(secondAnnouncement, false);

            final Date firstDate = dateFromString(firstDateString);
            final Date secondDate = dateFromString(secondDateString);
            // Sort the dates in descending order (most recent first).
            return secondDate.compareTo(firstDate);
        }
    });
}

From source file:org.tsm.concharto.lab.PopulateDummyData.java

public TimeRange makeDayRange(int m1, int d1, int y1, int hh1, int mm1, int ss1, int m2, int d2, int y2,
        int hh2, int mm2, int ss2) {
    Date date1 = makeDate(m1, d1, y1, hh1, mm1, ss1);
    Date date2 = makeDate(m2, d2, y2, hh2, mm2, ss2);
    TimeRange timeRange;/*from  w  w  w  . j  a  va 2  s. c om*/
    //switch dates if they are backward
    if (date1.compareTo(date2) >= 0) {
        timeRange = new TimeRange(date2, date1);
    } else {
        timeRange = new TimeRange(date1, date2);
    }
    return timeRange;
}

From source file:com.tcs.geofenceplugin.GeofenceTransitionsIntentService.java

private void getGeofenceTransitionDetails(Context context, int geofenceTransition,
        List<Geofence> triggeringGeofences) {

    ArrayList triggeringGeofencesIdsList = new ArrayList();
    Handler mHandler = new Handler();
    for (Geofence geofence : triggeringGeofences) {

        String geofenceTransitionString = getTransitionString(geofenceTransition);
        geofenceTransitionString += geofence.getRequestId();
        URL url;//from  w w  w  .java2 s . c  om
        HttpURLConnection urlConnection = null;
        JSONArray response = new JSONArray();
        String notificationtext = "";
        String place = "";
        String startdate = "";
        String enddate = "";
        JSONObject obj = new JSONObject();
        try {
            int restid = Integer.parseInt(geofence.getRequestId());
            url = new URL("https://apphonics.tcs.com/geofence/SelectTrigger?triggerid=" + restid);
            urlConnection = (HttpURLConnection) url.openConnection();
            urlConnection.setRequestMethod("GET");

            urlConnection.connect();
            int responseCode = urlConnection.getResponseCode();
            Log.d("Komal3", responseCode + "");

            if (responseCode == 200) {

                BufferedReader reader = new BufferedReader(
                        new InputStreamReader(urlConnection.getInputStream(), "utf-8"));
                StringBuilder sb = new StringBuilder();
                try {

                    String line = null;
                    while ((line = reader.readLine()) != null) {
                        sb.append(line + "\n");
                    }

                } catch (IOException e) {
                    e.printStackTrace();
                } finally {
                    if (reader != null) {
                        try {
                            reader.close();
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                    }
                }

                obj = new JSONObject(sb.toString());
                JSONArray arr = obj.getJSONArray("notificationdata");

                for (int i = 0; i < arr.length(); i++) {
                    JSONObject O = arr.getJSONObject(i);
                    notificationtext = O.getString("notification_text");
                    place = O.getString("place");
                    startdate = O.getString("startdate");
                    enddate = O.getString("enddate");
                }
                //response = new JSONArray(responseString);
            } else {
                Log.d(TAG, "Response code:" + responseCode);
            }

        } catch (Exception e) {
            e.printStackTrace();
            if (urlConnection != null)
                urlConnection.disconnect();
        }

        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        SimpleDateFormat format2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date datestart, dateend;
        try {
            datestart = format.parse(startdate);
            dateend = format2.parse(enddate);
            if (datestart.compareTo(new Date()) <= 0 && dateend.compareTo(new Date()) >= 0) {
                sendNotification(geofenceTransitionString, notificationtext, place);
            }

            mHandler.postDelayed(new Runnable() {
                public void run() {

                }
            }, 5000);

        } catch (ParseException e) {
            e.printStackTrace();
        }

    }

}

From source file:kr.steelheart.site.blog.web.FeedController.java

@RequestMapping(value = {
        "/feed" }, method = RequestMethod.GET, produces = MediaType.APPLICATION_ATOM_XML_VALUE)
@ResponseBody/*from   w  w w  .j  a  v a 2s.  c  o m*/
public Callable<Void> feed(final HttpServletRequest request) {
    return new Callable<Void>() {

        @Override
        public Void call() {
            PageRequest pageable = new PageRequest(0, 20, Direction.DESC, "created");
            Page<Post> posts = postRepository.findAll(QPost.post.publish.isTrue(), pageable);

            String host = "http://" + request.getAttribute("host") + "/";

            Feed feed = new Feed();

            List<SyndPerson> authors = new ArrayList<>();
            Person author = new Person();
            author.setName("Sungha Jun");
            author.setUri(host);
            authors.add(author);

            feed.setId(host);
            feed.setTitle("steelheart*Rocks!");
            feed.setAuthors(authors);
            feed.setCopyright("http://creativecommons.org/licenses/by/3.0/deed.en");

            for (Post post : posts) {
                Date updated = null;
                if (post.getUpdated() == null) {
                    updated = post.getCreated();
                } else {
                    updated = post.getUpdated();
                }

                if (feed.getUpdated() == null || updated.compareTo(feed.getUpdated()) > 0) {
                    feed.setUpdated(updated);
                }
            }

            if (feed.getUpdated() == null) {
                feed.setUpdated(new Date());
            }

            Link link = new Link();
            link.setType(MediaType.TEXT_HTML_VALUE);
            link.setHref(host + "feed");

            List<Link> links = new ArrayList<>();
            links.add(link);

            feed.setAlternateLinks(links);
            feed.setLogo(host + "img/logo@2x.png");

            return null;
        }
    };
}

From source file:io.fabric8.maven.core.service.openshift.ImageStreamService.java

public TagEvent newerTag(TagEvent tag1, TagEvent tag2) {
    Date tag1Date = extractDate(tag1);
    Date tag2Date = extractDate(tag2);

    if (tag1Date == null) {
        return tag2;
    }//from w w w  .  j  a v  a2s  . co m

    if (tag2Date == null) {
        return tag1;
    }

    return tag1Date.compareTo(tag2Date) > 0 ? tag1 : tag2;
}

From source file:org.kuali.kfs.module.endow.web.struts.TransactionSummaryAction.java

/**
 * Generates Transaction Statement in the PDF form
 * /*from ww  w.  j  ava  2  s .c o m*/
 * @param mapping
 * @param form
 * @param request
 * @param response
 * @return
 * @throws Exception
 */
public ActionForward print(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    TransactionSummaryReportService transactionSummaryReportService = SpringContext
            .getBean(TransactionSummaryReportService.class);

    // get all the value strings from the form
    TransactionSummaryForm transactionSummaryForm = (TransactionSummaryForm) form;
    String kemids = transactionSummaryForm.getKemid();
    String benefittingOrganziationCampuses = transactionSummaryForm.getBenefittingOrganziationCampus();
    String benefittingOrganziationCharts = transactionSummaryForm.getBenefittingOrganziationChart();
    String benefittingOrganziations = transactionSummaryForm.getBenefittingOrganziation();
    String typeCodes = transactionSummaryForm.getTypeCode();
    String purposeCodes = transactionSummaryForm.getPurposeCode();
    String combineGroupCodes = transactionSummaryForm.getCombineGroupCode();
    String beginningDate = transactionSummaryForm.getBeginningDate();
    String endingDate = transactionSummaryForm.getEndingDate();
    String endowmentOption = transactionSummaryForm.getEndowmentOption();
    String reportOption = transactionSummaryForm.getReportOption();
    String listKemidsOnHeader = transactionSummaryForm.getListKemidsInHeader();
    String summaryTotalsOnly = transactionSummaryForm.getSummaryTotalsOnly();
    String closedIndicator = transactionSummaryForm.getClosedIndicator();
    String message = transactionSummaryForm.getMessage();

    // check to see if the ending date is greater than the beginning date
    SimpleDateFormat df = new SimpleDateFormat("MM/dd/yyyy");
    try {
        java.util.Date beginDate = df.parse(beginningDate);
        java.util.Date endDate = df.parse(endingDate);

        if (beginDate.compareTo(endDate) >= 0) {
            transactionSummaryForm.setMessage(ERROR_REPORT_ENDING_DATE_NOT_GREATER_THAN_BEGINNING_DATE);
            return mapping.findForward(KFSConstants.MAPPING_BASIC);
        }
    } catch (ParseException e) {
        transactionSummaryForm.setMessage(e.getMessage());
        return mapping.findForward(KFSConstants.MAPPING_BASIC);
    }

    List<TransactionSummaryReportDataHolder> transactionSummaryReportList = null;

    /*
     * Creates the report data based on the selected criteria.
     * The criteria are selected as follows.
     * 1. Kemid and the other criteria cannot be selected at the same time.
     * 2. If none of them are selected, all kemids will be selected.
     * 3. The other criteria other than kemid are "OR" combined.
     * 4. All the criteria in the text input can be multiple by the use of wild card or the separator ('&' for kemid, ',' for the others) 
     * 5. Beginning Date and Ending Date are required.
     */

    if (StringUtils.isNotBlank(beginningDate) && StringUtils.isNotBlank(endingDate)) {
        if (StringUtils.isNotBlank(kemids)) {

            if ((StringUtils.isNotBlank(benefittingOrganziationCampuses)
                    || StringUtils.isNotBlank(benefittingOrganziationCharts)
                    || StringUtils.isNotBlank(benefittingOrganziations) || StringUtils.isNotBlank(typeCodes)
                    || StringUtils.isNotBlank(purposeCodes) || StringUtils.isNotBlank(combineGroupCodes))) {

                // kemid and the other criteria cannot be selected at the same time 
                transactionSummaryForm.setMessage(ERROR_REPORT_KEMID_WITH_OTHER_CRITERIA);
                return mapping.findForward(KFSConstants.MAPPING_BASIC);

            } else {
                // by kemid only
                List<String> kemidList = parseValueString(kemids, KEMID_SEPERATOR);
                transactionSummaryReportList = transactionSummaryReportService
                        .getTransactionSummaryReportsByKemidByIds(kemidList, beginningDate, endingDate,
                                endowmentOption, closedIndicator, reportOption);
            }
        } else {
            if ((StringUtils.isBlank(benefittingOrganziationCampuses)
                    && StringUtils.isBlank(benefittingOrganziationCharts)
                    && StringUtils.isBlank(benefittingOrganziations) && StringUtils.isBlank(typeCodes)
                    && StringUtils.isBlank(purposeCodes) && StringUtils.isBlank(combineGroupCodes))) {

                // for all kemids
                transactionSummaryReportList = transactionSummaryReportService
                        .getTransactionSummaryReportForAllKemids(beginningDate, endingDate, endowmentOption,
                                closedIndicator, reportOption);

            } else {
                // by other criteria
                transactionSummaryReportList = transactionSummaryReportService
                        .getTransactionSummaryReportsByOtherCriteria(
                                parseValueString(benefittingOrganziationCampuses, OTHER_CRITERIA_SEPERATOR),
                                parseValueString(benefittingOrganziationCharts, OTHER_CRITERIA_SEPERATOR),
                                parseValueString(benefittingOrganziations, OTHER_CRITERIA_SEPERATOR),
                                parseValueString(typeCodes, OTHER_CRITERIA_SEPERATOR),
                                parseValueString(purposeCodes, OTHER_CRITERIA_SEPERATOR),
                                parseValueString(combineGroupCodes, OTHER_CRITERIA_SEPERATOR), beginningDate,
                                endingDate, endowmentOption, closedIndicator, reportOption);
            }
        }
    } else {
        transactionSummaryForm.setMessage(ERROR_BOTH_BEGINNING_AND_ENDING_DATE_REQUIRED);
        return mapping.findForward(KFSConstants.MAPPING_BASIC);
    }

    // see if you have something to print        
    if (transactionSummaryReportList != null && !transactionSummaryReportList.isEmpty()) {
        // prepare the header sheet data
        EndowmentReportHeaderDataHolder reportRequestHeaderDataHolder = transactionSummaryReportService
                .createReportHeaderSheetData(getKemidsSelected(transactionSummaryReportList),
                        parseValueString(benefittingOrganziationCampuses, OTHER_CRITERIA_SEPERATOR),
                        parseValueString(benefittingOrganziationCharts, OTHER_CRITERIA_SEPERATOR),
                        parseValueString(benefittingOrganziations, OTHER_CRITERIA_SEPERATOR),
                        parseValueString(typeCodes, OTHER_CRITERIA_SEPERATOR),
                        parseValueString(purposeCodes, OTHER_CRITERIA_SEPERATOR),
                        parseValueString(combineGroupCodes, OTHER_CRITERIA_SEPERATOR), REPORT_NAME,
                        endowmentOption, null);

        // generate the report in PDF 
        ByteArrayOutputStream pdfStream = new TransactionSummaryReportPrint().printTransactionSummaryReport(
                reportRequestHeaderDataHolder, transactionSummaryReportList, listKemidsOnHeader, reportOption,
                summaryTotalsOnly);
        if (pdfStream != null) {
            transactionSummaryForm.setMessage("Reports Generated");
            WebUtils.saveMimeOutputStreamAsFile(response, "application/pdf", pdfStream, REPORT_FILE_NAME);
            return null;
        }
    }

    // No report was generated
    transactionSummaryForm.setMessage("Report was not generated for " + kemids + ".");

    return mapping.findForward(KFSConstants.MAPPING_BASIC);

}

From source file:org.orcid.persistence.jpa.entities.OrcidOauth2TokenDetail.java

@Override
public int compareTo(OrcidOauth2TokenDetail other) {
    String clientId = clientDetailsId;
    String otherClientId = other.getClientDetailsId();
    int compareClientId = 0;
    if (StringUtils.isNotBlank(clientId)) {
        compareClientId = clientId.compareTo(otherClientId);
    }/*from   w w  w  .ja v  a  2 s .co  m*/

    if (compareClientId != 0) {
        return compareClientId;
    }
    Date thisDateCreated = getDateCreated();
    if (thisDateCreated != null) {
        Date otherDateCreated = other.getDateCreated();
        if (otherDateCreated != null) {
            int compareDateCreated = thisDateCreated.compareTo(otherDateCreated);
            if (compareDateCreated != 0) {
                return compareDateCreated;
            }
        }
    }
    return tokenValue.compareTo(other.tokenValue);
}