@SuppressWarnings("MixedMutabilityReturnType")
  @Override public List<List<Span>> map(List<Span> input) {
    if (input.isEmpty()) return Collections.emptyList();

    Map<String, List<Span>> groupedByTraceId = new LinkedHashMap<>();
    for (Span span : input) {
      String traceId = span.traceId();
      if (!strictTraceId) traceId = lowerTraceId(traceId);
      if (!groupedByTraceId.containsKey(traceId)) {
        groupedByTraceId.put(traceId, new ArrayList<>());
      }
      groupedByTraceId.get(traceId).add(span);
    }
    // Modifiable so that StrictTraceId can filter without allocating a new list
    return new ArrayList<>(groupedByTraceId.values());
  }
A mapper that groups unorganized input spans by trace ID. Useful when preparing a result for
{@link SpanStore#getTraces(QueryRequest)}.
zipkin/src/main/java/zipkin2/storage/GroupByTraceId.java