Closes #2521 - Fix code smells Stream.collect(Collectors.toList()) to Stream.toList()

This commit is contained in:
Maria Margaritis 2024-03-05 16:26:55 +01:00 committed by MM1277
parent 9e547f8867
commit 1d8e87adf0
23 changed files with 44 additions and 87 deletions

View File

@ -7,7 +7,6 @@ import java.lang.reflect.Field;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;
import org.json.JSONObject;
import pro.taskana.common.api.exceptions.SystemException;
@ -56,7 +55,7 @@ public class ObjectAttributeChangeDetector {
.map(wrap(field -> Triplet.of(field, field.get(oldObject), field.get(newObject))))
.filter(not(t -> Objects.equals(t.getMiddle(), t.getRight())))
.map(t -> generateChangedAttribute(t.getLeft(), t.getMiddle(), t.getRight()))
.collect(Collectors.toList());
.toList();
JSONObject changes = new JSONObject();
changes.put("changes", changedAttributes);

View File

@ -10,7 +10,6 @@ import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
public class ReflectionUtil {
@ -38,7 +37,7 @@ public class ReflectionUtil {
fields.addAll(Arrays.asList(currentClass.getDeclaredFields()));
currentClass = currentClass.getSuperclass();
}
return fields.stream().filter(not(Field::isSynthetic)).collect(Collectors.toList());
return fields.stream().filter(not(Field::isSynthetic)).toList();
}
public static Class<?> getRawClass(Type type) {

View File

@ -2,7 +2,6 @@ package pro.taskana.common.internal.util;
import java.util.List;
import java.util.ServiceLoader;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
public class SpiLoader {
@ -13,6 +12,6 @@ public class SpiLoader {
public static <T> List<T> load(Class<T> clazz) {
ServiceLoader<T> serviceLoader = ServiceLoader.load(clazz);
return StreamSupport.stream(serviceLoader.spliterator(), false).collect(Collectors.toList());
return StreamSupport.stream(serviceLoader.spliterator(), false).toList();
}
}

View File

@ -238,7 +238,7 @@ public class TaskanaConfiguration {
public List<String> getAllClassificationCategories() {
return this.classificationCategoriesByType.values().stream()
.flatMap(Collection::stream)
.collect(Collectors.toList());
.toList();
}
public List<String> getClassificationCategoriesByType(String type) {
@ -1353,18 +1353,15 @@ public class TaskanaConfiguration {
}
private void adjustConfiguration() {
domains = domains.stream().map(String::toUpperCase).collect(Collectors.toList());
classificationTypes =
classificationTypes.stream().map(String::toUpperCase).collect(Collectors.toList());
domains = domains.stream().map(String::toUpperCase).toList();
classificationTypes = classificationTypes.stream().map(String::toUpperCase).toList();
classificationCategoriesByType =
classificationCategoriesByType.entrySet().stream()
.map(
e ->
Map.entry(
e.getKey().toUpperCase(),
e.getValue().stream()
.map(String::toUpperCase)
.collect(Collectors.toList())))
e.getValue().stream().map(String::toUpperCase).toList()))
.sorted(Comparator.comparingInt(e -> classificationTypes.indexOf(e.getKey())))
.collect(
Collectors.toMap(

View File

@ -3,7 +3,6 @@ package pro.taskana.common.internal.jobs;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.List;
import java.util.stream.Collectors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pro.taskana.common.api.ScheduledJob;
@ -34,8 +33,7 @@ public class JobRunner {
private List<ScheduledJob> findAndLockJobsToRun() {
return TaskanaTransactionProvider.executeInTransactionIfPossible(
txProvider,
() -> jobService.findJobsToRun().stream().map(this::lockJob).collect(Collectors.toList()));
txProvider, () -> jobService.findJobsToRun().stream().map(this::lockJob).toList());
}
private void runJobTransactionally(ScheduledJob scheduledJob) {

View File

@ -1,7 +1,6 @@
package pro.taskana.monitor.api.reports;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import pro.taskana.common.api.exceptions.NotAuthorizedException;
import pro.taskana.monitor.api.reports.header.ColumnHeader;
@ -25,7 +24,7 @@ public class TaskStatusReport extends Report<TaskQueryItem, TaskStatusColumnHead
super(
(filter != null ? filter.stream() : Stream.of(TaskState.values()))
.map(TaskStatusColumnHeader::new)
.collect(Collectors.toList()),
.toList(),
new String[] {"DOMAINS"});
}

View File

@ -7,7 +7,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.stream.Collectors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pro.taskana.common.api.WorkingTimeCalculator;
@ -91,7 +90,7 @@ public class WorkingDaysToDaysReportConverter {
cacheDaysToWorkingDays.entrySet().stream()
.filter(entry -> entry.getValue() == amountOfWorkdays)
.map(Entry::getKey)
.collect(Collectors.toList());
.toList();
if (listOfAllMatchingDays.isEmpty()) {
return Collections.singletonList(amountOfWorkdays);
}

View File

@ -5,7 +5,6 @@ import static pro.taskana.common.api.BaseQuery.toLowerCopy;
import java.time.Instant;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import pro.taskana.common.api.IntInterval;
import pro.taskana.common.api.TaskanaRole;
import pro.taskana.common.api.WorkingTimeCalculator;
@ -619,7 +618,7 @@ abstract class TimeIntervalReportBuilderImpl<
s.getSubKey(),
Collections.min(instance.convertWorkingDaysToDays(s.getLowerAgeLimit())),
Collections.max(instance.convertWorkingDaysToDays(s.getUpperAgeLimit()))))
.collect(Collectors.toList());
.toList();
}
private boolean subKeyIsSet(List<SelectedItem> selectedItems) {

View File

@ -5,7 +5,6 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
import pro.taskana.common.api.TaskanaRole;
import pro.taskana.common.api.exceptions.InvalidArgumentException;
import pro.taskana.common.api.exceptions.NotAuthorizedException;
@ -71,7 +70,7 @@ public class TimestampReportBuilderImpl
// That's why "the loop" is done outside mybatis.
.map(this::getTasksCountForStatusGroupedByOrgLevel)
.flatMap(Collection::stream)
.collect(Collectors.toList());
.toList();
report.addItems(
items,

View File

@ -56,9 +56,7 @@ public class ObjectReferenceHandler {
void insertAndDeleteObjectReferencesOnTaskUpdate(TaskImpl newTaskImpl, TaskImpl oldTaskImpl)
throws ObjectReferencePersistenceException, InvalidArgumentException {
List<ObjectReference> newObjectReferences =
newTaskImpl.getSecondaryObjectReferences().stream()
.filter(Objects::nonNull)
.collect(Collectors.toList());
newTaskImpl.getSecondaryObjectReferences().stream().filter(Objects::nonNull).toList();
newTaskImpl.setSecondaryObjectReferences(newObjectReferences);
for (ObjectReference objectReference : newObjectReferences) {
@ -81,7 +79,7 @@ public class ObjectReferenceHandler {
List<ObjectReference> newObjectReferences =
newTaskImpl.getSecondaryObjectReferences().stream()
.filter(not(o -> oldObjectReferencesIds.contains(o.getId())))
.collect(Collectors.toList());
.toList();
for (ObjectReference objectReference : newObjectReferences) {
insertNewObjectReferenceOnTaskUpdate(newTaskImpl, objectReference);
@ -115,8 +113,7 @@ public class ObjectReferenceHandler {
final List<ObjectReference> newObjectReferences = newTaskImpl.getSecondaryObjectReferences();
List<String> newObjectReferencesIds = new ArrayList<>();
if (newObjectReferences != null && !newObjectReferences.isEmpty()) {
newObjectReferencesIds =
newObjectReferences.stream().map(ObjectReference::getId).collect(Collectors.toList());
newObjectReferencesIds = newObjectReferences.stream().map(ObjectReference::getId).toList();
}
List<ObjectReference> oldObjectReferences = oldTaskImpl.getSecondaryObjectReferences();
if (oldObjectReferences != null && !oldObjectReferences.isEmpty()) {

View File

@ -71,9 +71,7 @@ class ServiceLevelHandler {
}
if (priorityChanged) {
List<MinimalTaskSummary> tasksWithoutManualPriority =
tasks.stream()
.filter(not(MinimalTaskSummary::isManualPriorityActive))
.collect(Collectors.toList());
tasks.stream().filter(not(MinimalTaskSummary::isManualPriorityActive)).toList();
updateTaskPriorityOnClassificationUpdate(
tasksWithoutManualPriority, attachments, allInvolvedClassifications);
}
@ -214,7 +212,7 @@ class ServiceLevelHandler {
t.getTaskId(),
determinePriorityForATask(
t, classificationIdToPriorityMap, taskIdToClassificationIdsMap)))
.collect(Collectors.toList());
.toList();
return taskIdPriorities.stream()
.collect(
groupingBy(
@ -425,8 +423,7 @@ class ServiceLevelHandler {
referenceTask.setPlanned(durationHolder.getPlanned());
referenceTask.setModified(Instant.now());
referenceTask.setDue(calculateDue(referenceTask.getPlanned(), durationHolder.getDuration()));
List<String> taskIdsToUpdate =
taskDurationList.stream().map(TaskDuration::getTaskId).collect(Collectors.toList());
List<String> taskIdsToUpdate = taskDurationList.stream().map(TaskDuration::getTaskId).toList();
Pair<List<MinimalTaskSummary>, BulkLog> existingAndAuthorizedTasks =
taskServiceImpl.getMinimalTaskSummaries(taskIdsToUpdate);
bulkLog.addAllErrors(existingAndAuthorizedTasks.getRight());
@ -565,9 +562,7 @@ class ServiceLevelHandler {
private List<AttachmentSummaryImpl> getAttachmentSummaries(
List<MinimalTaskSummary> existingTasksAuthorizedFor) {
List<String> existingTaskIdsAuthorizedFor =
existingTasksAuthorizedFor.stream()
.map(MinimalTaskSummary::getTaskId)
.collect(Collectors.toList());
existingTasksAuthorizedFor.stream().map(MinimalTaskSummary::getTaskId).toList();
return existingTaskIdsAuthorizedFor.isEmpty()
? new ArrayList<>()

View File

@ -707,7 +707,7 @@ public class TaskServiceImpl implements TaskService {
}
if (historyEventManager.isEnabled()) {
taskIds.forEach(this::createTaskDeletedEvent);
}
}
}
return bulkLog;
} finally {

View File

@ -8,7 +8,6 @@ import java.time.Instant;
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;
@ -108,7 +107,7 @@ public class TaskCleanupJob extends AbstractTaskanaJob {
.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()
@ -116,7 +115,7 @@ public class TaskCleanupJob extends AbstractTaskanaJob {
taskSummary ->
!taskIdsNotAllCompletedSameParentBusiness.contains(
taskSummary.getParentBusinessProcessId()))
.collect(Collectors.toList());
.toList();
}
return tasksToDelete;
@ -138,8 +137,7 @@ public class TaskCleanupJob extends AbstractTaskanaJob {
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()) {

View File

@ -89,7 +89,7 @@ public class UserServiceImpl implements UserService {
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

View File

@ -82,7 +82,7 @@ public class ServiceProviderExtractor {
List<Class<?>> serviceProviders, Map<Class<?>, Object> enclosingTestInstancesByClass) {
return serviceProviders.stream()
.map(clz -> instantiateClass(clz, enclosingTestInstancesByClass))
.collect(Collectors.toList());
.toList();
}
private static Object instantiateClass(

View File

@ -11,7 +11,6 @@ import java.util.List;
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;
@ -220,13 +219,13 @@ public class TaskanaRestExceptionHandler extends ResponseEntityExceptionHandler
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();
}
}
}

View File

@ -588,7 +588,7 @@ public class LdapClient {
.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 {

View File

@ -3,7 +3,6 @@ package pro.taskana.monitor.rest;
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;
@ -122,7 +121,7 @@ public class MonitorController {
List<PriorityColumnHeader> priorityColumnHeaders =
Arrays.stream(columnHeaders)
.map(priorityColumnHeaderRepresentationModelAssembler::toEntityModel)
.collect(Collectors.toList());
.toList();
builder.withColumnHeaders(priorityColumnHeaders);
}

View File

@ -10,7 +10,6 @@ import java.util.Objects;
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;
@ -111,7 +110,7 @@ public class TaskController {
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");
@ -715,17 +714,14 @@ public class TaskController {
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(

View File

@ -79,22 +79,16 @@ public class TaskRepresentationModelAssembler
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));
@ -186,13 +180,11 @@ public class TaskRepresentationModelAssembler
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)));

View File

@ -2,7 +2,6 @@ package pro.taskana.task.rest.assembler;
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;
@ -79,14 +78,12 @@ public class TaskSummaryRepresentationModelAssembler
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));
@ -146,14 +143,14 @@ public class TaskSummaryRepresentationModelAssembler
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());

View File

@ -3,7 +3,6 @@ package pro.taskana.user.jobs;
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;
@ -64,9 +63,7 @@ public class UserInfoRefreshJob extends AbstractTaskanaJob {
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);

View File

@ -4,7 +4,6 @@ import jakarta.servlet.http.HttpServletRequest;
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;
@ -313,7 +312,7 @@ public class WorkbasketController {
List<WorkbasketAccessItem> wbAccessItems =
workbasketAccessItemRepModels.getContent().stream()
.map(workbasketAccessItemRepresentationModelAssembler::toEntityModel)
.collect(Collectors.toList());
.toList();
workbasketService.setWorkbasketAccessItems(workbasketId, wbAccessItems);
List<WorkbasketAccessItem> updatedWbAccessItems =
workbasketService.getWorkbasketAccessItems(workbasketId);