List of usage examples for org.joda.time Interval contains
public boolean contains(long millisInstant)
From source file:io.druid.server.http.IntervalsResource.java
License:Apache License
@GET @Path("/{interval}") @Produces(MediaType.APPLICATION_JSON)// w w w .j a va 2 s. co m public Response getSpecificIntervals(@PathParam("interval") String interval, @QueryParam("simple") String simple, @QueryParam("full") String full, @Context final HttpServletRequest req) { final Interval theInterval = new Interval(interval.replace("_", "/")); final Set<DruidDataSource> datasources = authConfig.isEnabled() ? InventoryViewUtils.getSecuredDataSources(serverInventoryView, (AuthorizationInfo) req.getAttribute(AuthConfig.DRUID_AUTH_TOKEN)) : InventoryViewUtils.getDataSources(serverInventoryView); final Comparator<Interval> comparator = Comparators.inverse(Comparators.intervalsByStartThenEnd()); if (full != null) { final Map<Interval, Map<String, Map<String, Object>>> retVal = Maps.newTreeMap(comparator); for (DruidDataSource dataSource : datasources) { for (DataSegment dataSegment : dataSource.getSegments()) { if (theInterval.contains(dataSegment.getInterval())) { Map<String, Map<String, Object>> dataSourceInterval = retVal.get(dataSegment.getInterval()); if (dataSourceInterval == null) { Map<String, Map<String, Object>> tmp = Maps.newHashMap(); retVal.put(dataSegment.getInterval(), tmp); } setProperties(retVal, dataSource, dataSegment); } } } return Response.ok(retVal).build(); } if (simple != null) { final Map<Interval, Map<String, Object>> retVal = Maps.newHashMap(); for (DruidDataSource dataSource : datasources) { for (DataSegment dataSegment : dataSource.getSegments()) { if (theInterval.contains(dataSegment.getInterval())) { Map<String, Object> properties = retVal.get(dataSegment.getInterval()); if (properties == null) { properties = Maps.newHashMap(); properties.put("size", dataSegment.getSize()); properties.put("count", 1); retVal.put(dataSegment.getInterval(), properties); } else { properties.put("size", MapUtils.getLong(properties, "size", 0L) + dataSegment.getSize()); properties.put("count", MapUtils.getInt(properties, "count", 0) + 1); } } } } return Response.ok(retVal).build(); } final Map<String, Object> retVal = Maps.newHashMap(); for (DruidDataSource dataSource : datasources) { for (DataSegment dataSegment : dataSource.getSegments()) { if (theInterval.contains(dataSegment.getInterval())) { retVal.put("size", MapUtils.getLong(retVal, "size", 0L) + dataSegment.getSize()); retVal.put("count", MapUtils.getInt(retVal, "count", 0) + 1); } } } return Response.ok(retVal).build(); }
From source file:io.druid.timeline.VersionedIntervalTimeline.java
License:Apache License
/** * * @param timeline/* w w w. ja va 2 s.com*/ * @param key * @param entry * @return boolean flag indicating whether or not we inserted or discarded something */ private boolean addAtKey(NavigableMap<Interval, TimelineEntry> timeline, Interval key, TimelineEntry entry) { boolean retVal = false; Interval currKey = key; Interval entryInterval = entry.getTrueInterval(); if (!currKey.overlaps(entryInterval)) { return false; } while (entryInterval != null && currKey != null && currKey.overlaps(entryInterval)) { Interval nextKey = timeline.higherKey(currKey); int versionCompare = versionComparator.compare(entry.getVersion(), timeline.get(currKey).getVersion()); if (versionCompare < 0) { if (currKey.contains(entryInterval)) { return true; } else if (currKey.getStart().isBefore(entryInterval.getStart())) { entryInterval = new Interval(currKey.getEnd(), entryInterval.getEnd()); } else { addIntervalToTimeline(new Interval(entryInterval.getStart(), currKey.getStart()), entry, timeline); if (entryInterval.getEnd().isAfter(currKey.getEnd())) { entryInterval = new Interval(currKey.getEnd(), entryInterval.getEnd()); } else { entryInterval = null; // discard this entry } } } else if (versionCompare > 0) { TimelineEntry oldEntry = timeline.remove(currKey); if (currKey.contains(entryInterval)) { addIntervalToTimeline(new Interval(currKey.getStart(), entryInterval.getStart()), oldEntry, timeline); addIntervalToTimeline(new Interval(entryInterval.getEnd(), currKey.getEnd()), oldEntry, timeline); addIntervalToTimeline(entryInterval, entry, timeline); return true; } else if (currKey.getStart().isBefore(entryInterval.getStart())) { addIntervalToTimeline(new Interval(currKey.getStart(), entryInterval.getStart()), oldEntry, timeline); } else if (entryInterval.getEnd().isBefore(currKey.getEnd())) { addIntervalToTimeline(new Interval(entryInterval.getEnd(), currKey.getEnd()), oldEntry, timeline); } } else { if (timeline.get(currKey).equals(entry)) { // This occurs when restoring segments timeline.remove(currKey); } else { throw new UnsupportedOperationException( String.format("Cannot add overlapping segments [%s and %s] with the same version [%s]", currKey, entryInterval, entry.getVersion())); } } currKey = nextKey; retVal = true; } addIntervalToTimeline(entryInterval, entry, timeline); return retVal; }
From source file:jp.co.ntt.atrs.app.c0.MemberValidator.java
License:Apache License
/** * {@inheritDoc}// w w w . ja v a2 s . co m */ @Override public void validate(Object target, Errors errors) { IMemberForm form = (IMemberForm) target; // ? if (!errors.hasFieldErrors("mail") && !errors.hasFieldErrors("reEnterMail")) { String mail = form.getMail(); String reEnterMail = form.getReEnterMail(); if (!mail.equals(reEnterMail)) { // ?????????? errors.reject(MemberErrorCode.E_AR_C0_5001.code()); } } // ?? if (!errors.hasFieldErrors("tel1") && !errors.hasFieldErrors("tel2")) { if (!ValidationUtil.isValidTelNum(form.getTel1(), form.getTel2())) { // ?????67????? errors.reject(MemberErrorCode.E_AR_C0_5002.code()); } } // ? if (!errors.hasFieldErrors("dateOfBirth")) { DateTime dateOfBirthMin = DateTimeUtil.toDateTime(dateOfBirthMinDate); DateTime dateOfBirthMax = dateFactory.newDateTime(); DateTime dateOfBirth = new DateTime(form.getDateOfBirth()); Interval interval = new Interval(dateOfBirthMin, dateOfBirthMax); if (!interval.contains(dateOfBirth)) { // ?(190011????)???? errors.reject(MemberErrorCode.E_AR_C0_5003.code(), new Object[] { dateOfBirthMinDate, DateTimeUtil.toFormatDateString(dateOfBirthMax) }, ""); } } }
From source file:jp.co.ntt.atrs.domain.common.masterdata.PeakTimeProvider.java
License:Apache License
/** * ?????//from w w w. j a v a 2 s .co m * * @param depDate ? * @return ??????null */ public PeakTime getPeakTime(Date depDate) { Assert.notNull(depDate); for (PeakTime peakTime : peakTimeList) { Interval peakTimeInterval = new Interval( new DateTime(peakTime.getPeakStartDate()).withTimeAtStartOfDay(), new DateTime(peakTime.getPeakEndDate()).withTimeAtStartOfDay().plus(1)); // ????? if (peakTimeInterval.contains(depDate.getTime())) { return peakTime; } } return null; }
From source file:jp.co.ntt.atrs.domain.service.b0.TicketSharedServiceImpl.java
License:Apache License
/** * {@inheritDoc}//from w ww . j av a 2s .c o m */ @Override public void validateDepatureDate(Date departureDate) throws BusinessException { Assert.notNull(departureDate); DateTime sysDateMidnight = dateFactory.newDateTime().withTimeAtStartOfDay(); DateTime limitDateMidnight = getSearchLimitDate().toDateTimeAtStartOfDay(); // ???????????? Interval reservationAvailableInterval = new Interval(sysDateMidnight, limitDateMidnight.plusDays(1)); if (!reservationAvailableInterval.contains(departureDate.getTime())) { throw new AtrsBusinessException(TicketSearchErrorCode.E_AR_B1_2001); } }
From source file:jp.furplag.util.time.JodaPrettifier.java
License:Apache License
/** * Return the prettified String if the period includes specified moment. * * <pre>//from www .j av a 2s. c o m * prettify(DateTime.now().minusHours(1), null, null, null, null) = "one hour ago." prettify(DateTime.now(), DateTime.now().plusYears(1), null, null, null) = "one year ago." prettify(DateTime.now().minusHours(1), null, null, null, new Period().withDays(1)) = "one hour ago." prettify(DateTime.now().minusHours(1), null, null, null, new Period().withMinites(10)) = * DateTime.now().withZone(DateTimeZone.UTC).minusHours(1).toString(DateTimeFormat.forStyle("-M")) * * <pre> * * @param then the datetime object, null means current date-time. * @param reference the moment of a starting point ( {@link org.joda.time.ReadableInstant} and {@link Long} specifiable ). Use {@code DateTime.now()} as a start point if {@code reference} is null. * @param locale the language for Localization ( {@code String} and {@code Locale} specifiable ). Use ROOT if {@code locale} is null. * @param limit if the moment is in the specified period, return prettified String ( {@code Period} and {@code Interval} specifiable ). Prettify all, if null. * @return the prettified String if the period includes specified moment. In other situation, return stringified date-time. */ public static String prettify(final Object then, final Object reference, final Locale locale, final DateTimeZone zone, final Object limit) { DateTime temporary = DateTimeUtils.toDT(then, zone, true); if (temporary == null) return StringUtils.EMPTY; DateTime ref = DateTimeUtils.toDT(reference, temporary.getZone(), true); if (ref == null) return doPrettify(temporary, null, locale); if (ref.isEqual(temporary)) ref = ref.plusMillis(1); if (limit == null) return doPrettify(temporary, ref, locale); Interval limitter = null; if (Interval.class.equals(limit)) limitter = (Interval) limit; if (limit instanceof Period) { limitter = new Interval(ref.minus((Period) limit), ref.plusMillis(1).plus((Period) limit)); } if (limit instanceof BaseSingleFieldPeriod) { limitter = new Interval(ref.minus(new Period(limit)), ref.plusMillis(1).plus(new Period(limit))); } if (ObjectUtils.isAny(ClassUtils.primitiveToWrapper(limit.getClass()), Double.class, Float.class)) { limitter = new Interval(toDT(toAJD(ref) - NumberUtils.valueOf(limit, double.class), ref), toDT(toAJD(ref) + NumberUtils.valueOf(limit, double.class), ref)); } else if (BigDecimal.class.equals(limit.getClass())) { if (NumberUtils.compareTo((BigDecimal) limit, NumberUtils.down(limit)) == 0) { limitter = new Interval(ref.minusMillis(NumberUtils.valueOf(limit, int.class)), ref.plusMillis(NumberUtils.valueOf(limit, int.class) + 1)); } else { limitter = new Interval(toDT(toAJD(ref) - NumberUtils.valueOf(limit, double.class), ref), toDT(toAJD(ref) + NumberUtils.valueOf(limit, double.class), ref)); } } else if (Number.class.isAssignableFrom(ClassUtils.primitiveToWrapper(limit.getClass()))) { limitter = new Interval(ref.minusMillis(NumberUtils.valueOf(limit, int.class)), ref.plusMillis(NumberUtils.valueOf(limit, int.class) + 1)); } if (DateTime.class.equals(limit.getClass())) { limitter = new Interval(ref.minus(((DateTime) limit).getMillis()), ref.plus(((DateTime) limit).getMillis() + 1L)); } if (Boolean.class.equals(limit.getClass())) { limitter = new Interval(temporary.minusMillis(1), ((Boolean) limit) ? temporary.plusMillis(1) : temporary.minusMillis(1)); } if (limitter == null) return doPrettify(temporary, ref, locale); if (limitter.contains(temporary)) return doPrettify(temporary, ref, locale); return toDT(temporary, GJChronology.getInstance(temporary.getZone())) .toString(DateTimeFormat.forStyle(isToday(temporary, temporary.getZone()) ? "-M" : "MS") .withLocale(locale == null ? Locale.ROOT : locale)); }
From source file:module.workflow.domain.WorkflowProcess.java
License:Open Source License
/** * @deprecated use getExecutionLogStream instead *///from ww w . java 2s. c o m @Deprecated public List<WorkflowLog> getExecutionLogs(DateTime begin, DateTime end, Class<?>... activitiesClass) { List<WorkflowLog> logs = new ArrayList<WorkflowLog>(); Interval interval = new Interval(begin, end); for (WorkflowLog log : getExecutionLogs()) { if (interval.contains(log.getWhenOperationWasRan()) && (activitiesClass.length == 0 || (log instanceof ActivityLog && match(activitiesClass, ((ActivityLog) log).getOperation())))) { logs.add(log); } } return logs; }
From source file:module.workflow.domain.WorkflowProcess.java
License:Open Source License
public Stream<WorkflowLog> getExecutionLogStream(DateTime begin, DateTime end, Class<?>... activitiesClass) { final Interval i = new Interval(begin, end); final Stream<WorkflowLog> logs = getExecutionLogStream(); return logs.filter(l -> i.contains(l.getWhenOperationWasRan()) && (activitiesClass.length == 0 || (l instanceof ActivityLog && match(activitiesClass, ((ActivityLog) l).getOperation())))); }
From source file:net.schweerelos.timeline.model.Timeline.java
License:Open Source License
private Set<PayloadInterval<T>> calculateIntervalsWithinRange(DateTime rangeStart, DateTime rangeEnd) { Set<PayloadInterval<T>> result = new HashSet<PayloadInterval<T>>(); Interval range = new Interval(rangeStart, rangeEnd); for (PayloadInterval<T> interval : allIntervals) { if (range.contains(interval.getStart()) && range.contains(interval.getEnd())) { result.add(interval);/*w w w. ja v a2s. c o m*/ } } return result; }
From source file:net.schweerelos.timeline.ui.TimelinePanel.java
License:Open Source License
public IntervalChain<T> getSelections() { IntervalChain<T> result = new IntervalChain<T>(); if (selectionModel.isSelectionEmpty()) { return result; }/*from ww w.j a v a2 s . c om*/ List<Interval> selections = new ArrayList<Interval>(); int minSelectedIndex = selectionModel.getMinSelectionIndex(); int maxSelectedIndex = selectionModel.getMaxSelectionIndex(); DateTime lastStart = null; int currentIndex = minSelectedIndex; while (currentIndex <= maxSelectedIndex) { if (selectionModel.isSelectedIndex(currentIndex)) { if (lastStart == null) { // start of a new interval lastStart = tModel.convertSliceToInterval(currentIndex).getStart(); } } else { if (lastStart != null) { // end of a new interval DateTime end = tModel.convertSliceToInterval(currentIndex).getEnd(); Interval newInterval = new Interval(lastStart, end); selections.add(newInterval); lastStart = null; } } currentIndex++; } // lastStart should be non-null now if (lastStart != null) { // end of a new interval DateTime end = tModel.convertSliceToInterval(maxSelectedIndex).getEnd(); Interval newInterval = new Interval(lastStart, end); selections.add(newInterval); } else { logger.warn("last start is null, shouldn't happen"); } // TODO see if we can get this to be more efficient for (PayloadInterval<T> interval : tModel.getIntervalsWithinRange()) { for (Interval selection : selections) { if (selection.contains(interval.toInterval())) { result.add(interval); } } } return result; }