feat(tasks): define status graph and progress

This commit is contained in:
sechmachine
2026-08-14 23:31:50 +07:00
parent 5967f7f70d
commit 17a3c5dc70
4 changed files with 193 additions and 0 deletions
@@ -0,0 +1,40 @@
package com.lab.labtimesheet.tasks;
import java.util.Collection;
import java.util.OptionalDouble;
public record TaskProgress(int todo, int inProgress, int blocked, int done) {
public static TaskProgress from(Collection<TaskStatus> statuses) {
int todo = 0;
int inProgress = 0;
int blocked = 0;
int done = 0;
for (TaskStatus status : statuses) {
switch (status) {
case TODO -> todo++;
case IN_PROGRESS -> inProgress++;
case BLOCKED -> blocked++;
case DONE -> done++;
}
}
return new TaskProgress(todo, inProgress, blocked, done);
}
public int total() {
return todo + inProgress + blocked + done;
}
public int count(TaskStatus status) {
return switch (status) {
case TODO -> todo;
case IN_PROGRESS -> inProgress;
case BLOCKED -> blocked;
case DONE -> done;
};
}
public OptionalDouble completionPercentage() {
return total() == 0 ? OptionalDouble.empty() : OptionalDouble.of(done * 100.0 / total());
}
}
@@ -0,0 +1,17 @@
package com.lab.labtimesheet.tasks;
public enum TaskStatus {
TODO,
IN_PROGRESS,
BLOCKED,
DONE;
public boolean canTransitionTo(TaskStatus target) {
return switch (this) {
case TODO -> target == IN_PROGRESS || target == BLOCKED;
case IN_PROGRESS -> target == DONE || target == BLOCKED;
case BLOCKED -> target == TODO || target == IN_PROGRESS;
case DONE -> target == IN_PROGRESS;
};
}
}