public TimelineEvent<E> merge(TimelineEvent<E> event, Collection<TimelineEvent<E>> events, TimelineUpdater timelineUpdater) {
        if (event == null) {
            // nothing to merge
            return null;
        }

        if (events == null || events.isEmpty()) {
            // nothing to merge
            return event;
        }

        // check whether all events within the same group
        String group = event.getGroup();
        for (TimelineEvent<E> e : events) {
            if ((group == null && e.getGroup() != null) || (group != null && !group.equals(e.getGroup()))) {
                throw new IllegalStateException("Events to be merged may be only belong to one and the same group!");
            }
        }

        // order events according to their start / end dates
        TreeSet<TimelineEvent<E>> orderedEvents = new TreeSet<>(new TimelineEventComparator());
        orderedEvents.add(event);
        orderedEvents.addAll(events);

        // find the largest end date
        LocalDateTime endDate = orderedEvents.stream()
                .map(TimelineEvent::getEndDate)
                .filter(Objects::nonNull)
                .max(LocalDateTime::compareTo)
                .orElse(null);

        TimelineEvent<E> mergedEvent = TimelineEvent.<E>builder()
                .data(event.getData())
                .startDate(orderedEvents.first().getStartDate())
                .endDate(endDate)
                .editable(event.isEditable())
                .group(event.getGroup())
                .styleClass(event.getStyleClass())
                .build();

        // merge...
        deleteAll(events, timelineUpdater);
        update(mergedEvent, timelineUpdater);

        return mergedEvent;
    }
Merge the given one event with the given collection of events with UI update. Only events within one group can be merged.
Note: after merging, the merged event will get the same properties as the given one event except start and end dates.

@param event           given event to be merged with collection of events
@param events          collection of events
@param timelineUpdater TimelineUpdater instance to update the merged events in UI
@return TimelineEvent result event after merging
@throws IllegalStateException thrown if not all events are within the same group
primefaces/src/main/java/org/primefaces/model/timeline/TimelineModel.java