简体   繁体   中英

ical4j - Find Event based on the UID

I´m using ical4j to create my .ical - File and save events. But how can I find a stored VEvent in the calendar?

I have the following code, but it´s not working? I got my calendar -> this is working and I debug this already

public VEvent findEvent(CalendarExtern calendarExtern, String hashId) throws IOException, ParserException {

    Calendar calendar = readCalenderFromFile(calendarExtern);

    for (Component component : calendar.getComponents(Component.VEVENT)) {
          if (hashId.equals(component.getProperty(Property.UID))) {
              VEvent event = (VEvent) component;
                return event;
          }
        } 

    return null;
}

Any ideas? Many thanks

component.getProperty(Property.UID) returns a Property so what you really want to do is:

if (hashId.equals(component.getProperty(Property.UID).getValue()))...

Of course you, depending on your input, you may want to check for components without a UID property before doing getValue().

Alternative approach using a ComponentGroup to find the latest revision of an event:

ComponentGroup<VEvent> group = new ComponentGroup(
         calendar.getComponents(Component.VEVENT),
         new Uid(hashId));

return group.getLatestRevision();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM