Skip to content

Commit

Permalink
Closes Taskana#2521 - Fix code smells Stream.collect(Collectors.toLis…
Browse files Browse the repository at this point in the history
…t()) to Stream.toList()
  • Loading branch information
mmenv authored and MM1277 committed Mar 12, 2024
1 parent 15ecc95 commit f9c1bd9
Show file tree
Hide file tree
Showing 13 changed files with 26 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1049,9 +1049,7 @@ public List<String> findTasksIdsAffectedByClassificationChange(String classifica

// tasks indirectly affected via attachments
List<Pair<String, Instant>> affectedPairs =
tasksAffectedDirectly.stream()
.map(t -> Pair.of(t.getId(), t.getPlanned()))
.collect(Collectors.toList());
tasksAffectedDirectly.stream().map(t -> Pair.of(t.getId(), t.getPlanned())).toList();
// tasks indirectly affected via attachments
List<Pair<String, Instant>> taskIdsAndPlannedFromAttachments =
attachmentMapper.findTaskIdsAndPlannedAffectedByClassificationChange(classificationId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pro.taskana.TaskanaConfiguration;
Expand Down Expand Up @@ -108,15 +107,15 @@ private List<TaskSummary> getTasksCompletedBefore(Instant untilDate) {
.filter(not(entry -> entry.getKey().isEmpty()))
.filter(not(entry -> entry.getValue().equals(countParentTask.get(entry.getKey()))))
.map(Map.Entry::getKey)
.collect(Collectors.toList());
.toList();

tasksToDelete =
tasksToDelete.stream()
.filter(
taskSummary ->
!taskIdsNotAllCompletedSameParentBusiness.contains(
taskSummary.getParentBusinessProcessId()))
.collect(Collectors.toList());
.toList();
}

return tasksToDelete;
Expand All @@ -138,8 +137,7 @@ private int deleteTasksTransactionally(List<TaskSummary> tasksToBeDeleted) {
private int deleteTasks(List<TaskSummary> tasksToBeDeleted)
throws InvalidArgumentException, NotAuthorizedException {

List<String> tasksIdsToBeDeleted =
tasksToBeDeleted.stream().map(TaskSummary::getId).collect(Collectors.toList());
List<String> tasksIdsToBeDeleted = tasksToBeDeleted.stream().map(TaskSummary::getId).toList();
BulkOperationResults<String, TaskanaException> results =
taskanaEngineImpl.getTaskService().deleteTasks(tasksIdsToBeDeleted);
if (LOGGER.isDebugEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public List<User> getUsers(Set<String> userIds) throws InvalidArgumentException

users.forEach(user -> user.setDomains(determineDomains(user)));

return users.stream().map(User.class::cast).collect(Collectors.toList());
return users.stream().map(User.class::cast).toList();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private static List<Object> instantiateServiceProviders(
List<Class<?>> serviceProviders, Map<Class<?>, Object> enclosingTestInstancesByClass) {
return serviceProviders.stream()
.map(clz -> instantiateClass(clz, enclosingTestInstancesByClass))
.collect(Collectors.toList());
.toList();
}

private static Object instantiateClass(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.springframework.beans.BeanInstantiationException;
import org.springframework.beans.TypeMismatchException;
Expand Down Expand Up @@ -220,13 +219,13 @@ private List<MalformedQueryParameter> extractMalformedQueryParameters(FieldError
Arrays.stream(targetType.getEnumConstants())
.map(Enum.class::cast)
.map(Enum::name)
.collect(Collectors.toList());
.toList();
Set<String> enumConstantSet = new HashSet<>(enumConstants);

return getRejectedValues(typeMismatchException)
.filter(not(enumConstantSet::contains))
.map(value -> new MalformedQueryParameter(queryParameter, value, enumConstants))
.collect(Collectors.toList());
.toList();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ List<LdapSettings> checkForMissingConfigurations() {
.filter(not(LdapSettings.TASKANA_LDAP_GROUPS_OF_USER_NAME::equals))
.filter(not(LdapSettings.TASKANA_LDAP_GROUPS_OF_USER_TYPE::equals))
.filter(p -> p.getValueFromEnv(env) == null)
.collect(Collectors.toList());
.toList();
}

void testMinSearchForLength(final String name) throws InvalidArgumentException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.hateoas.config.EnableHypermediaSupport;
import org.springframework.http.HttpStatus;
Expand Down Expand Up @@ -122,7 +121,7 @@ public ResponseEntity<ReportRepresentationModel> computePriorityWorkbasketReport
List<PriorityColumnHeader> priorityColumnHeaders =
Arrays.stream(columnHeaders)
.map(priorityColumnHeaderRepresentationModelAssembler::toEntityModel)
.collect(Collectors.toList());
.toList();
builder.withColumnHeaders(priorityColumnHeaders);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Component;
import pro.taskana.common.api.exceptions.InvalidArgumentException;
Expand Down Expand Up @@ -186,7 +185,7 @@ ReportRepresentationModel toReportResource(Report<I, H> report, Instant time) {
.sorted(Comparator.comparing(e -> e.getKey().toLowerCase()))
.map(i -> transformRow(i, new String[report.getRowDesc().length], 0))
.flatMap(Collection::stream)
.collect(Collectors.toList());
.toList();

List<RowRepresentationModel> sumRow =
transformRow(report.getSumRow(), new String[report.getRowDesc().length], 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import java.util.Optional;
import java.util.Set;
import java.util.function.BiConsumer;
import java.util.stream.Collectors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.hateoas.config.EnableHypermediaSupport;
import org.springframework.hateoas.config.EnableHypermediaSupport.HypermediaType;
Expand Down Expand Up @@ -111,7 +110,7 @@ public ResponseEntity<TaskRepresentationModel> createTask(
if (!taskRepresentationModel.getAttachments().stream()
.filter(att -> Objects.nonNull(att.getTaskId()))
.filter(att -> !att.getTaskId().equals(taskRepresentationModel.getTaskId()))
.collect(Collectors.toList())
.toList()
.isEmpty()) {
throw new InvalidArgumentException(
"An attachments' taskId must be empty or equal to the id of the task it belongs to");
Expand Down Expand Up @@ -715,17 +714,14 @@ public ResponseEntity<TaskSummaryCollectionRepresentationModel> deleteTasks(

List<TaskSummary> taskSummaries = query.list();

List<String> taskIdsToDelete =
taskSummaries.stream().map(TaskSummary::getId).collect(Collectors.toList());
List<String> taskIdsToDelete = taskSummaries.stream().map(TaskSummary::getId).toList();

BulkOperationResults<String, TaskanaException> result =
taskService.deleteTasks(taskIdsToDelete);

Set<String> failedIds = new HashSet<>(result.getFailedIds());
List<TaskSummary> successfullyDeletedTaskSummaries =
taskSummaries.stream()
.filter(not(summary -> failedIds.contains(summary.getId())))
.collect(Collectors.toList());
taskSummaries.stream().filter(not(summary -> failedIds.contains(summary.getId()))).toList();

return ResponseEntity.ok(
taskSummaryRepresentationModelAssembler.toTaskanaCollectionModel(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,22 +79,16 @@ public TaskRepresentationModel toModel(Task task) {
repModel.setSecondaryObjectReferences(
task.getSecondaryObjectReferences().stream()
.map(objectReferenceAssembler::toModel)
.collect(Collectors.toList()));
.toList());
repModel.setRead(task.isRead());
repModel.setTransferred(task.isTransferred());
repModel.setGroupByCount(task.getGroupByCount());
repModel.setAttachments(
task.getAttachments().stream()
.map(attachmentAssembler::toModel)
.collect(Collectors.toList()));
task.getAttachments().stream().map(attachmentAssembler::toModel).toList());
repModel.setCustomAttributes(
task.getCustomAttributeMap().entrySet().stream()
.map(CustomAttribute::of)
.collect(Collectors.toList()));
task.getCustomAttributeMap().entrySet().stream().map(CustomAttribute::of).toList());
repModel.setCallbackInfo(
task.getCallbackInfo().entrySet().stream()
.map(CustomAttribute::of)
.collect(Collectors.toList()));
task.getCallbackInfo().entrySet().stream().map(CustomAttribute::of).toList());
repModel.setCustom1(task.getCustomField(TaskCustomField.CUSTOM_1));
repModel.setCustom2(task.getCustomField(TaskCustomField.CUSTOM_2));
repModel.setCustom3(task.getCustomField(TaskCustomField.CUSTOM_3));
Expand Down Expand Up @@ -186,13 +180,11 @@ public Task toEntityModel(TaskRepresentationModel repModel) throws InvalidArgume
task.setCustomIntField(TaskCustomIntField.CUSTOM_INT_7, repModel.getCustomInt7());
task.setCustomIntField(TaskCustomIntField.CUSTOM_INT_8, repModel.getCustomInt8());
task.setAttachments(
repModel.getAttachments().stream()
.map(attachmentAssembler::toEntityModel)
.collect(Collectors.toList()));
repModel.getAttachments().stream().map(attachmentAssembler::toEntityModel).toList());
task.setSecondaryObjectReferences(
repModel.getSecondaryObjectReferences().stream()
.map(objectReferenceAssembler::toEntity)
.collect(Collectors.toList()));
.toList());
task.setCustomAttributeMap(
repModel.getCustomAttributes().stream()
.collect(Collectors.toMap(CustomAttribute::getKey, CustomAttribute::getValue)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Component;
Expand Down Expand Up @@ -79,14 +78,12 @@ public TaskSummaryRepresentationModel toModel(@NonNull TaskSummary taskSummary)
repModel.setSecondaryObjectReferences(
taskSummary.getSecondaryObjectReferences().stream()
.map(objectReferenceAssembler::toModel)
.collect(Collectors.toList()));
.toList());
repModel.setRead(taskSummary.isRead());
repModel.setTransferred(taskSummary.isTransferred());
repModel.setGroupByCount(taskSummary.getGroupByCount());
repModel.setAttachmentSummaries(
taskSummary.getAttachmentSummaries().stream()
.map(attachmentAssembler::toModel)
.collect(Collectors.toList()));
taskSummary.getAttachmentSummaries().stream().map(attachmentAssembler::toModel).toList());
repModel.setCustom1(taskSummary.getCustomField(TaskCustomField.CUSTOM_1));
repModel.setCustom2(taskSummary.getCustomField(TaskCustomField.CUSTOM_2));
repModel.setCustom3(taskSummary.getCustomField(TaskCustomField.CUSTOM_3));
Expand Down Expand Up @@ -146,14 +143,14 @@ public TaskSummary toEntityModel(TaskSummaryRepresentationModel repModel) {
taskSummary.setSecondaryObjectReferences(
repModel.getSecondaryObjectReferences().stream()
.map(objectReferenceAssembler::toEntity)
.collect(Collectors.toList()));
.toList());
taskSummary.setRead(repModel.isRead());
taskSummary.setTransferred(repModel.isTransferred());
taskSummary.setGroupByCount(repModel.getGroupByCount());
taskSummary.setAttachmentSummaries(
repModel.getAttachmentSummaries().stream()
.map(attachmentAssembler::toEntityModel)
.collect(Collectors.toList()));
.toList());
taskSummary.setCustom1(repModel.getCustom1());
taskSummary.setCustom2(repModel.getCustom2());
taskSummary.setCustom3(repModel.getCustom3());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.sql.PreparedStatement;
import java.time.Duration;
import java.util.List;
import java.util.stream.Collectors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pro.taskana.TaskanaConfiguration;
Expand Down Expand Up @@ -64,9 +63,7 @@ protected void execute() {

List<User> users = ldapClient.searchUsersInUserRole();
List<User> usersAfterProcessing =
users.stream()
.map(refreshUserPostprocessorManager::processUserAfterRefresh)
.collect(Collectors.toList());
users.stream().map(refreshUserPostprocessorManager::processUserAfterRefresh).toList();
addExistingConfigurationDataToUsers(usersAfterProcessing);
clearExistingUsersAndGroupsAndPermissions();
insertNewUsers(usersAfterProcessing);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.beans.ConstructorProperties;
import java.util.List;
import java.util.function.BiConsumer;
import java.util.stream.Collectors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -313,7 +312,7 @@ public ResponseEntity<WorkbasketAccessItemCollectionRepresentationModel> setWork
List<WorkbasketAccessItem> wbAccessItems =
workbasketAccessItemRepModels.getContent().stream()
.map(workbasketAccessItemRepresentationModelAssembler::toEntityModel)
.collect(Collectors.toList());
.toList();
workbasketService.setWorkbasketAccessItems(workbasketId, wbAccessItems);
List<WorkbasketAccessItem> updatedWbAccessItems =
workbasketService.getWorkbasketAccessItems(workbasketId);
Expand Down

0 comments on commit f9c1bd9

Please sign in to comment.