/** * {@inheritDoc} */ public boolean addAll(Collection<? extends Period> arg0) { for (Period p : arg0) { add(p); } return true; }
/** * 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 Iterator i = periods.iterator(); i.hasNext();) { newList.add((Period) i.next()); } return newList.normalise(); } return this; }
/** * {@inheritDoc} */ public boolean addAll(Collection<? extends Period> arg0) { for (Period p : arg0) { add(p); } return true; }
/** * {@inheritDoc} */ public boolean addAll(Collection<? extends Period> arg0) { for (Period p : arg0) { add(p); } return true; }
/** * {@inheritDoc} */ public boolean addAll(Collection<? extends Period> arg0) { for (Period p : arg0) { add(p); } return true; }
/** * Parses the specified string representation to create a list of periods. * * @param aValue * a string representation of a list of periods * @throws ParseException * thrown when an invalid string representation of a period list * is specified */ public PeriodList(final String aValue) throws ParseException { this(); final StringTokenizer t = new StringTokenizer(aValue, ","); while (t.hasMoreTokens()) { add(new Period(t.nextToken())); } }
/** * Parses the specified string representation to create a list of periods. * * @param aValue * a string representation of a list of periods * @throws ParseException * thrown when an invalid string representation of a period list * is specified */ public PeriodList(final String aValue) throws ParseException { this(); final StringTokenizer t = new StringTokenizer(aValue, ","); while (t.hasMoreTokens()) { add(new Period(t.nextToken())); } }
/** * Parses the specified string representation to create a list of periods. * * @param aValue * a string representation of a list of periods * @throws ParseException * thrown when an invalid string representation of a period list * is specified */ public PeriodList(final String aValue) throws ParseException { this(); final StringTokenizer t = new StringTokenizer(aValue, ","); while (t.hasMoreTokens()) { add(new Period(t.nextToken())); } }
/** * Parses the specified string representation to create a list of periods. * * @param aValue * a string representation of a list of periods * @throws ParseException * thrown when an invalid string representation of a period list * is specified */ public PeriodList(final String aValue) throws ParseException { this(); final StringTokenizer t = new StringTokenizer(aValue, ","); while (t.hasMoreTokens()) { add((Object) new Period(t.nextToken())); } }
/** * Parses the specified string representation to create a list of periods. * * @param aValue * a string representation of a list of periods * @throws ParseException * thrown when an invalid string representation of a period list * is specified */ public PeriodList(final String aValue) throws ParseException { this(); final StringTokenizer t = new StringTokenizer(aValue, ","); while (t.hasMoreTokens()) { add(new Period(t.nextToken())); } }
/** * Add all periods that intersect a given period to the result PeriodList. */ private void addRelevantPeriods(PeriodList results, PeriodList periods, Period range) { for (Iterator<Period> it = periods.iterator(); it.hasNext();) { Period p = it.next(); if (p.intersects(range)) results.add(p); } }
/** * Add all periods that intersect a given period to the result PeriodList. */ private void addRelevantPeriods(PeriodList results, PeriodList periods, Period range) { for (Iterator<Period> it = periods.iterator(); it.hasNext();) { Period p = it.next(); if (p.intersects(range)) results.add(p); } }
/** * @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; }
/** * Add a period to the list. * * @param period * the period to add * @return true * @see java.util.List#add(java.lang.Object) */ public final boolean add(final Period period) { if (isUtc()) { period.setUtc(true); } else { period.setTimeZone(timezone); } return add((Object) period); }
/** * 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; } }
/** * 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; } }
@Override public void visit(TemporalExpressions.DateRange expr) { if (this.state.isExcluded) { throw new IllegalStateException("iCalendar does not support excluded date ranges"); } org.apache.ofbiz.base.util.DateRange range = expr.getDateRange(); PeriodList periodList = new PeriodList(); periodList.add(new Period(new DateTime(range.start()), new DateTime(range.end()))); this.incDateList.add(new RDate(periodList)); }
public final void testPeriodListSort() { PeriodList periods = new PeriodList(); Calendar cal = Calendar.getInstance(); cal.set(Calendar.DAY_OF_MONTH, 25); periods.add(new Period(new DateTime(), new DateTime(cal.getTime() .getTime()))); periods.add(new Period(new DateTime(cal.getTime().getTime()), java.time.Duration.ofHours(2))); periods.add(new Period(new DateTime(), java.time.Duration.ofHours(2))); periods.add(new Period(new DateTime(), java.time.Duration.ofHours(1))); // log.info("Unsorted list: " + periods); // Collections.sort(periods); log.info("Sorted list: " + periods); }
/** * 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()); } }
/** * Test timezone functionality. */ public void testTimezone() { // TimeZoneRegistry registry = TimeZoneRegistryFactory.getInstance() // .createRegistry(); // TimeZone timezone = registry.getTimeZone("Australia/Melbourne"); PeriodList list = new PeriodList(true); java.util.Calendar cal = java.util.Calendar.getInstance(); for (int i = 0; i < 5; i++) { DateTime start = new DateTime(cal.getTime()); cal.add(Calendar.DAY_OF_YEAR, 1); DateTime end = new DateTime(cal.getTime()); list.add(new Period(start, end)); } log.info("Timezone test - period list: [" + list + "]"); list.forEach(p -> { assertTrue(p.getStart().isUtc()); assertTrue(p.getEnd().isUtc()); }); }