-
Notifications
You must be signed in to change notification settings - Fork 0
/
Timesheet.java
108 lines (90 loc) · 2.6 KB
/
Timesheet.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
107
108
import java.util.ArrayList;
import java.util.Collections;
import java.io.Serializable;
public class Timesheet implements Serializable {
final long THIRTY_MINUTES = 1800000;
final long FOUR_HOURS = 14400000;
final long FOURTY_HOURS = 144000000;
ArrayList<Ticket> tickets;
private long timeRegular = 0;
private long timeCallback = 0;
private long timeJury = 0;
private long timeVacation = 0;
private long timeHoliday = 0;
private long timeBereavement = 0;
public Timesheet(ArrayList<Ticket> tickets) {
this.tickets = new ArrayList<Ticket>(tickets);
Collections.sort(this.tickets);
calculateHours();
}
public long getRegular() {
return timeRegular;
}
public long getCallback() {
return timeCallback;
}
public long getJury() {
return timeJury;
}
public long getVacation() {
return timeVacation;
}
public long getHoliday() {
return timeHoliday;
}
public long getBereavement() {
return timeBereavement;
}
public double getHoursWorked() {
double totalTime = (double) getRegular() + getCallback() + getJury() + getVacation() + getHoliday() + getBereavement();
return ((totalTime / (1000*60*60)));
}
public double getHoursPaid() {
long timeAndHalfNotApplicable = getBereavement() + getJury() + getVacation();
long timeAndHalfApplicable = getRegular() + getHoliday();
long callback = getCallback();
long timeAndHalf = 0;
if(timeAndHalfApplicable > FOURTY_HOURS) {
timeAndHalf += timeAndHalfApplicable - FOURTY_HOURS;
timeAndHalfApplicable -= timeAndHalf;
} else {
timeAndHalfNotApplicable += Math.max(FOUR_HOURS, callback);
}
if(timeAndHalf != 0 && callback != 0) {
long callbackExtra = Math.max(0, (FOUR_HOURS - callback));
timeAndHalfNotApplicable += callbackExtra;
timeAndHalf += callback;
}
timeAndHalf += (timeAndHalf*0.5);
double totalPay = (double) timeAndHalfNotApplicable + timeAndHalfApplicable + timeAndHalf;
return ((totalPay / (1000*60*60)));
}
private void calculateHours() {
for(int i = 0; i < tickets.size()-1; i++) {
Ticket ticketIn = tickets.get(i);
Ticket ticketOut = tickets.get(i+1);
long timeInBetween = ticketOut.datetime.getTime() - ticketIn.datetime.getTime();
switch(ticketIn.hourType) {
case Regular:
timeRegular += timeInBetween;
break;
case Callback:
timeCallback += timeInBetween;
break;
case JuryDuty:
timeJury += timeInBetween;
break;
case Vacation:
timeVacation += timeInBetween;
break;
case Holiday:
timeHoliday += timeInBetween;
break;
case Bereavement:
timeBereavement += timeInBetween;
break;
}
i += 1;
}
}
}