-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDraftState.java
More file actions
28 lines (25 loc) · 853 Bytes
/
DraftState.java
File metadata and controls
28 lines (25 loc) · 853 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package behavioral.state;
public class DraftState implements State {
public void goTo(DocumentContext context, StateType desired, UserRole role) {
switch (desired) {
case MODERATION -> {
context.setState(new ModerationState());
Main.println("Draft -> Moderation");
}
case PUBLISHED -> {
if (role == UserRole.ADMIN) {
context.setState(new PublishedState());
Main.println("Admin: Draft -> Published");
} else {
Main.errPrintln("Only Admin can publish");
}
}
default -> {
Main.errPrintln("Invalid transition from Draft");
}
}
}
public StateType getType() {
return StateType.DRAFT;
}
}