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