Compare commits
4
Commits
v2.1.0
..
2c7deaa9ae
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2c7deaa9ae | ||
|
|
8399ab0d58 | ||
|
|
f0b79f0db0 | ||
|
|
09cbf440ad |
+1
-1
@@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>ru.kamask.pet</groupId>
|
||||
<artifactId>todo</artifactId>
|
||||
<version>2.1</version>
|
||||
<version>2.2.0-SNAPSHOT</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.release>24</maven.compiler.release>
|
||||
|
||||
@@ -28,20 +28,19 @@ public class ListCommand implements Command {
|
||||
return String.format(templateUsage, name(), "Список всех задач.");
|
||||
}
|
||||
|
||||
String formatWithTable(List<Task> tasks, String msgIfEmpty){
|
||||
String formatWithTable(List<Task> tasks, String msgIfEmpty) {
|
||||
String template = "%-2s | %-30s | %s\n";
|
||||
String res = "";
|
||||
res += String.format(template, "ID", "Название задачи", "Статус");
|
||||
res += "-".repeat(50) + "\n";
|
||||
var res = new StringBuilder(String.format(template, "ID", "Название задачи", "Статус"));
|
||||
res.append("-".repeat(50) + "\n");
|
||||
|
||||
if (tasks.size() == 0)
|
||||
return res + "\n" + msgIfEmpty;
|
||||
return res.append("\n" + msgIfEmpty).toString();
|
||||
|
||||
for (Task task : tasks) {
|
||||
SimpleTask.Data data = ((SimpleTask) task).data();
|
||||
res += String.format(template, data.id(), data.title(), data.done() ? "выполнено" : "не выполнено");
|
||||
res.append(String.format(template, data.id(), data.title(), data.done() ? "выполнено" : "не выполнено"));
|
||||
}
|
||||
|
||||
return res;
|
||||
return res.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
package ru.kamask.pet.todo.model;
|
||||
|
||||
public interface Identifiable {
|
||||
int getId();
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package ru.kamask.pet.todo.model;
|
||||
|
||||
public abstract class Task {
|
||||
public abstract class Task implements Identifiable{
|
||||
private static int nextId = 1;
|
||||
|
||||
protected int id;
|
||||
@@ -11,10 +11,15 @@ public abstract class Task {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public int id() {
|
||||
@Override
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public int id() {
|
||||
return getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("Задача: id - %d, title: \"%s\"", id, title);
|
||||
|
||||
Reference in New Issue
Block a user