/** * Returns the {@link InvocationTreeElement} of the given lookup map which contains the given * data object. <code>null</code> is returned if no {@link InvocationTreeElement} matches. * * @param lookupMap * the lookup map * @param object * the data object to search * @return the {@link InvocationTreeElement} related to the given data object */ public static InvocationTreeElement lookupTreeElement(Map<Object, InvocationTreeElement> lookupMap, Object object) { if (lookupMap == null) { return null; } return lookupMap.get(calculateLookupKey(object)); }
/** * Builds the {@link #lookupMap} map of the given tree. This allows direct access to the tree * elements via data objects. * * @param tree * the tree * @return the lookup map for the given tree */ public static Map<Object, InvocationTreeElement> buildLookupMap(InvocationTreeElement tree) { return InvocationTreeUtil.getRoot(tree).asStream().collect(Collectors.toMap(e -> calculateLookupKey(e.getDataElement()), Function.identity())); }
/** * {@inheritDoc} */ @Override public ElementOccurrenceCount countOccurrences(Object element, ViewerFilter[] filters) { InvocationTreeContentProvider contentProvider = (InvocationTreeContentProvider) getContentProvider(); // count span occurence if (element instanceof Span) { boolean containsSpan = contentProvider.getLookupMap().containsKey(InvocationTreeUtil.calculateLookupKey(element)); if (containsSpan) { ElementOccurrenceCount elementCount = new ElementOccurrenceCount(); elementCount.increaseVisibleOccurrences(); return elementCount; } } // count invocation occurence if (contentProvider.getRootElement() != null) { List<InvocationSequenceData> sequences; sequences = InvocationTreeUtil.getInvocationSequences(contentProvider.getRootElement()); return OccurrenceFinderFactory.getOccurrenceCount(sequences, element, filters); } return ElementOccurrenceCount.emptyElement(); }