ResolvedTracingResult (@NotNull ResolverFactory resolverFactory) { assert myTrace.size() == mySourceChain.length(); List<ValuesOrderResolver.Result> resolvedTraces = ContainerUtil.map(myTrace, x -> resolverFactory.getResolver(x.getCall().getName()).resolve(x)); final TraceInfo firstCallTrace = myTrace.get(0); final List<IntermediateStreamCall> intermediateCalls = mySourceChain.getIntermediateCalls(); final ResolvedStreamChainImpl.Builder chainBuilder = new ResolvedStreamChainImpl.Builder(); final List<TraceElement> valuesBeforeFirstCall = TraceUtil.sortedByTime(firstCallTrace.getValuesOrderBefore().values()); final FirstStateImpl firstState = new FirstStateImpl(valuesBeforeFirstCall, firstCallTrace.getCall(), resolvedTraces.get(0).getDirectOrder()); if (intermediateCalls.isEmpty()) { chainBuilder.setTerminator(buildResolvedTerminationCall(myTrace.get(0), firstState, resolvedTraces.get(0).getReverseOrder())); } else { final ArrayList<IntermediateStateImpl> states = new ArrayList<>(); for (int i = 0; i < intermediateCalls.size() - 1; i++) { states.add(new IntermediateStateImpl(TraceUtil.sortedByTime(myTrace.get(i).getValuesOrderAfter().values()), intermediateCalls.get(i), intermediateCalls.get(i + 1), resolvedTraces.get(i).getReverseOrder(), resolvedTraces.get(i + 1).getDirectOrder())); } states.add(new IntermediateStateImpl(TraceUtil.sortedByTime(myTrace.get(myTrace.size() - 1).getValuesOrderBefore().values()), intermediateCalls.get(intermediateCalls.size() - 1), mySourceChain.getTerminationCall(), resolvedTraces.get(resolvedTraces.size() - 2).getReverseOrder(), resolvedTraces.get(resolvedTraces.size() - 1).getDirectOrder())); chainBuilder.addIntermediate(new ResolvedIntermediateCallImpl(intermediateCalls.get(0), firstState, states.get(0))); for (int i = 1; i < states.size(); i++) { chainBuilder.addIntermediate(new ResolvedIntermediateCallImpl(intermediateCalls.get(i), states.get(i - 1), states.get(i))); } chainBuilder.setTerminator(buildResolvedTerminationCall(myTrace.get(myTrace.size() - 1), states.get(states.size() - 1), resolvedTraces.get(resolvedTraces.size() - 1).getReverseOrder())); } return new MyResolvedResult(chainBuilder.build()); }