List of usage examples for java.util Date after
public boolean after(Date when)
From source file:com.linuxbox.enkive.filter.EnkiveFilter.java
private boolean filterDate(String value) throws java.text.ParseException { boolean matched = false; Date dateValue = dateFormatter.parse(value); Date dateFilterValue = dateFormatter.parse(filterValue); switch (filterComparator) { case FilterComparator.MATCHES: if (dateValue.equals(dateFilterValue)) matched = true;/*from ww w .j a v a2 s . c om*/ break; case FilterComparator.DOES_NOT_MATCH: if (!dateValue.equals(dateFilterValue)) matched = true; break; case FilterComparator.IS_GREATER_THAN: if (dateValue.after(dateFilterValue)) matched = true; break; case FilterComparator.IS_LESS_THAN: if (dateValue.before(dateFilterValue)) matched = true; break; } return matched; }
From source file:net.di2e.ecdr.commons.query.rest.parsers.BasicQueryParser.java
protected TemporalCriteria createTemporalCriteria(String start, String end, String type) throws UnsupportedQueryException { TemporalCriteria temporalCriteria = null; if (StringUtils.isNotBlank(start) || StringUtils.isNotBlank(end)) { Date startDate = parseDate(start); Date endDate = parseDate(end); if (startDate != null && endDate != null) { if (startDate.after(endDate)) { throw new UnsupportedQueryException( "Start date value [" + startDate + "] cannot be after endDate [" + endDate + "]"); }/* w w w .j a v a2 s . c o m*/ } String dateType = null; LOGGER.debug("Getting date type name for type [{}]", type); if (StringUtils.isNotBlank(type)) { if (DATETYPE_MAP.containsKey(type)) { dateType = DATETYPE_MAP.get(type); LOGGER.debug( "Date type value received in map for request value [{}], setting internal query value to [{}]", type, dateType); } else { String message = "Date type value not found in map for type [" + type + "], defaulting internal query value to [" + dateType + "]"; LOGGER.warn(message); throw new UnsupportedQueryException(message); } } else { dateType = DATETYPE_MAP.get(this.defaultDateType); LOGGER.debug( "Date type value was not specified in request, defaulting internal query value to [{}]", dateType); } temporalCriteria = new TemporalCriteria(startDate, endDate, dateType); } return temporalCriteria; }
From source file:org.motechproject.server.service.BCGScheduleTest.java
public void testCreateExpected() { Date date = new Date(); Calendar calendar = Calendar.getInstance(); calendar.setTime(date);/*from www . ja v a2 s. c o m*/ calendar.add(Calendar.MONTH, -2); // age is 2 months Patient patient = new Patient(); patient.setBirthdate(calendar.getTime()); patient.setDateCreated(calendar.getTime()); Capture<Date> minDateCapture = new Capture<Date>(); Capture<Date> dueDateCapture = new Capture<Date>(); Capture<Date> lateDateCapture = new Capture<Date>(); Capture<Date> maxDateCapture = new Capture<Date>(); List<Obs> obsList = new ArrayList<Obs>(); List<ExpectedObs> expectedObsList = new ArrayList<ExpectedObs>(); expect(registrarBean.getObs(patient, bcgSchedule.getConceptName(), bcgSchedule.getValueConceptName(), patient.getBirthdate())).andReturn(obsList); expect(registrarBean.getExpectedObs(patient, bcgSchedule.getName())).andReturn(expectedObsList); expect(registrarBean.createExpectedObs(eq(patient), eq(bcgSchedule.getConceptName()), eq(bcgSchedule.getValueConceptName()), eq(bcgEvent.getNumber()), capture(minDateCapture), capture(dueDateCapture), capture(lateDateCapture), capture(maxDateCapture), eq(bcgEvent.getName()), eq(bcgSchedule.getName()))).andReturn(new ExpectedObs()); calendar.set(2010, 03, 10); expect(registrarBean.getChildRegistrationDate()).andReturn(calendar.getTime()); calendar.set(2011, 03, 10); Encounter encounter = new Encounter(); encounter.setEncounterDatetime(calendar.getTime()); expect(registrarBean.getEncounters(patient, MotechConstants.ENCOUNTER_TYPE_PATIENTREGVISIT, patient.getBirthdate())).andReturn(Arrays.asList(encounter)); replay(registrarBean); bcgSchedule.updateSchedule(patient, date); verify(registrarBean); Date minDate = minDateCapture.getValue(); Date dueDate = dueDateCapture.getValue(); Date lateDate = lateDateCapture.getValue(); Date maxDate = maxDateCapture.getValue(); assertNotNull("Min date is null", minDate); assertNotNull("Due date is null", dueDate); assertNotNull("Late date is null", lateDate); assertNotNull("Max date is null", maxDate); assertEquals("Due date not equal min date", minDate, dueDate); assertTrue("Late date is not after due date", lateDate.after(dueDate)); assertTrue("Max date is not after late date", maxDate.after(lateDate)); }
From source file:com.iorga.webappwatcher.analyzer.model.session.DurationPerPrincipalStats.java
private TimeSlice findOrCreateTimeSlice(final Date date, final long timeSliceDurationMillis) { // will binary search the time slice int low = 0;// w ww . j ava2 s. com int high = timeSlices.size() - 1; int mid; while (low <= high) { mid = (low + high) / 2; final TimeSlice midTimeSlice = timeSlices.get(mid); if (date.after(midTimeSlice.endDate)) { low = mid + 1; } else if (date.before(midTimeSlice.startDate)) { high = mid - 1; } else { return midTimeSlice; } } // not found in the existing time slices, must create a new one return createNewTimeSlice(date, timeSliceDurationMillis); }
From source file:com.stimulus.archiva.domain.Volumes.java
private boolean shouldRotateActive(Volume activeVolume, AutoCreateEvent event) { Date baseDate = activeVolume.getCreatedDate(); // Check volumes from last to first for (ListIterator<Volume> li = getVolumes().listIterator(getVolumes().size()); li.hasPrevious();) { Volume vol = li.previous();/*w ww .j a v a 2 s . c o m*/ if (vol.getStatus() != Status.CLOSED) { // Skip unclosed volumes continue; } if (vol.enoughDiskSpace() != Space.RUNOUT) { // Scheduled close baseDate = vol.getClosedDate(); break; } else { // Unscheduled baseDate = vol.getCreatedDate(); } } Date now = new Date(); Calendar dateToClose = Calendar.getInstance(); dateToClose.setTime(baseDate); dateToClose.add(event.intervalField, event.intervalAmount); return now.after(dateToClose.getTime()); }
From source file:com.emc.vipr.sync.target.FilesystemTarget.java
@Override public void filter(SyncObject obj) { File destFile = createFile(targetRoot.getPath(), obj.getRelativePath()); obj.setTargetIdentifier(destFile.getPath()); LogMF.debug(l4j, "Writing {0} to {1}", obj.getSourceIdentifier(), destFile); Date mtime = obj.getMetadata().getModificationTime(); // make sure parent directory exists mkdirs(destFile.getParentFile());// www . java 2 s. c o m if (obj.isDirectory()) { synchronized (this) { if (!destFile.exists() && !destFile.mkdir()) throw new RuntimeException("Failed to create directory " + destFile); } } else { // If newer or forced, copy the file data if (force || mtime == null || !destFile.exists() || mtime.after(new Date(destFile.lastModified()))) { copyData(obj, destFile); } else { LogMF.debug(l4j, "No change in content timestamps for {0}", obj.getSourceIdentifier()); } } // encapsulate metadata from source system if (!ignoreMetadata) { File metaFile = createFile(null, SyncMetadata.getMetaPath(destFile.getPath(), destFile.isDirectory())); File metaDir = metaFile.getParentFile(); Date ctime = null; if (obj.getMetadata() instanceof AtmosMetadata) { // check for ctime in system meta UserMetadata m = ((AtmosMetadata) obj.getMetadata()).getSystemMetadata().get("ctime"); if (m != null) ctime = Iso8601Util.parse(m.getValue()); } if (ctime == null) ctime = mtime; // use mtime if there is no ctime // create metadata directory if it doesn't already exist synchronized (this) { if (!metaDir.exists() && !metaDir.mkdir()) throw new RuntimeException("Failed to create metadata directory " + metaDir); } // if *ctime* is newer or forced, write the metadata file if (force || ctime == null || !metaFile.exists() || ctime.after(new Date(metaFile.lastModified()))) { try { String metaJson = obj.getMetadata().toJson(); copyData(new ByteArrayInputStream(metaJson.getBytes("UTF-8")), createOutputStream(metaFile)); if (ctime != null) { // Set the metadata file mtime to the source ctime (i.e. this // metadata file's content is modified at the same // time as the source's metadata modification time) metaFile.setLastModified(ctime.getTime()); } } catch (IOException e) { throw new RuntimeException("Failed to write metadata to: " + metaFile, e); } } else { LogMF.debug(l4j, "No change in metadata for {0}", obj.getSourceIdentifier()); } } FilesystemUtil.applyFilesystemMetadata(destFile, obj.getMetadata(), includeAcl); }
From source file:eu.ggnet.dwoss.misc.op.listings.SalesListingProducerOperation.java
@Override public FileJacket generateAllSalesListing() { SubMonitor m = monitorFactory.newSubMonitor("All List", 5); m.message("loading Units"); m.start();/*from www .ja va2 s . c o m*/ List<StockUnit> stockUnits = new StockUnitEao(stockEm).findByNoLogicTransaction(); List<UniqueUnit> uniqueUnits = new UniqueUnitEao(uuEm).findByIds(toUniqueUnitIds(stockUnits)); m.worked(3, "preparing Units"); List<Object[]> retailers = new ArrayList<>(stockUnits.size()); List<Object[]> customers = new ArrayList<>(stockUnits.size()); for (Map.Entry<UniqueUnit, StockUnit> entry : toSortedMap(uniqueUnits, stockUnits, new UniqueUnitComparator()).entrySet()) { UniqueUnit uu = entry.getKey(); StockUnit su = entry.getValue(); Product p = uu.getProduct(); Date firstPriced = null; for (PriceHistory priceHistory : uu.getPriceHistory()) { if (firstPriced == null || firstPriced.after(priceHistory.getDate())) firstPriced = priceHistory.getDate(); } String source = "Automatisch"; if (p != null && p.getFlags().contains(Product.Flag.PRICE_FIXED)) source = "Manuell (Artikel)"; else if (uu.getFlags().contains(UniqueUnit.Flag.PRICE_FIXED)) source = "Manuell (Gert)"; Object[] row = { uu.getRefurbishId(), (p == null ? null : p.getPartNo()), (p == null ? null : p.getGroup().getNote()), (p == null ? null : p.getTradeName().getName()), (p == null ? null : p.getName()), (p == null ? null : p.getDescription()), uu.getWarranty().getName(), uu.getWarrentyValid(), UniqueUnitFormater.toSingleLineAccessories(uu), uu.getCondition().getNote(), UniqueUnitFormater.toSingleLineComment(uu), uu.getPrice(PriceType.RETAILER), uu.getPrice(PriceType.CUSTOMER), (!uu.hasPrice(PriceType.CUSTOMER) ? null : MathUtil.roundedApply(uu.getPrice(PriceType.CUSTOMER), GlobalConfig.TAX, 0)), (su.getStock() == null ? su.getTransaction() : su.getStock().getName()), uu.getMfgDate(), uu.getInputDate(), firstPriced, source }; if (uu.getSalesChannel() == SalesChannel.CUSTOMER && uu.hasPrice(PriceType.CUSTOMER)) customers.add(row); else if (uu.getSalesChannel() == SalesChannel.RETAILER && (uu.hasPrice(PriceType.CUSTOMER) || uu.hasPrice(PriceType.RETAILER))) retailers.add(row); } m.worked(1, "creating File, Endkundengerte: " + customers.size() + ", Hndlergerte: " + retailers.size()); STable consumerTable = new STable(); consumerTable .setTableFormat(new CFormat(CENTER, TOP, new CBorder(Color.GRAY, CBorder.LineStyle.THIN), true)); consumerTable.setHeadlineFormat( new CFormat(CFormat.FontStyle.BOLD, Color.BLACK, Color.LIGHT_GRAY, CENTER, MIDDLE)); consumerTable.setRowHeight(1000); consumerTable.add(new STableColumn("SopoNr", 12)); consumerTable.add(new STableColumn("ArtikelNr", 15)); consumerTable.add(new STableColumn("Warengruppe", 18)); consumerTable.add(new STableColumn("Hersteller", 15)); consumerTable.add(new STableColumn("Bezeichnung", 30)); consumerTable.add(new STableColumn("Beschreibung", 60, LFT)); consumerTable.add(new STableColumn("Garantie", 18, LFT)); consumerTable.add(new STableColumn("Garantie bis", 18, new CFormat(Representation.SHORT_DATE))); consumerTable.add(new STableColumn("Zubehr", 30, LFT)); consumerTable.add(new STableColumn("optische Bewertung", 25)); consumerTable.add(new STableColumn("Bemerkung", 50, LFT)); consumerTable.add(new STableColumn("Hndler", 15, EURO)); consumerTable.add(new STableColumn("Endkunde", 15, EURO)); consumerTable.add(new STableColumn("E.inc.Mwst", 15, EURO)); consumerTable.add(new STableColumn("Lager", 18)); consumerTable.add(new STableColumn("Mfg Datum", 18, new CFormat(Representation.SHORT_DATE))); consumerTable.add(new STableColumn("Aufnahme Datum", 18, new CFormat(Representation.SHORT_DATE))); consumerTable.add(new STableColumn("Erstmalig Bepreist", 18, new CFormat(Representation.SHORT_DATE))); consumerTable.add(new STableColumn("Preis Quelle", 18)); consumerTable.setModel(new STableModelList(customers)); STable retailerTable = new STable(consumerTable); retailerTable.setModel(new STableModelList(retailers)); CCalcDocument cdoc = new TempCalcDocument(); cdoc.add(new CSheet("Endkunde", consumerTable)); cdoc.add(new CSheet("Hndler", retailerTable)); FileJacket fj = new FileJacket("All", ".xls", LucidCalc.createWriter(LucidCalc.Backend.XLS).write(cdoc)); m.finish(); return fj; }
From source file:edu.cmu.cs.lti.discoursedb.io.mturk.converter.MturkConverterService.java
/** * Maps a discussion forum message to DiscourseDB * /*from w ww. java 2s. c o m*/ * @param subj the message subject * @param text the message text * @param forum_uid * @param thread_uid * @param group * @param team * @param author the message author (discoursedb user id number) * @param reply_to the discoursed_db contribution this replies to (or zero) * @param discourse_name * @param dataset_name * @param source_file_name * @param source_column_name * @param source_unique_index * * @returns the contribution Id written to the database */ public Long mapDiscussionPost(String subj, String text, String forum_uid, String thread_uid, String group, String team, long author, String when, long reply_to, String discourse_name, String dataset_name, String source_file_name, String source_column_name, String source_unique_index) { Discourse curDiscourse = discourseService.createOrGetDiscourse(discourse_name); User proxyUser = getProxyUser(author); ContributionTypes mappedType = null; if (reply_to == 0L) { mappedType = ContributionTypes.POST; } else { mappedType = ContributionTypes.RESPONSE; } log.trace("Create Content entity"); Content curContent = contentService.createContent(); curContent.setText(text); curContent.setTitle(subj); curContent.setAuthor(proxyUser); dataSourceService.addSource(curContent, new DataSourceInstance(source_unique_index, source_file_name + "#" + source_column_name + "(content)", DataSourceTypes.BAZAAR, dataset_name)); log.trace("Create Contribution entity"); Contribution curContribution = contributionService.createTypedContribution(mappedType); curContribution.setCurrentRevision(curContent); curContribution.setFirstRevision(curContent); dataSourceService.addSource(curContribution, new DataSourceInstance(source_unique_index, source_file_name + "#" + source_column_name + "(contribution)", DataSourceTypes.BAZAAR, dataset_name)); discussion_source2ddb.put(Long.valueOf(source_unique_index), curContribution.getId()); DiscoursePart thread = discoursepartService.createOrGetDiscoursePartByDataSource(curDiscourse, thread_uid, source_file_name + "#thread_uid", DataSourceTypes.BAZAAR, dataset_name, DiscoursePartTypes.THREAD); DiscoursePart forum = discoursepartService.createOrGetDiscoursePartByDataSource(curDiscourse, forum_uid, source_file_name + "#forum_uid", DataSourceTypes.BAZAAR, dataset_name, DiscoursePartTypes.FORUM); discoursepartService.createDiscoursePartRelation(forum, thread, DiscoursePartRelationTypes.SUBPART); if (!forum.getName().equals("dummy_name") && !forum.getName().equals(forumDpName(forum_uid))) { System.out.println("Changing forum " + forum_uid + " name from " + forum.getName() + " to " + forumDpName(forum_uid) + " in post " + source_unique_index); } forum.setName(forumDpName(forum_uid)); if (reply_to == 0) { if (!thread.getName().equals("dummy_name") && !thread.getName().equals(threadDpName(forum_uid, subj))) { System.out.println("Changing thread " + thread_uid + " name from " + thread.getName() + " to " + threadDpName(forum_uid, subj) + " in post " + source_unique_index); } thread.setName(threadDpName(forum_uid, subj)); } else { Contribution prior = getProxyContributionBySourceId(reply_to); if (prior == null) { System.out.println("What is this in reply to? Post # " + source_unique_index + "Replies to " + reply_to + " text starts with " + text); } else { contributionService.createDiscourseRelation(prior, curContribution, DiscourseRelationTypes.REPLY); } } if (reply_to == 0) { if (group != null) { DiscoursePart grp_dp = discoursepartService.createOrGetTypedDiscoursePart(curDiscourse, groupDpName(group), DiscoursePartTypes.GROUP); discoursepartService.createDiscoursePartRelation(grp_dp, forum, DiscoursePartRelationTypes.SUBPART); //discourses = grp_dp.getDiscourseToDiscourseParts(). } if (team != null && group != null) { DiscoursePart team_dp = discoursepartService.createOrGetTypedDiscoursePart(curDiscourse, teamDpName(group, team), DiscoursePartTypes.TEAM); discoursepartService.createDiscoursePartRelation(team_dp, thread, DiscoursePartRelationTypes.SUBPART); } } discoursepartService.addContributionToDiscoursePart(curContribution, thread); //parse and set creation time for content and contribution try { Date date = forgiving_date_parse(when); curContent.setStartTime(date); curContent.setEndTime(date); curContribution.setStartTime(date); curContribution.setEndTime(date); if (thread.getEndTime() == null || date.after(thread.getEndTime())) { thread.setEndTime(date); } if (thread.getStartTime() == null || date.before(thread.getStartTime())) { thread.setStartTime(date); } } catch (ParseException e) { log.error("Could not parse creation time " + when, e); } return curContribution.getId(); }
From source file:de.ep3.ftpc.model.CrawlerFile.java
/** * Decides whether this file is relevant for crawling or not * (depending on the crawler settings provided by the user). * * @param server Contains the crawler settings. * @param i18n To check and parse the user provided dates. * @return The decision.//from www. ja v a 2 s.c o m */ public boolean isRelevant(Server server, I18nManager i18n) { if (!isFile()) { return false; } if (server == null) { return false; } try { if (!server.has("crawler.file-name")) { return false; } if (!getName().matches(server.get("crawler.file-name"))) { return false; } } catch (PatternSyntaxException e) { return false; } long size = ftpFile.getSize() / 1024; if (server.has("crawler.file-size-min")) { long minSize = Long.parseLong(server.get("crawler.file-size-min")); if (size < minSize) { return false; } } if (server.has("crawler.file-size-max")) { long maxSize = Long.parseLong(server.get("crawler.file-size-max")); if (size > maxSize) { return false; } } Date date = ftpFile.getTimestamp().getTime(); if (server.has("crawler.file-date-start")) { try { Date startDate = i18n.parseDate(server.get("crawler.file-date-start")); if (date.before(startDate)) { return false; } } catch (ParseException e) { return false; } } if (server.has("crawler.file-date-end")) { try { Date endDate = i18n.parseDate(server.get("crawler.file-date-end")); if (date.after(endDate)) { return false; } } catch (ParseException e) { return false; } } return true; }