-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
artemdergunov
committed
Jan 26, 2025
1 parent
c12f425
commit e59a7d0
Showing
22 changed files
with
1,039 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,68 @@ | ||
import manager.InMemoryTaskManager; | ||
import manager.Managers; | ||
import enums.Status; | ||
import manager.TaskManager; | ||
import task.Task; | ||
import task.Epic; | ||
import task.Subtask; | ||
|
||
public class Main { | ||
|
||
public static void main(String[] args) { | ||
System.out.println("Поехали!"); | ||
|
||
final TaskManager taskManager = Managers.getDefault(); | ||
|
||
// создаем две задачи | ||
Task task1 = new Task("Сходить в магазин", "Купить молоко обязательно"); | ||
Task task2 = new Task("Покормить кота", "Влажным кормом"); | ||
|
||
|
||
taskManager.addTask(task1); | ||
taskManager.addTask(task2); | ||
|
||
System.out.println(task1); | ||
System.out.println(task2); | ||
|
||
|
||
// Создаем эпик с двумя подзадачами | ||
Epic epic1 = new Epic("Переезд", "В ближайшую неделю"); | ||
taskManager.addEpic(epic1); | ||
|
||
Subtask subtask1 = new Subtask("Собрать вещи", "Сложить все в коробки", epic1.getId()); | ||
Subtask subtask2 = new Subtask("Заказать машину", "Грузовую", epic1.getId()); | ||
taskManager.addSubtask(subtask1); | ||
taskManager.addSubtask(subtask2); | ||
|
||
System.out.println(epic1); | ||
System.out.println(subtask1); | ||
System.out.println(subtask2); | ||
|
||
// Создаем эпик с одной подзадачей | ||
Epic epic2 = new Epic("Ремонт на даче", "В ближайший месяц"); | ||
taskManager.addEpic(epic2); | ||
Subtask subtask3 = new Subtask("Купить материалы", "Отвезти на дачу", epic2.getId()); | ||
|
||
taskManager.addSubtask(subtask3); | ||
|
||
// меняем статусы | ||
subtask2.setStatus(Status.DONE); | ||
subtask1.setStatus(Status.DONE); | ||
taskManager.updateSubtask(subtask1); | ||
taskManager.updateSubtask(subtask2); | ||
task1.setStatus(Status.DONE); | ||
|
||
|
||
System.out.println(task1); | ||
System.out.println(epic1); | ||
|
||
} | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package enums; | ||
|
||
public enum Status { | ||
NEW, | ||
IN_PROGRESS, | ||
DONE | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package manager; | ||
|
||
import task.Task; | ||
|
||
import java.util.List; | ||
|
||
public interface HistoryManager { | ||
void add(Task task); | ||
|
||
List<Task> getHistory(); | ||
|
||
void remove(int id); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package manager; | ||
|
||
import task.Task; | ||
|
||
import java.util.*; | ||
|
||
public class InMemoryHistoryManager implements HistoryManager { | ||
|
||
private final Map<Integer, Node<Task>> viewedTasksMap = new HashMap<>(); | ||
private Node<Task> head; | ||
private Node<Task> tail; | ||
|
||
@Override | ||
public void add(Task task) { | ||
if (task != null) { | ||
linkLast(task); | ||
} | ||
} | ||
|
||
@Override | ||
public List<Task> getHistory() { | ||
return getTasks(); | ||
} | ||
|
||
@Override | ||
public void remove(int id) { | ||
removeNode(viewedTasksMap.get(id)); | ||
} | ||
|
||
private void linkLast(Task task) { | ||
if (viewedTasksMap.containsKey(task.getId())) { | ||
removeNode(viewedTasksMap.get(task.getId())); | ||
} | ||
final Node<Task> oldTail = tail; | ||
final Node<Task> newNode = new Node<>(task, tail, null); | ||
tail = newNode; | ||
viewedTasksMap.put(task.getId(), newNode); | ||
if (oldTail == null) { | ||
head = newNode; | ||
} else { | ||
oldTail.setNext(newNode); | ||
} | ||
} | ||
|
||
private List<Task> getTasks() { | ||
List<Task> tasks = new LinkedList<>(); | ||
Node<Task> currentNode = head; | ||
while (currentNode != null) { | ||
tasks.add(currentNode.getData()); | ||
currentNode = currentNode.getNext(); | ||
} | ||
return tasks; | ||
} | ||
|
||
private void removeNode(Node<Task> node) { | ||
if (node != null) { | ||
final Node<Task> next = node.getNext(); | ||
final Node<Task> previous = node.getPrevious(); | ||
node.setData(null); | ||
|
||
if (head == node && tail == node) { | ||
head = null; | ||
tail = null; | ||
} else if (head == node && tail != node) { | ||
head = next; | ||
head.setPrevious(null); | ||
} else if (head != node && tail == node) { | ||
tail = previous; | ||
tail.setNext(null); | ||
} else { | ||
previous.setNext(next); | ||
next.setPrevious(previous); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.