Рефакторинг класса ListCommand
-Обновление версии проекта до 2.2.0-SNAPSHOT -Рефакторинг класса ListCommand для объединения строк через класс StringBuilder -Повышение читаемости и производительности метода formatWithTable
This commit is contained in:
parent
65b3ddcc24
commit
09cbf440ad
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>ru.kamask.pet</groupId>
|
<groupId>ru.kamask.pet</groupId>
|
||||||
<artifactId>todo</artifactId>
|
<artifactId>todo</artifactId>
|
||||||
<version>2.1</version>
|
<version>2.2.0-SNAPSHOT</version>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.release>24</maven.compiler.release>
|
<maven.compiler.release>24</maven.compiler.release>
|
||||||
|
|||||||
@ -30,18 +30,17 @@ public class ListCommand implements Command {
|
|||||||
|
|
||||||
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";
|
||||||
String res = "";
|
var res = new StringBuilder(String.format(template, "ID", "Название задачи", "Статус"));
|
||||||
res += String.format(template, "ID", "Название задачи", "Статус");
|
res.append("-".repeat(50) + "\n");
|
||||||
res += "-".repeat(50) + "\n";
|
|
||||||
|
|
||||||
if (tasks.size() == 0)
|
if (tasks.size() == 0)
|
||||||
return res + "\n" + msgIfEmpty;
|
return res.append("\n" + msgIfEmpty).toString();
|
||||||
|
|
||||||
for (Task task : tasks) {
|
for (Task task : tasks) {
|
||||||
SimpleTask.Data data = ((SimpleTask) task).data();
|
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user