feat(tasks): define status graph and progress
This commit is contained in:
@@ -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;
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user