List of usage examples for java.util Date before
public boolean before(Date when)
From source file:com.netflix.simianarmy.janitor.JanitorEmailNotifier.java
/** * Decides if it is time for sending notification for the resource. This method can be * overridden in subclasses so notifications can be send earlier or later. * @param resource the resource//from ww w. j ava2 s.c o m * @return true if it is OK to send notification now, otherwise false. */ protected boolean canNotify(Resource resource) { Validate.notNull(resource); if (resource.getState() != CleanupState.MARKED || resource.isOptOutOfJanitor()) { return false; } Date notificationTime = resource.getNotificationTime(); // We don't want to send notification too early (since things may change) or too late (we need // to give owners enough time to take actions. Date windowStart = new Date( new DateTime(calendar.getBusinessDay(calendar.now().getTime(), daysBeforeTermination).getTime()) .minusHours(HOURS_IN_MARGIN).getMillis()); Date windowEnd = calendar.getBusinessDay(calendar.now().getTime(), daysBeforeTermination + 1); Date terminationDate = resource.getExpectedTerminationTime(); if (notificationTime == null || resource.getMarkTime().after(notificationTime)) { // remarked after a notification if (!terminationDate.before(windowStart) && !terminationDate.after(windowEnd)) { // The expected termination time is close enough for sending notification return true; } else if (terminationDate.before(windowStart)) { // The expected termination date is too close. To give the owner time to take possible actions, // we extend the expected termination time here. LOGGER.info(String.format( "It is less than %d days before the expected termination date," + " of resource %s, extending the termination time to %s.", daysBeforeTermination, resource.getId(), windowStart)); resource.setExpectedTerminationTime(windowStart); resourceTracker.addOrUpdate(resource); return true; } else { return false; } } return false; }
From source file:eu.europa.ec.fisheries.uvms.reporting.service.bean.impl.ReportExecutionServiceBean.java
private void updateTripWithVmsPositionCount(TripDTO trip, Collection<MovementMapResponseType> movementMap) { Integer count = 0;/*from ww w .j a va 2 s. c o m*/ if (trip != null && (trip.getRelativeFirstFaDateTime() != null && trip.getRelativeLastFaDateTime() != null)) { for (MovementMapResponseType map : movementMap) { for (MovementType movement : map.getMovements()) { if (movement.getPositionTime() != null) { Date movementDate = movement.getPositionTime(); if (movementDate.after(trip.getRelativeFirstFaDateTime()) && movementDate.before(trip.getRelativeLastFaDateTime())) { count++; } } } } trip.setVmsPositionCount(count); } }
From source file:com.iorga.webappwatcher.analyzer.model.session.DurationPerPrincipalStats.java
private boolean isDateInTimeSlice(final Date date, final TimeSlice currentTimeSlice) { return date.after(currentTimeSlice.startDate) && date.before(currentTimeSlice.endDate); }
From source file:dk.dma.ais.tracker.scenarioTracker.ScenarioTracker.java
/** * Get the Date of the first update in this scenario. * @return// w w w . j a v a2s.c om */ public Date scenarioBegin() { Date scenarioBegin = 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.firstKey(); if (scenarioBegin == null || targetFirstUpdate.before(scenarioBegin)) { scenarioBegin = targetFirstUpdate; } } catch (NoSuchElementException e) { } } return scenarioBegin; }
From source file:de.suse.swamp.core.util.BugzillaTools.java
private void cacheMaintenance() { // do maintenance, remove outdated entries List removeIds = new ArrayList(); synchronized (bugzillaCache) { for (Iterator it = bugzillaCache.keySet().iterator(); it.hasNext();) { Integer id = (Integer) it.next(); Date date = (Date) ((Hashtable) bugzillaCache.get(id)).get("date"); Date outDate = new Date(new Date().getTime() - 1000 * 60 * 20); if (date == null || date.before(outDate)) removeIds.add(id);/*w ww. j av a 2 s . c om*/ } for (Iterator it = removeIds.iterator(); it.hasNext();) { Integer id = (Integer) it.next(); bugzillaCache.remove(id); Logger.DEBUG("Bug cache outdated: " + id); } } }
From source file:org.dspace.embargo.EmbargoServiceImpl.java
/** * Get the embargo lift date for an Item, if any. This looks for the * metadata field configured to hold embargo terms, and gives it * to the EmbargoSetter plugin's method to interpret it into * an absolute timestamp. This is intended to be called at the time * the Item is installed into the archive. * <p>// www .j a v a 2s. c o m * Note that the plugin is *always* called, in case it gets its cue for * the embargo date from sources other than, or in addition to, the * specified field. * * @param context the DSpace context * @param item the item to embargo * @return lift date on which the embargo is to be lifted, or null if none */ @Override public DCDate getEmbargoTermsAsDate(Context context, Item item) throws SQLException, AuthorizeException { init(); List<MetadataValue> terms = itemService.getMetadata(item, terms_schema, terms_element, terms_qualifier, Item.ANY); DCDate result = null; // Its poor form to blindly use an object that could be null... if (terms == null) return null; result = setter.parseTerms(context, item, terms.size() > 0 ? terms.iterator().next().getValue() : null); if (result == null) return null; // new DCDate(non-date String) means toDate() will return null Date liftDate = result.toDate(); if (liftDate == null) { throw new IllegalArgumentException("Embargo lift date is uninterpretable: " + result.toString()); } // sanity check: do not allow an embargo lift date in the past. if (liftDate.before(new Date())) { throw new IllegalArgumentException( "Embargo lift date must be in the future, but this is in the past: " + result.toString()); } return result; }
From source file:com.virtusa.akura.student.controller.StudentAttendenceController.java
/** * generate student attendance detail for given time range in studentTemplate. map key contains date and * value contains attendance status as AttendeceStatus object. * /*ww w. j a v a 2 s .co m*/ * @param studentTemplate time rage as template * @param studentId for given studentId(primary key) * @param modelMap - a hash map related to the student attendance. * @return map with attendant status * @throws AkuraAppException when exception occurs */ private Map<String, AttendeceStatus> getAllAttendanceStatus(StudentWiseSwipInOutTemplate studentTemplate, int studentId, ModelMap modelMap) throws AkuraAppException { Date from = DateUtil.getParseDate(studentTemplate.getDateFrom()); Date to = DateUtil.getParseDate(studentTemplate.getDateTo()); Map<String, AttendeceStatus> allDays = new TreeMap<String, AttendeceStatus>(); // if the start date of the student is less than the attendance search from date, // save or edit. Date startedDate = studentService.getStudentStartedDate(studentId); if (startedDate != null && from.after(startedDate) || (startedDate != null && startedDate.equals(from))) { // map contains all the days with absent in default allDays = getDaysWithoutHolydays(from, to); // to overwrite the "allDays" map values for absent with a reason List<StudentLeave> leaveList = studentService.findAlreadyExistLeave(studentId, from, to); for (StudentLeave leave : leaveList) { Date leaveFrom = leave.getFromDate(); Date leaveTo = leave.getToDate(); for (Entry<String, AttendeceStatus> entry : allDays.entrySet()) { Date day = DateUtil.getParseDate(entry.getKey()); if (day.equals(leaveFrom) || day.equals(leaveTo) || (day.after(leaveFrom) && day.before(leaveTo))) { entry.getValue().setDescription(leave.getReason()); } } } // to overwrite the "allDays" map values for attended days List<DailyStudentAttendance> dalyAttendList = dailyAttendanceService.getAttendanceBettween(studentId, from, to); for (DailyStudentAttendance dalyAttend : dalyAttendList) { String dayKey = DateUtil.getFormatDate(dalyAttend.getDate()); if (allDays.containsKey(dayKey)) { AttendeceStatus attendStatus = allDays.get(dayKey); attendStatus.setAbsent(false); attendStatus.setTimeIn(dalyAttend.getTimeIn()); attendStatus.setTimeOut(dalyAttend.getTimeOut()); } } } else { String message = new ErrorMsgLoader().getErrorMessage(STUDENT_FIRST_DATE_ATTENDANCE_ERROR); modelMap.addAttribute(MESSAGE, message); } return allDays; }
From source file:edu.stanford.muse.datacache.BlobSet.java
private List<Blob> sortBlobsByTime() { // create a map of unique data -> earliest time it was seen (based on any of the others it maps to) final Map<Blob, Date> tmpMap = new LinkedHashMap<Blob, Date>(); for (Map.Entry<Blob, List<Blob>> me : uniqueBlobMap.entrySet()) { Blob unique_data = me.getKey(); List<Blob> datas_for_this_unique_data = me.getValue(); Date earliest = unique_data.getModifiedDate(); for (Blob b : datas_for_this_unique_data) { Date c = b.getModifiedDate(); if (c == null) b.modifiedDate = new Date(); // dummy date if (c != null && earliest != null) if (c.before(earliest)) earliest = c;/* ww w .j a va2 s. co m*/ } tmpMap.put(unique_data, earliest); } // now sort the unique_data's by earliest time set in tmpMap List<Blob> result = new ArrayList<Blob>(); log.info("Checking blobs consistency for sorting..."); result.addAll(tmpMap.keySet()); for (Blob b : result) { if (tmpMap.get(b) == null) log.warn("Blob " + b + " has null in tmpmap!"); if (!b.equals(b)) log.warn("Blob " + b + " failed equals with itself!"); } try { Collections.sort(result, new Comparator<Blob>() { public int compare(Blob b1, Blob b2) { Date c1 = tmpMap.get(b1); Date c2 = tmpMap.get(b2); if (c1 == null) { return -1; } if (c2 == null) return 1; // this will confuse the sorting, but what the heck... if (c1.before(c2)) return 1; else return -1; } }); } catch (Exception e) { log.warn("Error sorting blobs by time! --"); Util.print_exception(e); } return result; }