-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetTimes.txt
More file actions
34 lines (28 loc) · 937 Bytes
/
getTimes.txt
File metadata and controls
34 lines (28 loc) · 937 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
29
30
31
32
33
1. What design principles does this code violate?
Simplification
Duplication
2. Refactor the code to improve its design.
int checkValue(String myString, int value){
if(myString == null){
throw new MissingPropertiesException("missing interval");
}
if (value <= 0) {
throw new MissingPropertiesException("interval > 0");
}
return value
}
public void getTimes(Properties props) throws Exception {
String valueString;
int value;
checkInterval = checkValue(props.getProperty("interval"), value);
value = checkValue(props.getProperty("duration"), value);
if ((value % checkInterval) != 0) {
throw new MissingPropertiesException("duration % checkInterval");
}
monitorTime = value;
value = checkValue(props.getProperty("departure"), value);
if ((value % checkInterval) != 0) {
throw new MissingPropertiesException("departure % checkInterval");
}
departureOffset = value;
}