private static Stream<ResourceWithInstance> pairWithResources(boolean globalConcurrencyEnabled, InstanceState instanceState, Map<WorkflowId, Workflow> workflows, WorkflowResourceDecorator resourceDecorator) { final Optional<Workflow> workflowOpt = Optional.ofNullable(workflows.get(instanceState.workflowInstance().workflowId())); final Set<String> workflowResources = workflowResources(globalConcurrencyEnabled, workflowOpt); return workflowOpt .map(workflow -> resourceDecorator.decorateResources( instanceState.runState(), workflow.configuration(), workflowResources)) .orElse(workflowResources).stream() .map(resource -> ResourceWithInstance.create(resource, instanceState)); }