Source:
public static List<ProcessVariableSummary> adaptCollection(List<VariableInstance> variables, Map<String, String> properties, long processInstanceId, String deploymentId, String serverTemplateId, String sortBy, boolean asc) { List<VariableInstance> filteredVariables = variables.stream() .filter(variable -> !excludedVariables.contains(variable.getVariableName())) .collect(Collectors.toList()); List<ProcessVariableSummary> variablesSummary = new ArrayList<>(); properties.forEach((key, value) -> { VariableProcessor processor = processors.getOrDefault(value, new DefaultVariableProcessor()); processor.process(processInstanceId, key, value, filteredVariables, deploymentId, serverTemplateId, variableSummary -> variablesSummary.add(variableSummary)); }); variablesSummary.addAll(ofNullable(filteredVariables).orElse(emptyList()) .stream() .map(new ProcessInstanceVariableMapper(deploymentId, serverTemplateId, "")) .collect(Collectors.toList())); Comparator<ProcessVariableSummary> comparator; switch (ofNullable(sortBy).orElse(COL_PROCESS_INSTANCE_VAR_ID)) { case COL_PROCESS_INSTANCE_VAR_ID: comparator = comparing(ProcessVariableSummary::getVariableId); break; case COL_PROCESS_INSTANCE_VAR_VALUE: comparator = comparing(ProcessVariableSummary::getNewValue); break; case COL_PROCESS_INSTANCE_VAR_TYPE: comparator = comparing(ProcessVariableSummary::getType); break; case COL_PROCESS_INSTANCE_VAR_LASTMOD: comparator = comparing(ProcessVariableSummary::getTimestamp); break; default: comparator = comparing(ProcessVariableSummary::getName); } variablesSummary.sort(!asc ? comparator : comparator.reversed()); return variablesSummary; }

Target:
public static List<ProcessVariableSummary> adaptCollection(List<VariableInstance> variables, Map<String, String> properties, long processInstanceId, String deploymentId, String serverTemplateId, String sortBy, boolean asc) { List<VariableInstance> filteredVariables = variables.stream() .filter(variable -> !excludedVariables.contains(variable.getVariableName())) .collect(Collectors.toList()); List<ProcessVariableSummary> variablesSummary = new ArrayList<>(); properties.forEach((key, value) -> { VariableProcessor processor = processors.getOrDefault(value, new DefaultVariableProcessor()); processor.process(processInstanceId, key, value, filteredVariables, deploymentId, serverTemplateId, variableSummary -> variablesSummary.add(variableSummary)); }); variablesSummary.addAll(ofNullable(filteredVariables).orElse(emptyList()) .stream() .map(new ProcessInstanceVariableMapper(deploymentId, serverTemplateId, "")) .collect(Collectors.toList())); Comparator<ProcessVariableSummary> comparator; switch (ofNullable(sortBy).orElse(COL_PROCESS_INSTANCE_VAR_ID)) { case COL_PROCESS_INSTANCE_VAR_ID: comparator = comparing(ProcessVariableSummary::getVariableId); break; case COL_PROCESS_INSTANCE_VAR_VALUE: comparator = comparing(ProcessVariableSummary::getNewValue); break; case COL_PROCESS_INSTANCE_VAR_TYPE: comparator = comparing(ProcessVariableSummary::getType); break; case COL_PROCESS_INSTANCE_VAR_LASTMOD: comparator = comparing(ProcessVariableSummary::getTimestamp); break; default: comparator = comparing(ProcessVariableSummary::getName); } variablesSummary.sort(asc ? comparator : comparator.reversed()); return variablesSummary; }