List of usage examples for java.util Date compareTo
public int compareTo(Date anotherDate)
From source file:org.openvpms.archetype.rules.workflow.AbstractScheduleService.java
/** * Returns all events for the specified schedule, and time range. * * @param schedule the schedule/*from ww w . j a v a 2s . c o m*/ * @param from the from time * @param to the to time * @return a list of events */ public List<PropertySet> getEvents(Entity schedule, Date from, Date to) { Date fromDay = DateRules.getDate(from); Date toDay = DateRules.getDate(to); List<PropertySet> results = new ArrayList<PropertySet>(); while (fromDay.compareTo(toDay) <= 0) { for (PropertySet event : getEvents(schedule, fromDay)) { Date startTime = event.getDate(ScheduleEvent.ACT_START_TIME); Date endTime = event.getDate(ScheduleEvent.ACT_END_TIME); if (DateRules.intersects(startTime, endTime, from, to)) { results.add(event); } else if (DateRules.compareTo(startTime, to) >= 0) { break; } } fromDay = DateRules.getDate(fromDay, 1, DateUnits.DAYS); } return results; }
From source file:org.obiba.onyx.core.etl.participant.impl.ParticipantProcessor.java
private boolean isNewAppointmentDateValid(Participant participant) { Date newAppointmentDate = participant.getAppointment().getDate(); if (newAppointmentDate != null && newAppointmentDate.compareTo(new Date()) < 0) return false; return true;// w w w . j av a 2 s. c o m }
From source file:net.facework.core.http.ModAssetServer.java
@Override public void handle(final HttpRequest request, final HttpResponse response, final HttpContext context) throws HttpException, IOException { AbstractHttpEntity body = null;//from www . ja v a 2 s.c o m final String method = request.getRequestLine().getMethod().toUpperCase(Locale.ENGLISH); if (!method.equals("GET") && !method.equals("HEAD") && !method.equals("POST")) { throw new MethodNotSupportedException(method + " method not supported"); } final String url = URLDecoder.decode(request.getRequestLine().getUri()); if (request instanceof HttpEntityEnclosingRequest) { HttpEntity entity = ((HttpEntityEnclosingRequest) request).getEntity(); byte[] entityContent = EntityUtils.toByteArray(entity); Log.d(TAG, "Incoming entity content (bytes): " + entityContent.length); } final String location = "www" + (url.equals("/") ? "/index.htm" : url); response.setStatusCode(HttpStatus.SC_OK); try { Log.i(TAG, "Requested: \"" + url + "\""); // Compares the Last-Modified date header (if present) with the If-Modified-Since date if (request.containsHeader("If-Modified-Since")) { try { Date date = DateUtils.parseDate(request.getHeaders("If-Modified-Since")[0].getValue()); if (date.compareTo(mServer.mLastModified) <= 0) { // The file has not been modified response.setStatusCode(HttpStatus.SC_NOT_MODIFIED); return; } } catch (DateParseException e) { e.printStackTrace(); } } // We determine if the asset is compressed try { AssetFileDescriptor afd = mAssetManager.openFd(location); // The asset is not compressed FileInputStream fis = new FileInputStream(afd.getFileDescriptor()); fis.skip(afd.getStartOffset()); body = new InputStreamEntity(fis, afd.getDeclaredLength()); Log.d(TAG, "Serving uncompressed file " + "www" + url); } catch (FileNotFoundException e) { // The asset may be compressed // AAPT compresses assets so first we need to uncompress them to determine their length InputStream stream = mAssetManager.open(location, AssetManager.ACCESS_STREAMING); ByteArrayOutputStream buffer = new ByteArrayOutputStream(64000); byte[] tmp = new byte[4096]; int length = 0; while ((length = stream.read(tmp)) != -1) buffer.write(tmp, 0, length); body = new InputStreamEntity(new ByteArrayInputStream(buffer.toByteArray()), buffer.size()); stream.close(); Log.d(TAG, "Serving compressed file " + "www" + url); } body.setContentType(getMimeMediaType(url) + "; charset=UTF-8"); response.addHeader("Last-Modified", DateUtils.formatDate(mServer.mLastModified)); } catch (IOException e) { // File does not exist response.setStatusCode(HttpStatus.SC_NOT_FOUND); body = new EntityTemplate(new ContentProducer() { @Override public void writeTo(final OutputStream outstream) throws IOException { OutputStreamWriter writer = new OutputStreamWriter(outstream, "UTF-8"); writer.write("<html><body><h1>"); writer.write("File "); writer.write("www" + url); writer.write(" not found"); writer.write("</h1></body></html>"); writer.flush(); } }); Log.d(TAG, "File " + "www" + url + " not found"); body.setContentType("text/html; charset=UTF-8"); } response.setEntity(body); }
From source file:org.mariotaku.twidere.api.twitter.model.Activity.java
@Override public int compareTo(@NonNull final Activity another) { final Date thisDate = getCreatedAt(), thatDate = another.getCreatedAt(); if (thisDate == null || thatDate == null) return 0; return thisDate.compareTo(thatDate); }
From source file:org.sofun.core.sport.SportsGraphTimeManager.java
/** * Checks sports graph elements (Season, Stage, Round and Game) and * transitioning their status when needed. * //from ww w. j a v a2 s .c o m * @throws Exception */ // XXX DISABLED // @Schedule(minute = "*/5", hour = "*", persistent = false) public void check() throws Exception { if (!available) { return; } else { available = false; } try { // Update scheduled rounds start date for (TournamentRound round : sports.getTournamentRoundsByStatus(TournamentRoundStatus.SCHEDULED)) { Date first = null; for (TournamentGame game : round.getGames()) { Date startDate = game.getStartDate(); if (first == null) { first = startDate; } else if (startDate != null && startDate.compareTo(first) < 0) { first = game.getStartDate(); } } if (first != null && !first.equals(round.getStartDate())) { round.setStartDate(first); log.info("Updated start_date for round w/ uuid=" + round.getUUID()); } } // Update scheduled stages start date for (TournamentStage stage : sports.getTournamentStagesByStatus(TournamentStageStatus.SCHEDULED)) { Date first = null; for (TournamentRound round : stage.getRounds()) { Date startDate = round.getStartDate(); if (first == null) { first = startDate; } else if (startDate != null && startDate.compareTo(first) < 0) { first = round.getStartDate(); } } if (first != null && !first.equals(stage.getStartDate())) { stage.setStartDate(first); log.info("Update start_date for stage w/ uuid=" + stage.getUUID()); } } // Update scheduled seasons start date for (TournamentSeason season : sports.getTournamentSeasonsByStatus(TournamentSeasonStatus.SCHEDULED)) { Date first = null; for (TournamentStage stage : season.getStages()) { Date startDate = stage.getStartDate(); if (first == null) { first = startDate; } else if (startDate != null && startDate.compareTo(first) < 0) { first = stage.getStartDate(); } } if (first != null && !first.equals(season.getStartDate())) { season.setStartDate(first); log.info("Update start_date for season w/ uuid=" + season.getUUID()); } } } finally { available = true; } }
From source file:hudson.plugins.codeviation.RepositoryView.java
public void doGraph(StaplerRequest req, StaplerResponse rsp) throws IOException { CompilationStatus cs = repository.getCompilationStatus(); List<String> tags = new ArrayList<String>(cs.getTags()); // sort tags//w w w . j ava2s . co m Collections.sort(tags, new Comparator<String>() { public int compare(String o1, String o2) { Date date1 = repository.getTagDate(o2); Date date2 = repository.getTagDate(o2); if (date1 != null) { return date1.compareTo(date2); } return 0; } }); // create charts DataSetBuilder<String, String> dsb = new DataSetBuilder<String, String>(); int max = 1; int passed = 0; int failures = 0; for (String tag : tags) { passed = 0; failures = 0; Map<String, Boolean> statuses = cs.getSourceRootCompilationStatuses(tag); for (Map.Entry<String, Boolean> entry : statuses.entrySet()) { if (entry.getValue()) { passed++; } else { failures++; } } dsb.add(passed, "passed", tag); dsb.add(failures, "errors", tag); } max = Math.max(max, passed); max = Math.max(max, failures); ChartUtil.generateGraph(req, rsp, createChart(dsb.build(), max), 400, 200); }
From source file:org.openmrs.module.pihmalawi.page.controller.MastercardPageController.java
public void controller(@RequestParam(value = "patientId", required = false) Patient patient, @RequestParam(value = "headerForm") String headerForm, @RequestParam(value = "flowsheets") String[] flowsheets, @RequestParam(value = "viewOnly", required = false) Boolean viewOnly, @RequestParam(value = "requireEncounter", required = false) Boolean requireEncounter, UiUtils ui, PageModel model, @SpringBean("htmlFormEntryService") HtmlFormEntryService htmlFormEntryService, @SpringBean("formService") FormService formService, @SpringBean("locationService") LocationService locationService, @SpringBean("coreResourceFactory") ResourceFactory resourceFactory, @InjectBeans PatientDomainWrapper patientDomainWrapper, PageRequest pageRequest) { patientDomainWrapper.setPatient(patient); model.addAttribute("patient", patientDomainWrapper); model.addAttribute("headerForm", headerForm); model.addAttribute("flowsheets", flowsheets); model.addAttribute("requireEncounter", (requireEncounter == null || requireEncounter)); Location defaultLocation = null; Integer locationId = pageRequest.getSession().getAttribute(PihMalawiWebConstants.SESSION_LOCATION_ID, Integer.TYPE);//ww w . j av a2 s.com if (locationId != null) { defaultLocation = locationService.getLocation(locationId); } List<Encounter> allEncounters = new ArrayList<Encounter>(); List<String> alerts = new ArrayList<String>(); String headerFormResource = "pihmalawi:htmlforms/" + headerForm + ".xml"; HtmlForm headerHtmlForm = getHtmlFormFromResource(headerFormResource, resourceFactory, formService, htmlFormEntryService); model.addAttribute("headerForm", headerForm); Encounter headerEncounter = null; List<Encounter> headerEncounters = getEncountersForForm(patient, headerHtmlForm); if (headerEncounters.size() > 0) { headerEncounter = headerEncounters.get(headerEncounters.size() - 1); // Most recent if (headerEncounters.size() > 1) { alerts.add("WARNING: More than one " + headerHtmlForm.getName() + " encounters exist for this patient. Displaying the most recent only."); } allEncounters.add(headerEncounter); } model.addAttribute("headerEncounter", headerEncounter); Map<String, HtmlForm> flowsheetForms = new LinkedHashMap<String, HtmlForm>(); Map<String, List<Integer>> flowsheetEncounters = new LinkedHashMap<String, List<Integer>>(); if (flowsheets != null) { for (String flowsheet : flowsheets) { String flowsheetResource = "pihmalawi:htmlforms/" + flowsheet + ".xml"; HtmlForm htmlForm = getHtmlFormFromResource(flowsheetResource, resourceFactory, formService, htmlFormEntryService); flowsheetForms.put(flowsheet, htmlForm); List<Integer> encIds = new ArrayList<Integer>(); List<Encounter> encounters = getEncountersForForm(patient, htmlForm); for (Encounter e : encounters) { encIds.add(e.getEncounterId()); allEncounters.add(e); } flowsheetEncounters.put(flowsheet, encIds); } } model.addAttribute("flowsheetForms", flowsheetForms); model.addAttribute("flowsheetEncounters", flowsheetEncounters); model.addAttribute("alerts", alerts); if (defaultLocation == null) { Date maxDate = null; if (allEncounters.size() > 0) { for (Encounter e : allEncounters) { if (maxDate == null || maxDate.compareTo(e.getEncounterDatetime()) < 0) { maxDate = e.getEncounterDatetime(); defaultLocation = e.getLocation(); } } } } model.addAttribute("defaultLocationId", defaultLocation == null ? null : defaultLocation.getLocationId()); model.addAttribute("viewOnly", viewOnly == Boolean.TRUE); model.addAttribute("returnUrl", ui.pageLink("pihmalawi", "mastercard", SimpleObject.create("patientId", patient.getId(), "headerForm", headerForm, "flowsheets", flowsheets, "viewOnly", viewOnly))); }
From source file:org.openengsb.opencit.ui.web.ProjectDetails.java
@SuppressWarnings("serial") private IModel<List<Report>> createReportsModel() { return new LoadableDetachableModel<List<Report>>() { @Override/*from w w w .jav a 2s. c o m*/ protected List<Report> load() { String projectId = ContextHolder.get().getCurrentContextId(); ReportDomain reportDomain; WiringService ws = osgiUtilsService.getService(WiringService.class); reportDomain = ws.getDomainEndpoint(ReportDomain.class, "report"); List<Report> reports = new ArrayList<Report>(reportDomain.getAllReports(projectId)); Comparator<Report> comparator = Collections.reverseOrder(new Comparator<Report>() { @Override public int compare(Report report1, Report report2) { String name1 = report1.getName(); String name2 = report2.getName(); try { SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss:SSS"); Date date1 = format.parse(name1); Date date2 = format.parse(name2); return date1.compareTo(date2); } catch (ParseException pe) { return name1.compareTo(name2); } } }); Collections.sort(reports, comparator); return reports; } }; }
From source file:org.pentaho.di.www.ge.trans.LogBrowser.java
private void collectAndPushishLog() { HasLogChannelInterface provider = logProvider.getLogChannelProvider(); if (provider != null && !busy.get()) { busy.set(true);/*from w ww . ja va 2s.c o m*/ LogChannelInterface logChannel = provider.getLogChannel(); String parentLogChannelId = logChannel.getLogChannelId(); LoggingRegistry registry = LoggingRegistry.getInstance(); Date registryModDate = registry.getLastModificationTime(); if (childIds == null || lastLogRegistryChange == null || registryModDate.compareTo(lastLogRegistryChange) > 0) { lastLogRegistryChange = registry.getLastModificationTime(); childIds = LoggingRegistry.getInstance().getLogChannelChildren(parentLogChannelId); } // See if we need to log any lines... // int lastNr = KettleLogStore.getLastBufferLineNr(); System.out.println(String.format("LastLogId %d / LastBufferLineNr %d", lastLogId.get(), lastNr)); if (lastNr > lastLogId.get()) { List<KettleLoggingEvent> logLines = KettleLogStore.getLogBufferFromTo(childIds, true, lastLogId.get(), lastNr); System.out.println(String.format("Found %d lines --- LastLogId %d / LastBufferLineNr %d", logLines.size(), lastLogId.get(), lastNr)); // int position = text.getSelection().x; // StringBuffer buffer = new // StringBuffer(text.getText()); StringBuffer stringBuffer = new StringBuffer(10000); int index = lastLogId.get(); String[] logLineArray; List<String[]> logLinesList = new ArrayList<String[]>(); for (int i = 0; i < logLines.size(); i++) { logLineArray = new String[4]; KettleLoggingEvent event = logLines.get(i); String line = logLayout.format(event).trim(); boolean hasError = (event.getLevel() == LogLevel.ERROR); logLineArray[0] = "" + (index++); logLineArray[1] = hasError ? "true" : "false"; Date date = new Date(event.getTimeStamp()); logLineArray[2] = StringEscapeUtils.escapeHtml(date.toString()); String message = null; try { message = event.getMessage().toString(); } catch (IllegalArgumentException e) { LogMessage logMsg = (LogMessage) event.getMessage(); message = logMsg.getSubject() + "-" + logMsg.getMessage(); } logLineArray[3] = StringEscapeUtils.escapeHtml(message); logLinesList.add(logLineArray); lastLogId.set(lastNr); } ge.sendJsonToClient(GETransLogUpdateEncoderDecoder.INSTANCE .encode(new GETransLogUpdate(logLinesList, index - 1))); //ge.broadcast(null, GETransLogUpdateEncoderDecoder.INSTANCE.encode(new GETransLogUpdate(logLinesList))); } busy.set(false); } }
From source file:com.vmware.o11n.plugin.crypto.model.CryptoCertificate.java
/** * * @param date//from w ww . j a v a 2 s . c om * @return */ @VsoMethod(vsoReturnType = "boolean", description = "Is the certificate valid based on a provided date") public boolean isValidOn( @VsoParam(vsoType = "Date", description = "Date to check certificate validity on") Date date) { final Date validAfter = this.cert.getNotBefore(); final Date validBefore = this.cert.getNotAfter(); if (validAfter.compareTo(date) > 0) { //'validAfter' is after date //certificate is not valid yet compared to this date return false; } if (validBefore.compareTo(date) < 0) { // 'validBefore is before date' //certificate is expired compared to this date return false; } // passing both these checks, the cert is valid for this date return true; }