Skip to content
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
2 changes: 1 addition & 1 deletion .idea/misc.xml

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

4 changes: 0 additions & 4 deletions resources/task.csv
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
id,type,name,status,description,epic
1,TASK,Дом,NEW,Убраться в кухни и ванной,
2,TASK,Работа,IN_PROGRESS,Сделать куча рутины и пойти домой:),
3,EPIC,Прогулка,NEW,Прежде чем погулять нужно:,
4,EPIC,Приготовить кофе,NEW,Пойти на кухню и:,

30 changes: 15 additions & 15 deletions src/ru/yandex/javacource/golotin/schedule/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@
public class Main {
public static void main(String[] args) {
TaskManager taskManager = Manager.getDefault();
taskManager.createTask(new Task("Дом", Status.NEW, "Убраться в кухни и ванной"));
taskManager.createTask(new Task("Работа", Status.IN_PROGRESS, "Сделать куча рутины и пойти домой:)"));

taskManager.createEpic(new Epic("Прогулка", Status.NEW, "Прежде чем погулять нужно:"));
taskManager.createSubtask(new Subtask("Уборка", Status.NEW, "Убраться в квартире", 1));
taskManager.createSubtask(new Subtask("Одежда", Status.NEW, "Подготовить одежду к прогулке", 1));

taskManager.createEpic(new Epic("Приготовить кофе", Status.NEW, "Пойти на кухню и:"));
taskManager.createSubtask(new Subtask("Сделать кофе", Status.NEW, "Налить в кружку горячую воду и наспать кофе", 2));

taskManager.updateTask(new Task("Дом", Status.IN_PROGRESS, "Уборка в кухни и ванной"));

taskManager.updateEpic(new Epic("Прогулка", Status.NEW, "Не пойду гулять"));
taskManager.updateSubtask(new Subtask("Уборка", Status.IN_PROGRESS, "Убираюсь)", 1));
taskManager.updateSubtask(new Subtask("Сделать кофе", Status.DONE, "Кофе приготовлено", 1));
// taskManager.createTask(new Task("Дом", Status.NEW, "Убраться в кухни и ванной"));
// taskManager.createTask(new Task("Работа", Status.IN_PROGRESS, "Сделать куча рутины и пойти домой:)"));
//
// taskManager.createEpic(new Epic("Прогулка", Status.NEW, "Прежде чем погулять нужно:"));
// taskManager.createSubtask(new Subtask("Уборка", Status.NEW, "Убраться в квартире", 1));
// taskManager.createSubtask(new Subtask("Одежда", Status.NEW, "Подготовить одежду к прогулке", 1));
//
// taskManager.createEpic(new Epic("Приготовить кофе", Status.NEW, "Пойти на кухню и:"));
// taskManager.createSubtask(new Subtask("Сделать кофе", Status.NEW, "Налить в кружку горячую воду и наспать кофе", 2));
//
// taskManager.updateTask(new Task("Дом", Status.IN_PROGRESS, "Уборка в кухни и ванной"));
//
// taskManager.updateEpic(new Epic("Прогулка", Status.NEW, "Не пойду гулять"));
// taskManager.updateSubtask(new Subtask("Уборка", Status.IN_PROGRESS, "Убираюсь)", 1));
// taskManager.updateSubtask(new Subtask("Сделать кофе", Status.DONE, "Кофе приготовлено", 1));


System.out.println(taskManager.getTasks());
Expand Down
18 changes: 13 additions & 5 deletions src/ru/yandex/javacource/golotin/schedule/model/Epic.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
package ru.yandex.javacource.golotin.schedule.model;

import java.time.Duration;
import java.time.Instant;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

public class Epic extends Task {

private final List<Integer> subtaskIds = new ArrayList<>();
private LocalDateTime endTime;

public Epic(String name, Status status, String description) {
super(name, status, description);
public Epic(String name, Status status, String description, LocalDateTime startTime, long duration) {
super(name, status, description, startTime, duration);
}

public Epic(int id, String name, String description, Status status) {
super(name, status, description);
public Epic(int id, String name, String description, Status status, LocalDateTime startTime, long duration) {
super(name, status, description, startTime, duration);
setId(id);
}

Expand All @@ -36,11 +40,15 @@ public TaskType getType() {
return TaskType.EPIC;
}

public void setEndTime(LocalDateTime endTime) {
this.endTime = endTime;
}

@Override
public String toString() {
return "Epic{" +
"subtaskIds=" + subtaskIds +
", endTime=" + endTime +
'}';
}

}
11 changes: 7 additions & 4 deletions src/ru/yandex/javacource/golotin/schedule/model/Subtask.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
package ru.yandex.javacource.golotin.schedule.model;

import java.time.Instant;
import java.time.LocalDateTime;

public class Subtask extends Task {

private Integer epicId;

public Subtask(String name, Status status, String description, int epicId) {
public Subtask(String name, Status status, String description, LocalDateTime startTime, long duration, int epicId) {

super(name, status, description);
super(name, status, description, startTime, duration);
setEpicId(epicId);
}

public Subtask(int id, String name, String description, Status status, Integer epicId) {
super(name, status, description);
public Subtask(int id, String name, String description, Status status, LocalDateTime startTime, long duration, Integer epicId) {
super(name, status, description, startTime, duration);
setId(id);
setEpicId(epicId);
}
Expand Down
55 changes: 44 additions & 11 deletions src/ru/yandex/javacource/golotin/schedule/model/Task.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,34 @@
package ru.yandex.javacource.golotin.schedule.model;

import java.time.Duration;
import java.time.LocalDateTime;
import java.util.Objects;
import java.time.Instant;

public class Task {
private int id;
private String name;
private String description;
private Status status;

public Task(String name, Status status, String description) {
private LocalDateTime startTime; // LocalDateTime
private Duration duration; // минуты или Duration

public Task(String name, Status status, String description, LocalDateTime startTime, long duration) {
this.name = name;
this.status = status;
this.description = description;
this.startTime = LocalDateTime.from(startTime);
this.duration = Duration.ofMinutes(duration);
}

public Task(int id, String name, String description, Status status) {
public Task(int id, String name, String description, Status status, LocalDateTime startTime, long duration) {
setId(id);
this.name = name;
this.status = status;
this.description = description;
this.startTime = startTime;
this.duration = Duration.ofMinutes(duration);
}

public int getId() {
Expand Down Expand Up @@ -61,26 +71,49 @@ public void setStatus(Status status) {
this.status = status;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Task task = (Task) o;
return id == task.id;
public LocalDateTime getStartTime() {
return startTime;
}

@Override
public int hashCode() {
return Objects.hash(id);
public void setStartTime(LocalDateTime startTime) {
this.startTime = startTime;
}

public long getDuration() {
return duration.toMinutesPart();
}

public void setDuration(long duration) {
this.duration = Duration.ofMinutes(duration);
}

public LocalDateTime getEndTime() {
return startTime.plus(duration);
}


@Override
public String toString() {
return "Task{" +
"id=" + id +
", name='" + name + '\'' +
", description='" + description + '\'' +
", status=" + status +
", startTime=" + startTime +
", endTime=" + getEndTime() +
'}';
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Task task = (Task) o;
return id == task.id && Objects.equals(name, task.name) && Objects.equals(description, task.description) && status == task.status && Objects.equals(startTime, task.startTime) && Objects.equals(duration, task.duration);
}

@Override
public int hashCode() {
return Objects.hash(id, name, description, status, startTime, duration);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

import java.nio.file.Files;

import java.time.Duration;
import java.time.Instant;
import java.time.LocalDateTime;
import java.util.Map;

import ru.yandex.javacource.golotin.schedule.exception.ManagerSaveException;
Expand Down Expand Up @@ -41,10 +44,10 @@ public static FileBackedTaskManager loadFromFile(File file) {
taskManager.createTask(task);
} else if (task.getType() == TaskType.SUBTASK) {
taskManager.createSubtask(new Subtask(task.getId(), task.getName(), task.getDescription(),
task.getStatus(), task.getEpicId()));
task.getStatus(), task.getStartTime(), task.getDuration(), task.getEpicId()));
} else if (task.getType() == TaskType.EPIC) {
taskManager.createEpic(new Epic(task.getId(), task.getName(), task.getDescription(),
task.getStatus()));
task.getStatus(), task.getStartTime(), task.getDuration()));
for (Subtask subtask : taskManager.subtasks.values()) {// Поиск подзадач эпика
if (subtask.getEpicId() == task.getId()) {
Epic epic = taskManager.epics.get(task.getId());
Expand Down Expand Up @@ -124,7 +127,7 @@ public void deleteSubtask(int id) {

public static String toString(Task task) {
return task.getId() + "," + task.getType() + "," + task.getName() + "," + task.getStatus() + "," +
task.getDescription() + "," + (task.getType().equals(TaskType.SUBTASK) ? task.getEpicId() : "");
task.getDescription() + "," + (task.getType().equals(TaskType.SUBTASK) ? task.getEpicId() : ""+task.getStartTime()+","+task.getEndTime());
}


Expand All @@ -135,15 +138,17 @@ public static Task taskFromString(String value) {
final String name = values[2];
final Status status = Status.valueOf(values[3]);
final String description = values[4];
final LocalDateTime startTime = LocalDateTime.parse(values[5]);
final Duration duration = Duration.between(LocalDateTime.parse(values[5]), LocalDateTime.parse(values[6]));
if (type == TaskType.TASK) {
return new Task(id, name, description, status);
return new Task(id, name, description, status, startTime, duration.toMinutesPart());
}
if (type == TaskType.SUBTASK) {
final int epicId = Integer.parseInt(values[5]);
return new Subtask(id, name, description, status, epicId);
return new Subtask(id, name, description, status, startTime, duration.toMinutesPart(), epicId);
}

return new Epic(id, name, description, status);
return new Epic(id, name, description, status, startTime, duration.toMinutesPart());
}

protected void saveToFile() {
Expand Down
Loading