revert Merge pull request 'init/2.0.0' (#20) from init/2.0.0 into main Reviewed-on: #20
86 lines
1.9 KiB
Java
86 lines
1.9 KiB
Java
package ru.kamask.pet;
|
|
|
|
import java.time.LocalDate;
|
|
|
|
class Task {
|
|
static int taskCount = 0;
|
|
|
|
enum TaskIdGenerator {
|
|
INSTANCE;
|
|
|
|
private int currentId = 1;
|
|
|
|
int nextId() {
|
|
return currentId++;
|
|
}
|
|
}
|
|
|
|
private int id;
|
|
private String title;
|
|
private String description;
|
|
private TaskStatus status;
|
|
private LocalDate createdAt;
|
|
|
|
Task(String title, String description) {
|
|
id = TaskIdGenerator.INSTANCE.nextId();
|
|
status = TaskStatus.NEW;
|
|
createdAt = LocalDate.now();
|
|
taskCount++;
|
|
|
|
this.title = title;
|
|
this.description = description;
|
|
};
|
|
|
|
static void printTotalTasksCreated() {
|
|
System.out.println("Колличество дел: " + taskCount);
|
|
}
|
|
|
|
int getId() {
|
|
return id;
|
|
}
|
|
|
|
String getTitle() {
|
|
return title;
|
|
}
|
|
|
|
boolean isCompleted() {
|
|
return status == TaskStatus.COMPLETED;
|
|
}
|
|
|
|
void markCompleted() {
|
|
status = TaskStatus.COMPLETED;
|
|
}
|
|
|
|
void markInProgress() {
|
|
status = TaskStatus.IN_PROGRESS;
|
|
}
|
|
|
|
void markCanceled() {
|
|
status = TaskStatus.CANCELLED;
|
|
}
|
|
|
|
TaskStatus getStatus() {
|
|
return status;
|
|
}
|
|
|
|
static class TaskPrinter {
|
|
static void print(Task task) {
|
|
String template = """
|
|
|
|
──────────────────────────────
|
|
Номер: %-3d
|
|
Дата создания: %s
|
|
Статус: %s
|
|
Название: %-20s
|
|
------------------------------
|
|
%s
|
|
|
|
""";
|
|
;
|
|
String stringCompleted = task.status.getColorCode() + task.status.getDescription() + "\u001B[0m";
|
|
System.out.printf(template, task.id, task.createdAt, stringCompleted, task.title, task.description);
|
|
}
|
|
}
|
|
|
|
}
|