Source:
<code>public synchronized boolean doTerminate() { Collection<ImmutableWorkerInfo> workers = runner.getWorkers(); Collection<? extends TaskRunnerWorkItem> pendingTasks = runner.getPendingTasks(); final DefaultWorkerBehaviorConfig workerConfig = ProvisioningUtil.getDefaultWorkerBehaviorConfig( workerConfigRef, "terminate" ); if (workerConfig == null) { log.info("No worker config found. Skip terminating."); return false; } boolean didTerminate = false; WorkerCategorySpec workerCategorySpec = ProvisioningUtil.getWorkerCategorySpec(workerConfig); Map<String, List<TaskRunnerWorkItem>> pendingTasksByCategories = groupTasksByCategories( pendingTasks, runner, workerCategorySpec ); Map<String, List<ImmutableWorkerInfo>> workersByCategories = ProvisioningUtil.getWorkersByCategories(workers); Set<String> allCategories = workersByCategories.keySet(); log.debug( "Workers of %d categories: %s", workersByCategories.size(), allCategories ); Map<String, AutoScaler> autoscalersByCategory = ProvisioningUtil.mapAutoscalerByCategory(workerConfig.getAutoScalers()); for (String category : allCategories) { AutoScaler categoryAutoscaler = ProvisioningUtil.getAutoscalerByCategory(category, autoscalersByCategory); if (categoryAutoscaler == null) { log.error("No autoScaler available, cannot execute doTerminate for workers of category %s", category); continue; } category = ProvisioningUtil.getAutoscalerCategory(categoryAutoscaler); List<ImmutableWorkerInfo> categoryWorkers = workersByCategories.getOrDefault(category, Collections.emptyList()); <START> currentlyProvisioningMap.putIfAbsent(category, new HashSet<>()); Set<String> currentlyProvisioning = this.currentlyProvisioningMap.get(category); currentlyTerminatingMap.putIfAbsent(category, new HashSet<>()); Set<String> currentlyTerminating = this.currentlyTerminatingMap.get(category); <END> List<? extends TaskRunnerWorkItem> categoryPendingTasks = pendingTasksByCategories.getOrDefault( category, Collections.emptyList() ); didTerminate = doTerminate( category, categoryWorkers, currentlyProvisioning, currentlyTerminating, categoryAutoscaler, categoryPendingTasks ) || didTerminate; } return didTerminate; }</code><technical_language>nit: HashSet instantiation</technical_language>

Target:
public synchronized boolean doTerminate() { Collection<ImmutableWorkerInfo> workers = runner.getWorkers(); Collection<? extends TaskRunnerWorkItem> pendingTasks = runner.getPendingTasks(); final DefaultWorkerBehaviorConfig workerConfig = ProvisioningUtil.getDefaultWorkerBehaviorConfig( workerConfigRef, "terminate" ); if (workerConfig == null) { log.info("No worker config found. Skip terminating."); return false; } boolean didTerminate = false; WorkerCategorySpec workerCategorySpec = ProvisioningUtil.getWorkerCategorySpec(workerConfig); Map<String, List<TaskRunnerWorkItem>> pendingTasksByCategories = groupTasksByCategories( pendingTasks, runner, workerCategorySpec ); Map<String, List<ImmutableWorkerInfo>> workersByCategories = ProvisioningUtil.getWorkersByCategories(workers); Set<String> allCategories = workersByCategories.keySet(); log.debug( "Workers of %d categories: %s", workersByCategories.size(), allCategories ); Map<String, AutoScaler> autoscalersByCategory = ProvisioningUtil.mapAutoscalerByCategory(workerConfig.getAutoScalers()); for (String category : allCategories) { AutoScaler categoryAutoscaler = ProvisioningUtil.getAutoscalerByCategory(category, autoscalersByCategory); if (categoryAutoscaler == null) { log.error("No autoScaler available, cannot execute doTerminate for workers of category %s", category); continue; } category = ProvisioningUtil.getAutoscalerCategory(categoryAutoscaler); List<ImmutableWorkerInfo> categoryWorkers = workersByCategories.getOrDefault(category, Collections.emptyList()); Set<String> currentlyProvisioning = this.currentlyProvisioningMap.computeIfAbsent( category, ignored -> new HashSet<>() ); Set<String> currentlyTerminating = this.currentlyTerminatingMap.computeIfAbsent( category, ignored -> new HashSet<>() ); List<? extends TaskRunnerWorkItem> categoryPendingTasks = pendingTasksByCategories.getOrDefault( category, Collections.emptyList() ); didTerminate = doTerminate( category, categoryWorkers, currentlyProvisioning, currentlyTerminating, categoryAutoscaler, categoryPendingTasks ) || didTerminate; } return didTerminate; }