private void findAndAddParentsIfNecessary(Map<String, EventInformation> allEventsMap, Map<String, EventInformation> relatedEventsMap, Map<String, EventInformation> eventsToAddMap, EventInformation event) { Set<String> parentIds = event.getParentIds(); for (String parentId : parentIds) { if (!relatedEventsMap.containsKey(parentId) && !eventsToAddMap.containsKey(parentId)) { // find and add parent to relatedEventsMap EventInformation parent = allEventsMap.get(parentId); if (parent == null) { throw new RuntimeException("Failed to find parent event: logged event information may be corrupted."); } eventsToAddMap.put(parent.getEventId(), parent); // newly found parent event may have parent event(s) as well... find them as well findAndAddParentsIfNecessary(allEventsMap, relatedEventsMap, eventsToAddMap, parent); } } }
public Map<String, EventInformationTreeNode> constructEventTreeAsMap(String rootEventId) { Stream<EventInformation> eventsAssociatedToRootEventStream = events.stream().filter(e -> { boolean isRootEvent = e.getEventId().equals(rootEventId); boolean containsRootEvent = e.getRootIds() != null && e.getRootIds().contains(rootEventId); return isRootEvent || containsRootEvent; }); Map<String, EventInformationTreeNode> nodes = eventsAssociatedToRootEventStream.collect( toMap(EventInformation::getEventId, EventInformationTreeNode::new)); nodes.forEach((eventId, node) -> { Set<String> parentIds = node.getEventInformation().getParentIds(); parentIds.forEach(parentId -> { EventInformationTreeNode parentNode = nodes.get(parentId); // parent will not be in nodes when parent is originated to another root event // if it's the case, just ignore it if (parentNode != null) { parentNode.addChild(node); } }); }); return nodes; }
@Override public int hashCode() { int result = (int) (getTimestamp() ^ (getTimestamp() >>> 32)); result = 31 * result + (getComponentName() != null ? getComponentName().hashCode() : 0); result = 31 * result + (getStreamId() != null ? getStreamId().hashCode() : 0); result = 31 * result + (getTargetComponents() != null ? getTargetComponents().hashCode() : 0); result = 31 * result + (getEventId() != null ? getEventId().hashCode() : 0); result = 31 * result + (getRootIds() != null ? getRootIds().hashCode() : 0); result = 31 * result + (getParentIds() != null ? getParentIds().hashCode() : 0); result = 31 * result + (getFieldsAndValues() != null ? getFieldsAndValues().hashCode() : 0); return result; }
@Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof EventInformation)) return false; EventInformation that = (EventInformation) o; if (getTimestamp() != that.getTimestamp()) return false; if (getComponentName() != null ? !getComponentName().equals(that.getComponentName()) : that.getComponentName() != null) return false; if (getStreamId() != null ? !getStreamId().equals(that.getStreamId()) : that.getStreamId() != null) return false; if (getTargetComponents() != null ? !getTargetComponents().equals(that.getTargetComponents()) : that.getTargetComponents() != null) return false; if (getEventId() != null ? !getEventId().equals(that.getEventId()) : that.getEventId() != null) return false; if (getRootIds() != null ? !getRootIds().equals(that.getRootIds()) : that.getRootIds() != null) return false; if (getParentIds() != null ? !getParentIds().equals(that.getParentIds()) : that.getParentIds() != null) return false; return getFieldsAndValues() != null ? getFieldsAndValues().equals(that.getFieldsAndValues()) : that.getFieldsAndValues() == null; }