/** * {@inheritDoc} */ public final String toString() { final StringBuffer buffer = new StringBuffer(); for (final Iterator i = iterator(); i.hasNext();) { buffer.append(i.next().toString()); } return buffer.toString(); }
/** * Returns the first component of specified name. * @param aName name of component to return * @return a component or null if no matching component found */ public final Component getComponent(final String aName) { for (final Iterator i = iterator(); i.hasNext();) { final Component c = (Component) i.next(); if (c.getName().equals(aName)) { return c; } } return null; }
/** * gets master component. * @param components The component list. * @return The component. */ private Component getMasterComponent(ComponentList<? extends Component> components) { Iterator<? extends Component> it = components.iterator(); while(it.hasNext()) { Component c = it.next(); if(c.getProperty(Property.RECURRENCE_ID)==null) { return c; } } throw new IllegalArgumentException("no master found"); }
/** * gets master component. * @param components The component list. * @return The component. */ private Component getMasterComponent(ComponentList<? extends Component> components) { Iterator<? extends Component> it = components.iterator(); while(it.hasNext()) { Component c = it.next(); if(c.getProperty(Property.RECURRENCE_ID)==null) { return c; } } throw new IllegalArgumentException("no master found"); }
/** * Invoke validation on the calendar components in its current state. * @throws ValidationException where any of the calendar components is not in a valid state */ private void validateComponents() throws ValidationException { for (final Iterator i = getComponents().iterator(); i.hasNext();) { final Component component = (Component) i.next(); component.validate(); } }
/** * Creates a deep copy of the specified component list. * @param components a component list to copy * @throws IOException where an error occurs reading component data * @throws ParseException where component data cannot be parsed * @throws URISyntaxException where component data contains an invalid URI */ public ComponentList(ComponentList components) throws ParseException, IOException, URISyntaxException { for (final Iterator i = components.iterator(); i.hasNext();) { final Component c = (Component) i.next(); add(c.copy()); } }
/** * Returns the latest component revision based on ascending sequence number and modified date. * * @return */ public T getLatestRevision() { ComponentList<T> revisions = getRevisions(); revisions.sort(new ComponentSequenceComparator()); Collections.reverse(revisions); return revisions.iterator().next(); }
/** * Returns a list containing all components with specified name. * @param name name of components to return * @return a list of components with the matching name */ public final ComponentList getComponents(final String name) { final ComponentList components = new ComponentList(); for (final Iterator i = iterator(); i.hasNext();) { final Component c = (Component) i.next(); if (c.getName().equals(name)) { components.add(c); } } return components; }
/** * Returns the latest component revision based on ascending sequence number and modified date. * * @return */ public T getLatestRevision() { ComponentList<T> revisions = getRevisions(); revisions.sort(new ComponentSequenceComparator()); Collections.reverse(revisions); return revisions.iterator().next(); }
/** * Returns the first component containing a property with the specified * value. * @param propertyValue the value of the property identified in the returned * component * @return a component or null if no component is found containing a property * with the specified value */ public Component getComponent(final String propertyValue) { final ComponentList components = getComponents(propertyValue); if (!components.isEmpty()) { return (Component) components.iterator().next(); } return null; } }
/** * Creates a new instance indexed on properties with the specified name. * @param list a list of components * @param propertyName the name of the properties to index on */ public IndexedComponentList(final ComponentList list, final String propertyName) { final Map indexedComponents = new HashMap(); for (final Iterator i = list.iterator(); i.hasNext();) { final Component component = (Component) i.next(); for (final Iterator j = component.getProperties(propertyName).iterator(); j.hasNext();) { final Property property = (Property) j.next(); ComponentList components = (ComponentList) indexedComponents.get(property.getValue()); if (components == null) { components = new ComponentList(); indexedComponents.put(property.getValue(), components); } components.add(component); } } this.index = Collections.unmodifiableMap(indexedComponents); }
/** * Returns the latest applicable timezone observance for the specified date. * @param date the latest possible date for a timezone observance onset * @return the latest applicable timezone observance for the specified date or null if there are no applicable * observances */ public final Observance getApplicableObservance(final Date date) { Observance latestObservance = null; Date latestOnset = null; for (final Iterator i = getObservances().iterator(); i.hasNext();) { final Observance observance = (Observance) i.next(); final Date onset = observance.getLatestOnset(date); if (latestOnset == null || (onset != null && onset.after(latestOnset))) { latestOnset = onset; latestObservance = observance; } } return latestObservance; }
for (Iterator<VEvent> i = vevents.iterator(); i.hasNext();) { VEvent event = i.next(); if (event.getRecurrenceId() != null) {
for (Iterator<VEvent> i = vevents.iterator(); i.hasNext();) { VEvent event = i.next(); if (event.getRecurrenceId() != null) {
/** * Creates a list of periods representing the time consumed by the specified list of components. * @param components * @return */ private PeriodList getConsumedTime(final ComponentList components, final DateTime rangeStart, final DateTime rangeEnd) { final PeriodList periods = new PeriodList(); // only events consume time.. for (final Iterator i = components.getComponents(Component.VEVENT).iterator(); i.hasNext();) { final Component component = (Component) i.next(); periods.addAll(((VEvent) component).getConsumedTime(rangeStart, rangeEnd, false)); } return periods.normalise(); }
/** * Returns a unique identifier as specified by components in the provided calendar. * @param calendar a calendar instance * @return the UID property * @throws ConstraintViolationException if zero or more than one unique identifer is found in the specified calendar */ public static Uid getUid(final Calendar calendar) throws ConstraintViolationException { Uid uid = null; for (final Iterator i = calendar.getComponents().iterator(); i.hasNext();) { final Component c = (Component) i.next(); for (final Iterator j = c.getProperties(Property.UID).iterator(); j.hasNext();) { final Uid foundUid = (Uid) j.next(); if (uid != null && !uid.equals(foundUid)) { throw new ConstraintViolationException("More than one UID found in calendar"); } uid = foundUid; } } if (uid == null) { throw new ConstraintViolationException("Calendar must specify a single unique identifier (UID)"); } return uid; }
/** * ICU4J generates VTIMEZONE RRULEs with floating UNTIL, which results * in a bad VTIMEZONE because the UNTIL is converted to UTC, which will * be different depending on the default timezone of the server. So * to fix this, always add a day to UNTIL to make sure the RRULE * doesn't fall short. This should work for most timezones as timezones * don't usually change from day to day. Hopefully this is fixed in * an icu4j update. * @param vtz */ protected static void fixIcuVTimeZone(VTimeZone vtz) { for(Iterator<Observance> obIt = vtz.getObservances().iterator();obIt.hasNext();) { PropertyList<RRule> rruleList= obIt.next().getProperties(Property.RRULE); for(RRule rrule: rruleList) { Recur recur = rrule.getRecur(); if(recur.getUntil()!=null) { recur.getUntil().setTime(recur.getUntil().getTime() + ONE_DAY); } } } }
/** * ICU4J generates VTIMEZONE RRULEs with floating UNTIL, which results * in a bad VTIMEZONE because the UNTIL is converted to UTC, which will * be different depending on the default timezone of the server. So * to fix this, always add a day to UNTIL to make sure the RRULE * doesn't fall short. This should work for most timezones as timezones * don't usually change from day to day. Hopefully this is fixed in * an icu4j update. * @param vtz */ protected static void fixIcuVTimeZone(VTimeZone vtz) { for(Iterator<Observance> obIt = vtz.getObservances().iterator();obIt.hasNext();) { PropertyList<RRule> rruleList= obIt.next().getProperties(Property.RRULE); for(RRule rrule: rruleList) { Recur recur = rrule.getRecur(); if(recur.getUntil()!=null) { recur.getUntil().setTime(recur.getUntil().getTime() + ONE_DAY); } } } }
/** * Indexing with IndexedPropertyList. */ public void testIndexing() { // a VEvent for more interesting data.. Component component = (Component) calendar.getComponents(Component.VEVENT).iterator().next(); IndexedPropertyList list = new IndexedPropertyList(component.getProperties(), Parameter.CUTYPE); LOG.info(list.getProperties(CuType.INDIVIDUAL.getValue()).size() + " individual attendees."); } }
/** * {@inheritDoc} */ public void validate() throws ValidationException { for (final Iterator i = getObservances().iterator(); i.hasNext();) { final Observance observance = (Observance) i.next(); PropertyValidator.getInstance().assertOne(Property.DTSTART, observance.getProperties()); PropertyValidator.getInstance().assertOne(Property.TZOFFSETFROM, observance.getProperties()); PropertyValidator.getInstance().assertOne(Property.TZOFFSETTO, observance.getProperties()); PropertyValidator.getInstance().assertOneOrLess(Property.COMMENT, observance.getProperties()); PropertyValidator.getInstance().assertOneOrLess(Property.TZNAME, observance.getProperties()); } } }