Добавил тесты проведения, повторного проведения и изменения сумм операций

This commit is contained in:
Kashey committed 2026-10-19 14:05:42 +03:00
1 parent d264ed6583
commit 8af851a49a
18 files changed
+303 -35

No files matched your search

+48
View File
@@ -0,0 +1,48 @@
package model;
import java.time.LocalDate;
import java.util.*;
public class OperationJournal {
private final Map<Long, Operation> operations = new HashMap<>();
public void saveOperation(Operation operation) {
if (operation == null) {
throw new IllegalArgumentException("Не указана операция для сохранения в журнал");
}
operations.put(operation.getId(), operation);
}
public Operation getOperationById(Long id) {
return operations.get(id);
}
public List<Operation> getOperationsBetweenDates(LocalDate dateFrom, LocalDate dateTo) {
if (dateFrom == null || dateTo == null) {
throw new IllegalArgumentException(
"Необходимо указать начало и конец периода"
);
}
if (dateFrom.isAfter(dateTo)) {
throw new IllegalArgumentException(
"Начало периода не может быть позже конца"
);
}
List<Operation> result = new ArrayList<>();
for (Operation operation : operations.values()) {
if (!operation.getDate().isBefore(dateFrom) && !operation.getDate().isAfter(dateTo)) {
result.add(operation);
}
}
result.sort(Comparator.comparing(Operation::getDate).thenComparing(Operation::getId));
return result;
}
}