code: public static Collection<CommunicationSummaryStatistics> buildCommunicationSummaryTree(
              Collection<CommunicationSummaryStatistics> nodes, Set<String> endpoints) {
          Map<String, CommunicationSummaryStatistics> nodeMap = new HashMap<String, CommunicationSummaryStatistics>();
  
          // Create a map of nodes
          for (CommunicationSummaryStatistics css : nodes) {
              nodeMap.put(css.getId(), css);
          }
  
          List<CommunicationSummaryStatistics> ret = new ArrayList<>();
          for (String endpoint : endpoints) {
              // Check if a 'client' node also exists for the endpoint, and if so, use this as the
              // initial endpoint
              CommunicationSummaryStatistics n = nodeMap.get(EndpointUtil.encodeClientURI(endpoint));
              if (n == null) {
                  n = nodeMap.get(endpoint);
              }
              if (n != null) {
                  CommunicationSummaryStatistics rootNode = new CommunicationSummaryStatistics(n);
                  initCommunicationSummaryTreeNode(rootNode, nodeMap,
                          new HashSet<>(Collections.singleton(rootNode.getId())));
                  ret.add(rootNode);
              }
          }
  
          return ret;
      }
docs: This method returns the supplied list of flat nodes as a set of tree structures with related nodes.
  
  @param nodes The collection of nodes represented as a flat list
  @param endpoints The initial endpoints
  @return The nodes returns as a collection of independent tree structures