Compare commits

..

No commits in common. "f0b79f0db0c6e089f64748412da60e20c122c306" and "65b3ddcc24bb91a9162ba0c543666771cd1d970f" have entirely different histories.

2 changed files with 9 additions and 8 deletions

View File

@ -6,7 +6,7 @@
<groupId>ru.kamask.pet</groupId>
<artifactId>todo</artifactId>
<version>2.2.0-SNAPSHOT</version>
<version>2.1</version>
<properties>
<maven.compiler.release>24</maven.compiler.release>

View File

@ -19,7 +19,7 @@ public class ListCommand implements Command {
return Optional.of(Command.errorMessage);
var res = formatWithTable(service.list(), "Список задач пуст.");
return Optional.of(res);
}
@ -28,19 +28,20 @@ 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";
var res = new StringBuilder(String.format(template, "ID", "Название задачи", "Статус"));
res.append("-".repeat(50) + "\n");
String res = "";
res += String.format(template, "ID", "Название задачи", "Статус");
res += "-".repeat(50) + "\n";
if (tasks.size() == 0)
return res.append("\n" + msgIfEmpty).toString();
return res + "\n" + msgIfEmpty;
for (Task task : tasks) {
SimpleTask.Data data = ((SimpleTask) task).data();
res.append(String.format(template, data.id(), data.title(), data.done() ? "выполнено" : "не выполнено"));
res += String.format(template, data.id(), data.title(), data.done() ? "выполнено" : "не выполнено");
}
return res.toString();
return res;
}
}