/** * A convenience method that combines all the periods in the specified list to * this list. The result returned is a new PeriodList instance, except where * no periods are specified in the arguments. In such cases this instance is returned. * * Normalisation is also performed automatically after all periods have been added. * * @param periods a list of periods to add * @return a period list instance */ public final PeriodList add(final PeriodList periods) { if (periods != null) { final PeriodList newList = new PeriodList(); newList.addAll(this); for (final Period p : periods) { newList.add(p); } return newList.normalise(); } return this; }
/** * @return String representation of list */ public String getValue() throws CalFacadeException { if (value == null) { if ((periods == null) || periods.isEmpty()) { return null; } PeriodList pl = new PeriodList(); for (Period p: getPeriods()) { pl.add(p); } value = pl.toString(); } return value; }
/** * Subtracts the intersection of this list with the specified list of * periods from this list and returns the results as a new period list. If * no intersection is identified this list is returned. * * @param subtractions * a list of periods to subtract from this list * @return a period list */ public final PeriodList subtract(final PeriodList subtractions) { if (subtractions == null || subtractions.isEmpty()) { return this; } PeriodList result = this; PeriodList tmpResult = new PeriodList(); for (final Period subtraction : subtractions) { for (final Period period : result) { tmpResult.addAll(period.subtract(subtraction)); } result = tmpResult; tmpResult = new PeriodList(); } return result; }
/** * A convenience method that combines all the periods in the specified list to * this list. The result returned is a new PeriodList instance, except where * no periods are specified in the arguments. In such cases this instance is returned. * * Normalisation is also performed automatically after all periods have been added. * * @param periods a list of periods to add * @return a period list instance */ public final PeriodList add(final PeriodList periods) { if (periods != null) { final PeriodList newList = new PeriodList(); newList.addAll(this); newList.addAll(periods); return newList.normalise(); } return this; }
/** * {@inheritDoc} */ public final void setTimeZone(TimeZone timezone) { if (periods != null && !(periods.isEmpty() && periods.isUnmodifiable())) { periods.setTimeZone(timezone); } else { super.setTimeZone(timezone); } }
Period prevPeriod = null; Period period = null; final PeriodList newList = new PeriodList(isUtc()); if (timezone != null) { newList.setTimeZone(timezone); for (final Iterator i = iterator(); i.hasNext();) { period = (Period) i.next(); if (period.isEmpty()) { newList.add(prevPeriod); newList.add(prevPeriod);
final PeriodList recurrenceSet = new PeriodList(); recurrenceSet.setUtc(true); recurrenceSet.setTimeZone(((DateTime) start.getDate()).getTimeZone()); final Value rdateValue = (Value) rdate.getParameter(Parameter.VALUE); if (Value.PERIOD.equals(rdateValue)) { for (final Iterator j = rdate.getPeriods().iterator(); j.hasNext();) { final Period rdatePeriod = (Period) j.next(); if (period.intersects(rdatePeriod)) { recurrenceSet.add(rdatePeriod); final DateTime rdateTime = (DateTime) j.next(); if (period.includes(rdateTime)) { recurrenceSet.add(new Period(rdateTime, rDuration)); final Date rdateDate = (Date) j.next(); if (period.includes(rdateDate)) { recurrenceSet.add(new Period(new DateTime(rdateDate), rDuration)); for (final Iterator j = rruleDates.iterator(); j.hasNext();) { final Date rruleDate = (Date) j.next(); recurrenceSet.add(new Period(new DateTime(rruleDate), rDuration)); recurrenceSet.add(startPeriod); for (final Iterator j = recurrenceSet.iterator(); j.hasNext();) { final Period recurrence = (Period) j.next();
final PeriodList recurrenceSet = new PeriodList(); recurrenceSet.setUtc(true); } else if (start.getDate() instanceof DateTime) { recurrenceSet.setTimeZone(((DateTime) start.getDate()).getTimeZone()); recurrenceSet.addAll(rDates.stream().filter(p -> p.getParameter(Parameter.VALUE) == Value.PERIOD) .map(p -> p.getPeriods()).flatMap(PeriodList::stream).filter(rdatePeriod -> period.intersects(rdatePeriod)) .collect(Collectors.toList())); recurrenceSet.addAll(rDates.stream().filter(p -> p.getParameter(Parameter.VALUE) == Value.DATE_TIME) .map(p -> p.getDates()).flatMap(DateList::stream).filter(date -> period.includes(date)) .map(rdateTime -> new Period((DateTime) rdateTime, rDuration)).collect(Collectors.toList())); recurrenceSet.addAll(rDates.stream().filter(p -> p.getParameter(Parameter.VALUE) == Value.DATE) .map(p -> p.getDates()).flatMap(DateList::stream).filter(date -> period.includes(date)) .map(rdateDate -> new Period(new DateTime(rdateDate), rDuration)).collect(Collectors.toList())); recurrenceSet.addAll(rRules.stream().map(r -> r.getRecur().getDates(start.getDate(), new Period(startMinusDuration, period.getEnd()), startValue)).flatMap(DateList::stream) .map(rruleDate -> new Period(new DateTime(rruleDate), rDuration)).collect(Collectors.toList())); recurrenceSet.add(startPeriod); recurrenceSet.removeIf(recurrence -> { recurrenceSet.removeIf(recurrence -> {
/** * Unit tests for {@link PeriodList#normalise()}. */ public void testNormalise() { // test a list of periods consuming no time.. PeriodList periods = new PeriodList(); DateTime start = new DateTime(); periods.add(new Period(start, start)); DateTime start2 = new DateTime(); periods.add(new Period(start2, start2)); assertTrue(periods.normalise().isEmpty()); } }
PeriodList periods = new PeriodList(); if (!periods.isEmpty() && normalise) { periods = periods.normalise();
/** * Subtracts the intersection of this list with the specified list of * periods from this list and returns the results as a new period list. If * no intersection is identified this list is returned. * * @param subtractions * a list of periods to subtract from this list * @return a period list */ public final PeriodList subtract(final PeriodList subtractions) { if (subtractions == null || subtractions.isEmpty()) { return this; } PeriodList result = this; PeriodList tmpResult = new PeriodList(); for (final Iterator i = subtractions.iterator(); i.hasNext();) { final Period subtraction = (Period) i.next(); for (final Iterator j = result.iterator(); j.hasNext();) { final Period period = (Period) j.next(); tmpResult.addAll(period.subtract(subtraction)); } result = tmpResult; tmpResult = new PeriodList(); } return result; }
/** * Calculate all recurring periods for the specified date range. This method will take all * revisions into account when generating the set. * * @param period * @return * * @see Component#calculateRecurrenceSet(Period) */ public PeriodList calculateRecurrenceSet(final Period period) { PeriodList periods = new PeriodList(); for (Component component : getRevisions()) { periods = periods.add(component.calculateRecurrenceSet(period)); } return periods; } }
/** * {@inheritDoc} */ public final void setValue(final String aValue) throws ParseException { periods = new PeriodList(aValue); }
/** * {@inheritDoc} */ public boolean addAll(Collection<? extends Period> arg0) { for (Period p : arg0) { add(p); } return true; }
/** * {@inheritDoc} */ public final String getValue() { if (periods != null && !(periods.isEmpty() && periods.isUnmodifiable())) { return Strings.valueOf(getPeriods()); } return super.getValue(); }
/** * @param pList a list of periods */ public FreeBusy(final PeriodList pList) { super(FREEBUSY, new Factory()); if (!pList.isUtc()) { throw new IllegalArgumentException("Periods must be in UTC format"); } periods = pList; }
/** Get the free busy periods * * @return Collection of Period * @throws CalFacadeException */ public Collection<Period> getPeriods() throws CalFacadeException { if (periods == null) { periods = new TreeSet<Period>(); if (getValue() != null) { PeriodList pl; try { pl = new PeriodList(getValue()); } catch (Throwable t) { throw new CalFacadeException(t); } Iterator perit = pl.iterator(); while (perit.hasNext()) { Period per = (Period)perit.next(); periods.add(per); } } } return periods; }
/** * {@inheritDoc} */ public final String getValue() { return getPeriods().toString(); } }
public FreeBusy build() { final PeriodList periods = getConsumedTime(components, start, end); final DateRange range = new DateRange(start, end); // periods must be in UTC time for freebusy.. periods.setUtc(true); for (final Iterator i = periods.iterator(); i.hasNext();) { final Period period = (Period) i.next(); // check if period outside bounds.. if (!range.intersects(period)) { periods.remove(period); } } return new FreeBusy(periods); } }