Skip to content

Commit

Permalink
Менеджер задач - ФЗ-5
Browse files Browse the repository at this point in the history
Выделение интерфейсов TaskManager и HistoryManager, покрытие тестами
  • Loading branch information
OlgaPegushina committed Nov 9, 2024
1 parent 948eeab commit 06d0867
Show file tree
Hide file tree
Showing 11 changed files with 844 additions and 244 deletions.
124 changes: 124 additions & 0 deletions .idea/uiDesigner.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 49 additions & 0 deletions java-kanban.iml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,57 @@
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/tests" isTestSource="true" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library" scope="TEST">
<library name="JUnit5.8.1">
<CLASSES>
<root url="jar://$MODULE_DIR$/lib/junit-jupiter-5.8.1.jar!/" />
<root url="jar://$MODULE_DIR$/lib/junit-jupiter-api-5.8.1.jar!/" />
<root url="jar://$MODULE_DIR$/lib/opentest4j-1.2.0.jar!/" />
<root url="jar://$MODULE_DIR$/lib/junit-platform-commons-1.8.1.jar!/" />
<root url="jar://$MODULE_DIR$/lib/apiguardian-api-1.1.2.jar!/" />
<root url="jar://$MODULE_DIR$/lib/junit-jupiter-params-5.8.1.jar!/" />
<root url="jar://$MODULE_DIR$/lib/junit-jupiter-engine-5.8.1.jar!/" />
<root url="jar://$MODULE_DIR$/lib/junit-platform-engine-1.8.1.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library" scope="TEST">
<library name="JUnit5.8.1">
<CLASSES>
<root url="jar://$MODULE_DIR$/lib/junit-jupiter-5.8.1.jar!/" />
<root url="jar://$MODULE_DIR$/lib/junit-jupiter-api-5.8.1.jar!/" />
<root url="jar://$MODULE_DIR$/lib/opentest4j-1.2.0.jar!/" />
<root url="jar://$MODULE_DIR$/lib/junit-platform-commons-1.8.1.jar!/" />
<root url="jar://$MODULE_DIR$/lib/apiguardian-api-1.1.2.jar!/" />
<root url="jar://$MODULE_DIR$/lib/junit-jupiter-params-5.8.1.jar!/" />
<root url="jar://$MODULE_DIR$/lib/junit-jupiter-engine-5.8.1.jar!/" />
<root url="jar://$MODULE_DIR$/lib/junit-platform-engine-1.8.1.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library" scope="TEST">
<library name="JUnit5.8.1">
<CLASSES>
<root url="jar://$MODULE_DIR$/lib/junit-jupiter-5.8.1.jar!/" />
<root url="jar://$MODULE_DIR$/lib/junit-jupiter-api-5.8.1.jar!/" />
<root url="jar://$MODULE_DIR$/lib/opentest4j-1.2.0.jar!/" />
<root url="jar://$MODULE_DIR$/lib/junit-platform-commons-1.8.1.jar!/" />
<root url="jar://$MODULE_DIR$/lib/apiguardian-api-1.1.2.jar!/" />
<root url="jar://$MODULE_DIR$/lib/junit-jupiter-params-5.8.1.jar!/" />
<root url="jar://$MODULE_DIR$/lib/junit-jupiter-engine-5.8.1.jar!/" />
<root url="jar://$MODULE_DIR$/lib/junit-platform-engine-1.8.1.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
</component>
</module>
101 changes: 42 additions & 59 deletions src/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
import model.Status;
import model.Subtask;
import model.Task;
import service.HistoryManager;
import service.InMemoryTaskManager;
import service.Managers;
import service.TaskManager;


public class Main {

public static void main(String[] args) {
TaskManager manager = new TaskManager();

System.out.println("Создаем задачи:\n");
TaskManager manager = Managers.getDefault();

Task task1 = new Task("Просто задача - 1", "Описание простой задачи - 1");
int task1Id = manager.addNewTask(task1);
Expand All @@ -33,61 +35,42 @@ public static void main(String[] args) {
"Описание подзадачи - 3, эпической задачи - 2", epic2.getId());
int subtask3Id = manager.addNewSubtask(subtask3);

System.out.println(manager.getAllTasks().toString());
System.out.println(manager.getAllEpics().toString());
System.out.println(manager.getAllSubtasks().toString() + '\n');

System.out.println("Обновляем задачи и смотрим статусы:\n");

Task task3 = new Task(task1.getId(), "Просто задача - 3", "Ставим вместо простой задачи - 1, меняем статус", Status.IN_PROGRESS);
manager.updateTask(task3);
Subtask subtask4 = new Subtask(subtask2.getId(), "Подзадача - 4", "Ставим вместо подзадачи - 2, эпической задачи - 1, меняем статус", Status.DONE, subtask2.getEpicId());
manager.updateSubtask(subtask4);

System.out.println(manager.getAllTasks().toString());
System.out.println(manager.getAllSubtasks().toString());
System.out.println(manager.getAllEpics().toString());

Epic epic3 = new Epic(epic1.getId(), "Эпическая задача - 3", "Ставим вместо эпической задачи - 1", epic1.getStatus());
manager.updateEpic(epic3);

System.out.println(manager.getAllEpics().toString());

Subtask subtask5 = new Subtask(subtask1.getId(), "Подзадача - 5", "Ставим вместо подзадачи - 1, эпической задачи - 3, меняем статус", Status.DONE, subtask1.getEpicId());
manager.updateSubtask(subtask5);
subtask3 = new Subtask(subtask3.getId(), "Подзадача - 3",
"Меняем статус", Status.DONE, subtask3.getEpicId());
manager.updateSubtask(subtask3);

System.out.println(manager.getAllSubtasks().toString());
System.out.println(manager.getAllEpics().toString());

subtask5 = new Subtask(subtask5.getId(), "Подзадача - 5", "Меняем статус", Status.IN_PROGRESS, subtask5.getEpicId());
manager.updateSubtask(subtask5);
subtask4 = new Subtask(subtask4.getId(), "Подзадача - 4", "Меняем статус", Status.NEW, subtask4.getEpicId());
manager.updateSubtask(subtask4);

System.out.println(manager.getAllSubtasks().toString());
System.out.println(manager.getAllEpics().toString());

subtask5 = new Subtask(subtask5.getId(), "Подзадача - 5", "Меняем статус", Status.NEW, subtask5.getEpicId());
manager.updateSubtask(subtask5);

System.out.println(manager.getAllSubtasks().toString());
System.out.println(manager.getAllEpics().toString());

System.out.println("\nУдаляем задачи:\n");

System.out.println("Удаляем простую задачу - 1");
manager.deleteTask(task1.getId());
System.out.println(manager.getAllTasks().toString());
System.out.println("Удаляем подзадачу - 3, эпической задачи - 2");
manager.deleteSubtask(subtask3.getId());
System.out.println(manager.getAllSubtasks().toString() + '\n');

System.out.println("Удаляем все подзадачи и очищаем списки эпиков");
manager.deleteAllSubtasks();
System.out.println(manager.getAllSubtasks().toString());
System.out.println(manager.getAllEpics().toString());
manager.getTask(2);
manager.getTask(1);
manager.getTask(2);
manager.getEpic(4);
manager.getSubtask(6);
manager.getSubtask(5);
manager.getEpic(3);
manager.getSubtask(7);
manager.getTask(1);
manager.getTask(1);
manager.getSubtask(6);
manager.getSubtask(5);

printAllTasks(manager);
}
private static void printAllTasks(TaskManager manager) {
System.out.println("Задачи:");
for (Task task : manager.getAllTasks()) {
System.out.println(task);
}
System.out.println("Эпики:");
for (Task epic : manager.getAllEpics()) {
System.out.println(epic);

for (Task task : manager.getEpicSubtasks(epic.getId())) {
System.out.println("--> " + task);
}
}
System.out.println("Подзадачи:");
for (Task subtask : manager.getAllSubtasks()) {
System.out.println(subtask);
}

System.out.println("История:");
for (Task task : manager.getHistory()) {
System.out.println(task);
}
}
}
10 changes: 10 additions & 0 deletions src/service/HistoryManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package service;

import model.Task;

import java.util.List;

public interface HistoryManager {
void addInHistory(Task task);
List<Task> getHistory();
}
30 changes: 30 additions & 0 deletions src/service/InMemoryHistoryManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package service;

import model.Task;

import java.util.ArrayList;
import java.util.List;

public class InMemoryHistoryManager implements HistoryManager {
private static final int SIZE_HISTORY = 10;
private final List<Task> history = new ArrayList<>(SIZE_HISTORY);

private void removeHistoryFirst() {
if (!history.isEmpty() && history.size() == SIZE_HISTORY) {
history.removeFirst();
}
}

@Override
public List<Task> getHistory() {
return history;
}

@Override
public void addInHistory(Task task) {
if (task != null && SIZE_HISTORY != 0) {
removeHistoryFirst();
history.add(task);
}
}
}
Loading

0 comments on commit 06d0867

Please sign in to comment.