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
372 changes: 249 additions & 123 deletions src/Main.java

Large diffs are not rendered by default.

50 changes: 36 additions & 14 deletions src/data/Epic.java
Original file line number Diff line number Diff line change
@@ -1,58 +1,80 @@
package data;

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

public class Epic extends Task {

/// Хранилище ID подзадач
private final ArrayList<Integer> subtaskIds = new ArrayList<>();
private ArrayList<Integer> subtaskIds = new ArrayList<>();

/// Дата и время завершения эпика
private LocalDateTime endTime;

/// Конструктор
public Epic(Integer id, String title, String description) {
super(id, title, description);
}

/// Получение всех ID подзадач
public ArrayList<Integer> getSubtaskIds() {
public List<Integer> getSubtaskIds() {
return new ArrayList<>(subtaskIds);
}

@Override
public LocalDateTime getEndTime() {
return endTime;
}

/// Добавление новой ID подзадачи
public void addSubtaskId(Integer subtaskId) {
subtaskIds.remove(subtaskId);
subtaskIds.add(subtaskId);
}

/// Удаление всех ID подзадач
public void removeAllSubtaskIds() {
subtaskIds.clear();
}

/// Удаление ID подзадачи
public void removeSubtaskId(Integer subtaskId) {
subtaskIds.remove(subtaskId);
}

@Override
public Type getType() {
return Type.EPIC;
}

@Override
/// Получение копии объекта
@Override
public Epic getCopy() {
Epic newEpic = new Epic(this.id, this.title, this.description);
newEpic.setStatus(this.status);
newEpic.status = this.status;
newEpic.startTime = this.startTime;
newEpic.duration = this.duration;
newEpic.endTime = this.endTime;
newEpic.subtaskIds = this.subtaskIds;
return newEpic;
}

/// Внесение даты и времени завершения
public void setEndTime(LocalDateTime endTime) {
this.endTime = endTime;
}

/// Удаление всех ID подзадач
public void removeAllSubtaskIds() {
subtaskIds.clear();
}

/// Удаление ID подзадачи
public void removeSubtaskId(Integer subtaskId) {
subtaskIds.remove(subtaskId);
}

@Override
public String toString() {
return "Epic{" +
"id='" + super.getId() + '\'' +
", title='" + super.getTitle() + '\'' +
", description='" + super.getDescription() + '\'' +
", status='" + super.getStatus() + '\'' +
", startTime='" + (startTime == null ? "null" : startTime.format(DATE_TIME_FORMATTER)) + '\'' +
", endTime='" + (endTime == null ? "null" : endTime.format(DATE_TIME_FORMATTER)) + '\'' +
", duration='" + (duration == null ? "null" : duration.toMinutes()) + '\'' +
'}';
}
}
30 changes: 27 additions & 3 deletions src/data/Subtask.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
package data;

import java.time.Duration;
import java.time.LocalDateTime;

public class Subtask extends Task {

/// ID целевого эпика
private final Integer epicId;

/// Конструктор
public Subtask(Integer id, String title, String description, Status status, Integer epicId) {
public Subtask(
Integer id,
String title,
String description,
Status status,
Integer epicId,
LocalDateTime startTime,
Duration duration
) {
super(id, title, description, status);
this.epicId = epicId;
this.startTime = startTime;
setDuration(duration);
}

/// Получение ID целевого эпика
Expand All @@ -21,10 +34,18 @@ public Type getType() {
return Type.SUBTASK;
}

@Override
/// Получение копии объекта
@Override
public Subtask getCopy() {
return new Subtask(this.id, this.title, this.description, this.status, this.epicId);
return new Subtask(
this.id,
this.title,
this.description,
this.status,
this.epicId,
this.startTime,
this.duration
);
}

@Override
Expand All @@ -35,6 +56,9 @@ public String toString() {
", title='" + super.getTitle() + '\'' +
", description='" + super.getDescription() + '\'' +
", status='" + super.getStatus() + '\'' +
", startTime='" + (startTime == null ? "null" : startTime.format(DATE_TIME_FORMATTER)) + '\'' +
", endTime='" + (getEndTime() == null ? "null" : getEndTime().format(DATE_TIME_FORMATTER)) + '\'' +
", duration='" + (duration == null ? "null" : duration.toMinutes()) + '\'' +
'}';
}
}
62 changes: 60 additions & 2 deletions src/data/Task.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package data;

import java.time.Duration;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Objects;

public class Task implements Comparable<Task> {
Expand All @@ -16,6 +19,14 @@ public class Task implements Comparable<Task> {
/// Статус задачи
protected Status status;

/// Дата и время, когда предполагается приступить к выполнению задачи
protected LocalDateTime startTime;

/// Продолжительность задачи в минутах
protected Duration duration;

protected static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");

/// Конструктор 1
public Task(Integer id, String title, String description) {
this.id = id;
Expand All @@ -31,6 +42,23 @@ public Task(Integer id, String title, String description, Status status) {
this.status = status;
}

/// Конструктор 3
public Task(
Integer id,
String title,
String description,
Status status,
LocalDateTime startTime,
Duration duration
) {
this.id = id;
this.title = title;
this.description = description;
this.status = status;
this.startTime = startTime;
this.duration = duration;
}

/// Получение ID задачи
public Integer getId() {
return id;
Expand Down Expand Up @@ -71,14 +99,41 @@ public void setStatus(Status status) {
this.status = status;
}

/// Дата и время начала выполнения задачи
public LocalDateTime getStartTime() {
return startTime;
}

/// Внесение времени начала выполнения
public void setStartTime(LocalDateTime startTime) {
this.startTime = startTime;
}

/// Время выполнения задачи
public Duration getDuration() {
return duration;
}

/// Внесение продолжительности задачи
public void setDuration(Duration duration) {
this.duration = duration;
}

public LocalDateTime getEndTime() {
if (startTime != null && duration != null) {
return startTime.plus(duration);
}
return null;
}

/// Получение типа объекта
public Type getType() {
return Type.TASK;
}

/// Получение копии объекта
public Task getCopy() {
return new Task(this.id, this.title, this.description, this.status);
return new Task(this.id, this.title, this.description, this.status, this.startTime, this.duration);
}

@Override
Expand All @@ -104,7 +159,10 @@ public String toString() {
"id='" + id + '\'' +
", title='" + title + '\'' +
", description='" + description + '\'' +
", status=" + status +
", status='" + status + '\'' +
", startTime='" + (startTime == null ? "null" : startTime.format(DATE_TIME_FORMATTER)) + '\'' +
", endTime='" + (getEndTime() == null ? "null" : getEndTime().format(DATE_TIME_FORMATTER)) + '\'' +
", duration='" + (duration == null ? "null" : duration.toMinutes()) + '\'' +
'}';
}
}
Loading