Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
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;

Expand Down Expand Up @@ -56,7 +55,7 @@ public static <T> String determineChangesInAttributes(T oldObject, T newObject)
.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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class ReflectionUtil {

Expand Down Expand Up @@ -38,7 +37,7 @@ public static List<Field> retrieveAllFields(Class<?> currentClass) {
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.util.List;
import java.util.ServiceLoader;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;

public class SpiLoader {
Expand All @@ -13,6 +12,6 @@ private 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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ public static boolean shouldUseLowerCaseForAccessIds() {
public List<String> getAllClassificationCategories() {
return this.classificationCategoriesByType.values().stream()
.flatMap(Collection::stream)
.collect(Collectors.toList());
.toList();
}

public List<String> getClassificationCategoriesByType(String type) {
Expand Down Expand Up @@ -1353,18 +1353,15 @@ private void setFieldValue(Field field, Object value) {
}

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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
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;
Expand Down Expand Up @@ -34,8 +33,7 @@ public void runJobs() {

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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -25,7 +24,7 @@ public TaskStatusReport(List<TaskState> filter) {
super(
(filter != null ? filter.stream() : Stream.of(TaskState.values()))
.map(TaskStatusColumnHeader::new)
.collect(Collectors.toList()),
.toList(),
new String[] {"DOMAINS"});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
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;
Expand Down Expand Up @@ -91,7 +90,7 @@ public List<Integer> convertWorkingDaysToDays(int amountOfWorkdays) {
cacheDaysToWorkingDays.entrySet().stream()
.filter(entry -> entry.getValue() == amountOfWorkdays)
.map(Entry::getKey)
.collect(Collectors.toList());
.toList();
if (listOfAllMatchingDays.isEmpty()) {
return Collections.singletonList(amountOfWorkdays);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
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;
Expand Down Expand Up @@ -619,7 +618,7 @@ private List<SelectedItem> convertWorkingDaysToDays(
s.getSubKey(),
Collections.min(instance.convertWorkingDaysToDays(s.getLowerAgeLimit())),
Collections.max(instance.convertWorkingDaysToDays(s.getUpperAgeLimit()))))
.collect(Collectors.toList());
.toList();
}

private boolean subKeyIsSet(List<SelectedItem> selectedItems) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
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;
Expand Down Expand Up @@ -71,7 +70,7 @@ public TimestampReport buildReport() throws InvalidArgumentException, NotAuthori
// That's why "the loop" is done outside mybatis.
.map(this::getTasksCountForStatusGroupedByOrgLevel)
.flatMap(Collection::stream)
.collect(Collectors.toList());
.toList();

report.addItems(
items,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ void insertNewSecondaryObjectReferencesOnTaskCreation(TaskImpl task)
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) {
Expand All @@ -81,7 +79,7 @@ private void insertNewObjectReferencesOnTaskUpdate(TaskImpl newTaskImpl, TaskImp
List<ObjectReference> newObjectReferences =
newTaskImpl.getSecondaryObjectReferences().stream()
.filter(not(o -> oldObjectReferencesIds.contains(o.getId())))
.collect(Collectors.toList());
.toList();

for (ObjectReference objectReference : newObjectReferences) {
insertNewObjectReferenceOnTaskUpdate(newTaskImpl, objectReference);
Expand Down Expand Up @@ -115,8 +113,7 @@ private void deleteRemovedObjectReferencesOnTaskUpdate(
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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ public void refreshPriorityAndDueDatesOfTasks(
}
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);
}
Expand Down Expand Up @@ -214,7 +212,7 @@ private Map<Integer, List<String>> getPriorityToTasksIdsMap(
t.getTaskId(),
determinePriorityForATask(
t, classificationIdToPriorityMap, taskIdToClassificationIdsMap)))
.collect(Collectors.toList());
.toList();
return taskIdPriorities.stream()
.collect(
groupingBy(
Expand Down Expand Up @@ -425,8 +423,7 @@ private BulkLog updateDuePropertyOfAffectedTasks(
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());
Expand Down Expand Up @@ -565,9 +562,7 @@ private List<ClassificationWithServiceLevelResolved> resolveDurationsInClassific
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<>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,7 @@ public BulkOperationResults<String, TaskanaException> deleteTasks(List<String> t
}
if (historyEventManager.isEnabled()) {
taskIds.forEach(this::createTaskDeletedEvent);
}
}
}
return bulkLog;
} finally {
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 @@ -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
Loading