-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLeaveApplication.java
106 lines (80 loc) · 1.91 KB
/
LeaveApplication.java
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package implementation.chainOfResponsibility;
import java.time.LocalDate;
import java.time.Period;
//Represents a request in our chain of responsibility
public class LeaveApplication {
public enum Type {Sick, PTO, LOP};
public enum Status {Pending, Approved, Rejecetd };
private Type type;
private LocalDate from;
private LocalDate to;
private String processedBy;
private Status status;
public LeaveApplication(Type type, LocalDate from, LocalDate to) {
this.type = type;
this.from = from;
this.to = to;
this.status = Status.Pending;
}
public Type getType() {
return type;
}
public LocalDate getFrom() {
return from;
}
public LocalDate getTo() {
return to;
}
public int getNoOfDays() {
return Period.between(from, to).getDays();
}
public String getProcessedBy() {
return processedBy;
}
public Status getStatus() {
return status;
}
public void approve(String approverName) {
this.status = Status.Approved;
this.processedBy = approverName;
}
public void reject(String approverName) {
this.status = Status.Rejecetd;
this.processedBy = approverName;
}
public static Builder getBuilder() {
return new Builder();
}
@Override
public String toString() {
return type + " leave for "+getNoOfDays()+" day(s) "+status
+ " by "+processedBy;
}
public static class Builder {
private Type type;
private LocalDate from;
private LocalDate to;
private LeaveApplication application;
private Builder() {
}
public Builder withType(Type type) {
this.type = type;
return this;
}
public Builder from(LocalDate from) {
this.from = from;
return this;
}
public Builder to(LocalDate to) {
this.to = to;
return this;
}
public LeaveApplication build() {
this.application = new LeaveApplication(type, from, to);
return this.application;
}
public LeaveApplication getApplication() {
return application;
}
}
}