List of usage examples for java.util Date after
public boolean after(Date when)
From source file:com.netspective.commons.validate.rule.DateValueValidationRule.java
public boolean isValid(ValidationContext vc, Value value) { if (!isValidType(vc, value, Date.class)) return false; Date dateValue = (Date) value.getValue(); if (dateValue == null) return true; if (pastOnly || futureOnly) { Date now = new Date(); if (pastOnly && dateValue.after(now)) { vc.addValidationError(value, getPastOnlyDateMessage(), new Object[] { getValueCaption(vc), format(now) }); return false; }/*from w w w. j a v a2 s . co m*/ if (futureOnly && dateValue.before(now)) { vc.addValidationError(value, getFutureOnlyDateMessage(), new Object[] { getValueCaption(vc), format(now) }); return false; } } Date minimumDate = getValueSourceOrDate("Minimum", value, minDateSource, vc, minDate); if (minimumDate != null && dateValue.before(minimumDate)) { vc.addValidationError(value, getPreMinDateDateMessage(), new Object[] { getValueCaption(vc), format(minimumDate) }); return false; } Date maximumDate = getValueSourceOrDate("Maximum", value, maxDateSource, vc, maxDate); if (maximumDate != null && dateValue.after(maximumDate)) { vc.addValidationError(value, getPostMaxDateMessage(), new Object[] { getValueCaption(vc), format(maximumDate) }); return false; } return true; }
From source file:gov.nih.nci.ncicb.tcga.dcc.dam.dao.usage.UsageLoggerFileImpl.java
/** * If start date and end date are null, returns all sessions. If start date is null, returns all sessions from * first recorded until end date. If end date is null, returns all sessions since start date. * * @return a List of all UsageSessions that have been recorded between start and end date * @throws UsageLoggerException if there is an error * @param startDate the start date, or null * @param endDate the end date, or null/*from w w w . j av a2 s . co m*/ */ public List<UsageSession> getAllSessionsForDates(Date startDate, Date endDate) throws UsageLoggerException { List<UsageSession> sessions = new ArrayList<UsageSession>(); BufferedReader logFile = null; try { //noinspection IOResourceOpenedButNotSafelyClosed logFile = new BufferedReader(new FileReader(getFile())); String line = logFile.readLine(); Pattern actionPattern = Pattern.compile("^\\[(.+)\\](.+)=(.*)@(.+)$"); UsageSession currentSession = null; while (line != null) { Matcher m = actionPattern.matcher(line); if (m.matches()) { String sessionId = m.group(1); String actionName = m.group(2); String value = m.group(3); String dateString = m.group(4); Date date = getDateFormat().parse(dateString); boolean include = true; if (startDate != null && date.before(startDate)) { include = false; } if (endDate != null && date.after(startDate)) { include = false; } if (include) { if (currentSession == null || !sessionId.equals(currentSession.sessionKey)) { currentSession = new UsageSession(); sessions.add(currentSession); } UsageSessionAction action = new UsageSessionAction(); action.name = actionName; action.value = value; action.actionTime = date; currentSession.actions.add(action); } } line = logFile.readLine(); } } catch (FileNotFoundException e) { throw new UsageLoggerException("Could not open usage log", e); } catch (IOException e) { throw new UsageLoggerException("Error reading log", e); } catch (ParseException e) { throw new UsageLoggerException("Error parsing date in log", e); } finally { IOUtils.closeQuietly(logFile); } return sessions; }
From source file:com.ge.predix.uaa.token.lib.FastTokenServices.java
private void verifyTimeWindow(final Map<String, Object> claims) { Date iatDate = getIatDate(claims); Date expDate = getExpDate(claims); Date currentDate = new Date(); if (iatDate != null && iatDate.after(currentDate)) { throw new InvalidTokenException(String.format( "Token validity window is in the future. Token is issued at [%s]. Current date is [%s]", iatDate.toString(), currentDate.toString())); }//from w w w . j a v a2 s .c o m if (expDate != null && expDate.before(currentDate)) { throw new InvalidTokenException( String.format("Token is expired. Expiration date is [%s]. Current date is [%s]", expDate.toString(), currentDate.toString())); } }
From source file:com.nridge.connector.fs.con_fs.core.FileCrawler.java
/** * Invoked for a file in a directory.// w w w . ja v a 2s . c o m * Unless overridden, this method returns {@link java.nio.file.FileVisitResult#CONTINUE * CONTINUE}. * * @param aPath Path instance. * @param aFileAttributes File attribute instance. */ @Override public FileVisitResult visitFile(Path aPath, BasicFileAttributes aFileAttributes) throws IOException { Logger appLogger = mAppMgr.getLogger(this, "visitFile"); String pathFileName = aPath.toAbsolutePath().toString(); if (mCrawlIgnore.isMatchedNormalized(pathFileName)) appLogger.debug(String.format("Ignoring File: %s", pathFileName)); else { File fsFile = aPath.toFile(); if ((fsFile.canRead()) && (mBag != null)) { String crawlType = mCrawlQueue.getCrawlType(); if (StringUtils.equals(crawlType, Connector.CRAWL_TYPE_INCREMENTAL)) { String docId = generateDocumentId(aPath); boolean docExistsInIndex = documentExistsInIndex(docId); if (docExistsInIndex) { Date incDate = mCrawlQueue.getCrawlLastModified(); FileTime lastModifiedTime = aFileAttributes.lastModifiedTime(); Date lmDate = new Date(lastModifiedTime.toMillis()); if (lmDate.after(incDate)) processFile(aPath, aFileAttributes); } else processFile(aPath, aFileAttributes); } else processFile(aPath, aFileAttributes); } else appLogger.warn(String.format("Access Failed: %s", pathFileName)); } if (mAppMgr.isAlive()) return FileVisitResult.CONTINUE; else return FileVisitResult.TERMINATE; }
From source file:gtu.jpa.hibernate.Rcdf002eDBUI.java
private JButton getJButton1x() { if (porcessDoAllBtn == null) { porcessDoAllBtn = new JButton(); porcessDoAllBtn.setText("\u6392\u7a0b\u57f7\u884c"); porcessDoAllBtn.setPreferredSize(new java.awt.Dimension(80, 54)); porcessDoAllBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { try { String dateTime = processDoAllText.getText(); Validate.notBlank(dateTime, ""); Validate.isTrue(StringUtils.isNumeric(dateTime), ""); Validate.isTrue(StringUtils.isNumeric(dateTime), ""); Validate.isTrue(dateTime.length() == 14, "14"); SimpleDateFormat sdf = new SimpleDateFormat(); sdf.applyPattern("yyyyMMddHHmmss"); Date newDate = sdf.parse(dateTime); Validate.isTrue(newDate.after(new Date()), "??"); setTitle(DateFormatUtils.format(newDate, "yyyy/MM/dd HH:mm:ss") + "?..."); Timer timer = new Timer(); timer.schedule(new TimerTask() { @Override public void run() { oneClickDoAll(); }//from w ww. jav a 2 s. com }, newDate); } catch (Exception ex) { JCommonUtil.handleException(ex); setTitle("......" + ex.getMessage()); } } }); } return porcessDoAllBtn; }
From source file:DataPreProcess.ConvertedTrace.java
private void construct_Matrix_Phase() { long time_shift = 0; Date cali_st = null;//from w w w . j a v a 2 s .c o m Date pt_st = null; Date pt_ed = null; Date pri_st = null; Date pri_ed = null; Date sec_st = null; Date sec_ed = null; Date pst_sec_st = null; Date pst_sec_ed = null; // Date pd_st = null; // Date pd_ed = null; //Get all the date for (Phase ph : p) { if (pt.contains(ph.phaseName)) { cali_st = ph.start; pt_st = ph.start; pt_ed = ph.end; } if (pre_pri.contains(ph.phaseName)) { //merge preprimary to patient arrival pt_ed = ph.end; } if (pri.contains(ph.phaseName)) { pt_ed = ph.start; pri_st = ph.start; pri_ed = ph.end; } if (sec.contains(ph.phaseName)) { pri_ed = ph.start; sec_st = ph.start; sec_ed = ph.end; } if (pst_sec.contains(ph.phaseName)) { sec_ed = ph.start; pst_sec_st = ph.start; pst_sec_ed = ph.end; } // if (pd.contains(ph.phaseName)) { // pd_st = ph.start; // pd_ed = ph.end; // } } if (cali_st != null) { time_shift = cali_st.getTime(); } // Calibrate start time pt_st = new Date(pt_st.getTime() - time_shift); pt_ed = new Date(pt_ed.getTime() - time_shift); pri_st = new Date(pri_st.getTime() - time_shift); pri_ed = new Date(pri_ed.getTime() - time_shift); sec_st = new Date(sec_st.getTime() - time_shift); sec_ed = new Date(sec_ed.getTime() - time_shift); pst_sec_st = new Date(pst_sec_st.getTime() - time_shift); pst_sec_ed = new Date(pst_sec_ed.getTime() - time_shift); phase_percentage[0] = (double) (pt_ed.getTime() - pt_st.getTime()); phase_percentage[1] = (double) (pri_ed.getTime() - pri_st.getTime()); phase_percentage[2] = (double) (sec_ed.getTime() - sec_st.getTime()); phase_percentage[3] = (double) (pst_sec_ed.getTime() - pst_sec_st.getTime()); for (Activity ac : activities) { int start_index = 0; int end_index = 0; Date ac_st = ac.get_startTime(); Date ac_end = ac.get_endTime(); if (ac_st.after(pst_sec_ed)) { start_index = Length - 1; //wrong situation, start after end } else if (ac_st.after(pst_sec_st) || ac_st.equals(pst_sec_st)) { start_index = pt_arrival_length + Primary_length + Secondary_length + (int) ((double) (ac_st.getTime() - pst_sec_st.getTime()) / phase_percentage[3] * Pst_secondary_length); } else if (ac_st.after(sec_st) || ac_st.equals(sec_st)) { start_index = pt_arrival_length + Primary_length + (int) ((double) (ac_st.getTime() - sec_st.getTime()) / phase_percentage[2] * Secondary_length); } else if (ac_st.after(pri_st) || ac_st.equals(pri_st)) { start_index = pt_arrival_length + (int) ((double) (ac_st.getTime() - pri_st.getTime()) / phase_percentage[1] * Primary_length); } else if (ac_st.after(pt_st) || ac_st.equals(pt_st)) { start_index = (int) ((double) (ac_st.getTime() - pt_st.getTime()) / phase_percentage[0] * pt_arrival_length); } else { start_index = 0; } if (ac_end.before(pt_st)) { end_index = 0; //wrong situation, end before start } else if (ac_end.before(pt_ed) || ac_end.equals(pt_ed)) { end_index = pt_arrival_length - (int) ((double) (pt_ed.getTime() - ac_end.getTime()) / phase_percentage[0] * pt_arrival_length); } else if (ac_end.before(pri_ed) || ac_end.equals(pri_ed)) { end_index = pt_arrival_length + Primary_length - (int) ((double) (pri_ed.getTime() - ac_end.getTime()) / phase_percentage[1] * Primary_length); } else if (ac_end.before(sec_ed) || ac_end.equals(sec_ed)) { end_index = pt_arrival_length + Primary_length + Secondary_length - (int) ((double) (sec_ed.getTime() - ac_end.getTime()) / phase_percentage[2] * Secondary_length); } else if (ac_end.before(pst_sec_ed) || ac_end.equals(pst_sec_ed)) { end_index = pt_arrival_length + Primary_length + Secondary_length + Pst_secondary_length - (int) ((double) (pst_sec_ed.getTime() - ac_end.getTime()) / phase_percentage[3] * Pst_secondary_length); } else { end_index = Length; //Patient departure, not included } end_index = end_index >= Length ? Length : end_index; // Avoid out of boundry //Set corresponding cells to 1 int row_index = Activity_set.indexOf(ac.get_name()); try { if (end_index < start_index) { System.out.println("Activity: " + ac.get_name() + " Index incorrect: " + " st:" + start_index + " ed:" + end_index); } else { if (end_index == start_index && end_index < Length) { end_index++; } fill_activity(row_index, start_index, end_index); } } catch (ArrayIndexOutOfBoundsException e) { System.out.println("Activity: " + ac.get_name() + " st:" + start_index + " ed:" + end_index + " OutOfBounds!!!"); } normalize_matrix_row(); } double duration = pst_sec_ed.getTime() - pt_st.getTime(); phase_percentage[0] /= duration; phase_percentage[1] /= duration; phase_percentage[2] /= duration; phase_percentage[3] /= duration; }
From source file:com.emuneee.nctrafficcams.tasks.GetLatestCameras.java
private Boolean isUpdateNeeded(String updateDatetime) throws ParseException { Boolean updateNeeded = null;/* w w w.ja va 2s . c om*/ String storedUpdateDatetime = PreferenceManager.getDefaultSharedPreferences(mContext) .getString(Constants.PREF_LAST_UPDATE_DATETIME, null); if (storedUpdateDatetime == null) { updateNeeded = null; } else { Date storedUpdate = ConversionUtils.parseDate(storedUpdateDatetime, ConversionUtils.ISO_DATE_FORMAT); Date update = ConversionUtils.parseDate(updateDatetime, ConversionUtils.ISO_DATE_FORMAT); Log.d(TAG, "Stored update datetime: " + storedUpdate); Log.d(TAG, "Server Update datetime: " + update); updateNeeded = update.after(storedUpdate); } return updateNeeded; }
From source file:dk.dma.ais.tracker.scenarioTracker.ScenarioTracker.java
/** * Get the Date of the last update in this scenario. * @return// w w w. java 2 s . c o m */ public Date scenarioEnd() { Date scenarioEnd = null; Set<Map.Entry<Integer, Target>> entries = targets.entrySet(); Iterator<Map.Entry<Integer, Target>> i = entries.iterator(); while (i.hasNext()) { Target target = i.next().getValue(); try { Date targetFirstUpdate = target.positionReports.lastKey(); if (scenarioEnd == null || targetFirstUpdate.after(scenarioEnd)) { scenarioEnd = targetFirstUpdate; } } catch (NoSuchElementException e) { } } return scenarioEnd; }
From source file:be.fedict.trust.service.bean.DownloaderMDB.java
private void processColdStartMessage(ColdStartMessage coldStartMessage) { if (null == coldStartMessage) { return;/* w ww . j av a 2s. c o m*/ } String crlUrl = coldStartMessage.getCrlUrl(); String certUrl = coldStartMessage.getCertUrl(); LOG.debug("cold start CRL URL: " + crlUrl); LOG.debug("cold start CA URL: " + certUrl); File crlFile = download(crlUrl); File certFile = download(certUrl); // parsing CertificateFactory certificateFactory; try { certificateFactory = CertificateFactory.getInstance("X.509"); } catch (CertificateException e) { LOG.debug("certificate factory error: " + e.getMessage(), e); crlFile.delete(); certFile.delete(); return; } X509Certificate certificate = null; try { certificate = (X509Certificate) certificateFactory.generateCertificate(new FileInputStream(certFile)); } catch (Exception e) { LOG.debug("error DER-parsing certificate"); try { PEMReader pemReader = new PEMReader(new FileReader(certFile)); certificate = (X509Certificate) pemReader.readObject(); pemReader.close(); } catch (Exception e2) { retry("error PEM-parsing certificate", e, certFile, crlFile); } } certFile.delete(); X509CRL crl = null; try { crl = (X509CRL) certificateFactory.generateCRL(new FileInputStream(crlFile)); } catch (Exception e) { retry("error parsing CRL", e, crlFile); } // first check whether the two correspond try { crl.verify(certificate.getPublicKey()); } catch (Exception e) { LOG.error("no correspondence between CRL and CA"); LOG.error("CRL issuer: " + crl.getIssuerX500Principal()); LOG.debug("CA subject: " + certificate.getSubjectX500Principal()); crlFile.delete(); return; } LOG.debug("CRL matches CA: " + certificate.getSubjectX500Principal()); // skip expired CAs Date now = new Date(); Date notAfter = certificate.getNotAfter(); if (now.after(notAfter)) { LOG.warn("CA already expired: " + certificate.getSubjectX500Principal()); crlFile.delete(); return; } // create database entitities CertificateAuthorityEntity certificateAuthority = this.certificateAuthorityDAO .findCertificateAuthority(certificate); if (null != certificateAuthority) { LOG.debug("CA already in cache: " + certificate.getSubjectX500Principal()); crlFile.delete(); return; } /* * Lookup Root CA's trust point via parent certificates' CA entity. */ LOG.debug( "Lookup Root CA's trust point via parent certificates' CA entity - Don't have Issuer's Serial Number??"); String parentIssuerName = certificate.getIssuerX500Principal().toString(); CertificateAuthorityEntity parentCertificateAuthority = this.certificateAuthorityDAO .findCertificateAuthority(parentIssuerName); if (null == parentCertificateAuthority) { LOG.error("CA not found for " + parentIssuerName + " ?!"); crlFile.delete(); return; } LOG.debug("parent CA: " + parentCertificateAuthority.getName()); TrustPointEntity parentTrustPoint = parentCertificateAuthority.getTrustPoint(); if (null != parentTrustPoint) { LOG.debug("trust point parent: " + parentTrustPoint.getName()); LOG.debug("previous trust point fire data: " + parentTrustPoint.getFireDate()); } else { LOG.debug("no parent trust point"); } // create new CA certificateAuthority = this.certificateAuthorityDAO.addCertificateAuthority(certificate, crlUrl); // prepare harvesting certificateAuthority.setTrustPoint(parentTrustPoint); certificateAuthority.setStatus(Status.PROCESSING); if (null != certificateAuthority.getTrustPoint() && null == certificateAuthority.getTrustPoint().getFireDate()) { try { this.schedulingService.startTimer(certificateAuthority.getTrustPoint()); } catch (InvalidCronExpressionException e) { LOG.error("invalid cron expression"); crlFile.delete(); return; } } // notify harvester String crlFilePath = crlFile.getAbsolutePath(); try { this.notificationService.notifyHarvester(certificate.getSubjectX500Principal().toString(), crlFilePath, false); } catch (JMSException e) { crlFile.delete(); throw new RuntimeException(e); } }
From source file:org.motechproject.server.service.IPTScheduleTest.java
public void testCreateExpected() { Date date = new Date(); Patient patient = new Patient(1); Capture<Date> minDateCapture = new Capture<Date>(); Capture<Date> dueDateCapture = new Capture<Date>(); Capture<Date> lateDateCapture = new Capture<Date>(); List<Obs> obsList = new ArrayList<Obs>(); List<ExpectedObs> expectedObsList = new ArrayList<ExpectedObs>(); Date pregnancyDate = new Date(); expect(registrarBean.getActivePregnancyDueDate(patient.getPatientId())).andReturn(pregnancyDate); expect(registrarBean.getObs(eq(patient), eq(iptSchedule.getConceptName()), eq(iptSchedule.getValueConceptName()), (Date) anyObject())).andReturn(obsList); expect(registrarBean.getExpectedObs(patient, iptSchedule.getName())).andReturn(expectedObsList); expect(registrarBean.createExpectedObs(eq(patient), eq(iptSchedule.getConceptName()), eq(iptSchedule.getValueConceptName()), eq(ipt1Event.getNumber()), capture(minDateCapture), capture(dueDateCapture), capture(lateDateCapture), (Date) anyObject(), eq(ipt1Event.getName()), eq(iptSchedule.getName()))).andReturn(new ExpectedObs()); replay(registrarBean);//from w w w .j a va2s . c o m iptSchedule.updateSchedule(patient, date); verify(registrarBean); Date minDate = minDateCapture.getValue(); Date dueDate = dueDateCapture.getValue(); Date lateDate = lateDateCapture.getValue(); assertNotNull("Min date is null", minDate); assertNotNull("Due date is null", dueDate); assertNotNull("Late date is null", lateDate); assertTrue("Min date is not before due date", minDate.before(dueDate)); assertTrue("Late date is not after due date", lateDate.after(dueDate)); }